You can render hardware shaders using the mental ray for Maya renderer. mental ray for Maya recognizes hardware shaders and treats them as lambert shaders.
Using this feature, you do not need to duplicate materials and create software versions of your hardware shaders to bake lightmaps; this removes a lot of overhead if you have a large number of shaders in your scene.
All shaders of type kPluginHardwareShader are supported. mental ray for Maya first checks the hardware shader for the parameters it would expect on a Lambert shader, such as Color, Transparency, Diffuse, and so forth. If an expected parameter does not exist, the default Lambert value is used.
In addition, you can also remap the standard Lambert parameters to your custom hardware shader parameters using a simple MEL script. This way, diffuse and normal maps on your custom shader can also be supported.
An example custom MEL procedure is provided below. In this example, standard Lambert parameters are mapped to their equivalent parameters in a dx11Shader using MayaUberShader.fx.
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; }
The custom MEL procedure uses the following nomenclature:
$shaderType + “_lambertParameters”
For example: dx11Shader_lambertParameters
This callback is invoked once per shader node instance.
After remapping, mental ray for Maya interprets the hardware shader attributes as their equivalent Lambert attributes.