Image based lighting

Classifying a plug-in node as an image light

When registering a plug-in node, it is possible to opt-in to use the internal hardware lighting evaluation for an environment light by specifying a classification with the root. This allows the plug-in node to behave like an internal IBL (image) light in Maya:

/drawdb/light/image

For example:

/drawdb/light/image/environment

When specified, a default 3d UI drawing implementation is used. If an explicit override classification is supplied, then that override will be used for drawing.

If multiple nodes use an image classification, then only the first will be considered to contribute to internal lighting.

The aiSkyDomeLight Arnold for Maya plug-in light uses this classification, and therefore supports environment lighting.

Evaluation

The internal hardware lighting evaluation currently supports the following attributes if they are defined on the Maya node:

Given the color input, two maps are generated internally for shader usage: an irradiance environment map and a specular environment map.

The specular map is a 3d map with each Z slice containing samples at different levels of specularity.

An example is shown below. These images represent the generated specular 3d map with 8 levels of sampling.

This image represents the generated irradiance 2d texture.

This image shows the input environment texture.

This image represents a blinn shader using the example environment maps, as specified on a plug-in node that is classified as an image light.

API Access

When writing shader fragments, environment data can be accessed implicitly by specifying input shader properties with the following names:

For example, the following is a combiner which takes IrradianceEnv and SpecularEnv as inputs to compute a final color.

<fragment uiName="myShaderCombiner" name="myShaderCombiner" type="plumbing" class="ShadeFragment" version="1.0" feature_level="0">
    <description><![CDATA[Combines inputs from shader fragments.]]></description>
    <properties>
        <float3 name="color" />
        <float3 name="specularColor" />
        <float name="Ks" />
        <float name="Kd" />
        <float3 name="IrradianceEnv" />
        <float3 name="SpecularEnv" />
    </properties>
    <values>
        <float3 name="color" value="1.0 1.0 1.0" />
        <float3 name="specularColor" value="0.0 0.0 0.0" />
        <float name="Ks" value=”0.2”/>
        <float name="Kd" value=“0.8”/>
        <float3 name="IrradianceEnv" value="0.0 0.0 0.0" />
        <float3 name="SpecularEnv" value="0.0 0.0 0.0" />
    </values>
    <outputs>
        <struct name="myShaderCombiner" struct_name="mayaSurfaceShaderOutput" />
    </outputs>
    <implementation>
        // Sample implementation using environment inputs
        <implementation render="OGSRenderer" language="Cg" lang_version="2.1">
            <function_name val="myShaderCombiner" />
            <source>
                <![CDATA[
                mayaSurfaceShaderOutput myShaderCombiner(
                float3 color,
                float3 specularColor,
                float Ks,
                float Kd,
                float3 IrradianceEnv,
                float3 SpecularEnv)
{
    mayaSurfaceShaderOutput result;
    float3 diffuse = color * IrradianceEnv * Kd;
    float3 specular = specularColor * SpecularEnv * Ks;

    result.outColor = diffuse + specular;
    result.outTransparency = float3(0.0f, 0.0f, 0.0f);
    result.outGlowColor = float3(0.0f, 0.0f, 0.0f);
    result.outMatteOpacity = float3(-1.0e+06f, -1.0e+06f, -1.0e+06f);
    result.outSurfaceFinal = float4(result.outColor, 1.0f);
    return result;
}

Implicit binding is performed for viewport and batch rendering if image based lights exist in the Maya scene. Implicit environment lighting binding is performed for the Material Viewer in the Hypershade, when the Hardware renderer is selected. Hardware swatch rendering does not bind any environment lighting.

The kIrradianceEnvironment and kSpecularEnvironment enums on the MDrawContext::getInternalTexture() interface allow for explicit access to internal irradiance and specular environment maps.

The textures are available for the first image light which is active at the time that the draw context is available.