在 mental ray 中渲染硬件着色器

可以使用 mental ray for Maya 渲染器来渲染硬件着色器。mental ray for Maya 识别硬件着色器,并将其作为 Lambert 着色器。

使用此功能,您无需为了烘焙光照贴图而复制材质和创建硬件着色器的软件版本;若场景中有大量的着色器,这将会免除许多开销。

支持 kPluginHardwareShader 类型的所有着色器。mental ray for Maya 首先检查预期在 “Lambert”着色器上的硬件着色器参数,如“颜色”(Color)“透明度”(Transparency)“漫反射”(Diffuse)等。如果预期参数不存在,则使用默认的“Lambert”值。

此外,您也可以使用简单的 MEL 脚本,将标准的“Lambert”参数重新映射到自定义硬件着色器参数。这样,自定义着色器上的漫反射和法线贴图也会受支持。

自定义 MEL 程序的示例如下。在此示例中,使用 MayaUberShader.fx,将标准的“Lambert”参数映射到 dx11Shader 中的等效参数。

注: 对于硬件着色器,参数名称特定于该着色器加载的着色器文件
global proc string[] dx11Shader_lambertParameters( string $node, string $params[] )
//
// Description:
//		Custom MEL procedure invoked during a mentalray render to allow plug-in
//		hardware shaders to participate as lambert shaders.
//
//		This procedure allows the plug-in hardware shader an opportunity to map
//		lambert attribute parameters to the equivalent hardware shader attribute(s).
//
//		The function must exhibit the following characteristics:
//
//		1. Size of the returned string[] array must equal the size of the input $params[] array.
//		2. A string entry of "" will use the default lambert attribute name.
//
{
    string $newParams[];
    int $nParams = size($params);
    int $i;
    for( $i = 0; $i < $nParams; $i++ )
    {
        string $param = $params[$i];
		
		// Default to the lambert attribute name. Also ensures we allocate an entry per lambert parameter.
        $newParams[$i] = $param;
		
        if( $param == "color" )
        {
			// Remaps the color attribute to the diffuse map on the dx11Shader (MayaUberShader.fx)
            $newParams[$i] = "DiffuseTexture";
        }
        else if( $param == "transparency" )
        {
            // Remaps the transparency attribute to the diffuse map on the dx11Shader (MayaUberShader.fx)
            $newParams[$i] = "Diffuse_Map_Transparency";
        }
        else if( $param == "normalCamera" )
        {
			// Remaps the normal attribute to the normal map on the dx11Shader (MayaUberShader.fx)
            $newParams[$i] = "NormalTexture";
        }
    }
    return $newParams;
}

自定义 MEL 程序使用以下命名法:

$shaderType + "_lambertParameters"

例如:dx11Shader_lambertParameters

提示: 进行批量渲染时,将 MEL 程序添加到“渲染设置窗口: 公用”(Render Settings window: Common)选项卡上的“渲染前 MEL”(Pre render MEL)字段。

调用此回调函数,每次一个着色器节点实例。

重新映射后,mental ray for Maya 将“硬件着色器”属性解释为等效的“Lambert”属性。