Evaluating shading nodes outside of the rendering context

Shading nodes can request rendering information regarding the current sample position through pre-defined attributes (See Appendix C: Rendering attributes for a complete list of rendering specific attributes and their corresponding names). However, these pre-defined attributes are not supplied in a non-rendering context. Evaluation of shading nodes outside of the rendering context is supported using the call MRenderUtil::sampleShadingNetwork.

MStatus MRenderUtil::sampleShadingNetwork(
    MString shadingNodeName,
    long numSamples,
    bool useShadowMaps,
    bool reuseMaps,
    MFloatPointArray *points, // sample points in world
    MFloatArray *uCoords,
    MFloatArray *vCoords,
    MFloatVectorArray *normals, // normals in world
    MFloatPointArray *refPoints, // refPoints in world
    MFloatVectorArray *tangentUs,
    MFloatVectorArray *tangentVs,
    MFloatArray *filterSizes,
    MFloatVectorArray &resultColors,
    MFloatVectorArray &resultTransparencies

You provide lists of sample points, normals, UVs, etc., and the function will return lists of colors and transparencies calculated based on the supplied sample data.

Shadow calculation can also be done by forcing a test rendering to generate shadow maps before samples are taken.

An example plug-in, sampleCmd.cpp, has been provided. This command takes a particle object and a shading node/shading engine name as input, and creates particles which have the color assigned based on the sampling result.