Custom volume shaders


When using custom volume shaders, you should make your shader compatible with the Maya volume engine. This is the best way to make volume shaders work correctly with render passes, Maya light shaders and other Maya features.

To do so, use the following data structure for the shader result rather than a simple miColor:

typedef struct VolumeShader_R {
miColor color;
miColor glowColor;
miColor matteOpacity;
miColor transparency;
} VolumeShader_R; 

The volume is considered opaque unless the transparency field of the structure is set to a non-zero value. The volume engine takes care of integrating and compositing volume samples, so the volume shader only needs to take care of computing the raw color value and transparency for the current sample.

To retrieve the start and end points of the current volume ray segment, use the following code:

miVector orgObj, pointObj;
mi_point_to_object(state, &orgObj, &state->org);
mi_point_to_object(state, &pointObj, &state->point);

Then, to get the traversed length, in object space, do the following:

miScalar length = mi_vector_dist(&orgObj, &pointObj);

Legacy volume shaders

Legacy volume shaders that are not compatible with the Maya volume engine can still be used with Maya 2014. However, you must turn off the volume engine with the following MEL code:

select mentalrayGlobals;
addAttr -ln useVolumeEngine -at bool;
setAttr mentalrayGlobals.useVolumeEngine false; 

The native Maya volume shaders (fog, fluids, particles, and so forth) do not work if the volume engine is turned off. Therefore, the preferred and proper permanent solution is to convert the shaders to be compatible with the Maya volume engine using the guidelines mentioned above.

Creative Commons License Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License