Integrating Custom Mental Ray Shaders

 
 
 

Follow these tips to view your custom mental shaders at:

For more information on the syntax for writing custom mental ray shaders, see mental ray shader language extensions.

File swatch vs. Interactive swatch

The classification string of the shading node determines whether the swatch is a file swatch or an interactive swatch. A file swatch appears in the Hypershade as a static icon, while the interactive swatch dynamically updates.

Swatch type Classification string contains...

file swatch

mentalRaySwatchGen

interactive swatch

swatch/mentalRaySwatchGen

Classifications strings are registered when the shading node is registered, upon start up of Maya. In order to change the classification string of a particular shading node, you must edit the mentalrayCustomNodeClass.mel file, before starting Maya. You can find this file in <maya directory>/scripts/others.

To check the classification string of a shading node, use the following MEL command:

getClassification <nodeType>

where <nodeType> is the shading node you want to check. For example:

getClassification mib_illum_lambert;

Viewing your custom mental ray shader at render time

See Load shaders for information on how to import a custom shader library.

In addition, if your shader links against mayabase.lib, then mayabase.dll must be in your PATH environment variable. Add the following line to your Maya.env file:

PATH = $MAYA_LOCATION/mentalray/shaders;$PATH

Viewing your custom mental ray shader as a swatch in the Hypershade or in the Attribute Editor

Edit the mentalrayCustomNodeClass.mel file, located at $MAYA_LOCATION/scripts/others/ and add your shader. This file defines the classification string for mental ray shaders. Ensure that the classification string for your shader includes swatch/mentalRaySwatchGen. mental ray is used to render a swatch for your shader. This swatch appears in the Hypershade and in the Attribute Editor if you define a custom AE template.

Viewing your custom mental ray shader in the scene view in shaded mode

The scene view attempts to implement a simple Phong shading model to display custom shaders. The hardware shader looks for specific attributes to fulfill the requirements of the Phong model. At a minimum, the requirements for the Diffuse channel should be satisfied.

The Diffuse channel of the Phong model are driven by any of these attributes if they exist on the shader (if more than one exist, then the first of the list is used). The attribute must be of type color.

The Ambient channel is driven by this attribute if it exists. This attribute must be a color.

The Ambience attribute is used to scale the ambient value. This attribute must be a color.

The Specular channel of the Phong model is driven by any of these attributes if they exist on the shader (if more than one exists, then the first one in the list is used). The attribute must be of type color.

The Exponent of the Phong model is driven by any of these attributes if they exist on the shader (if more than one exists, then the first one in the list is used). These must be scalar (float) attributes.

The Alpha value of the Phong model is driven by this attribute if it exists. It must be a scalar (float value).

Viewing your custom mental ray shader in the scene view with hardware texturing enabled

To enable texturing on the shader, you need to create a custom Attribute Editor for your shader node. To add custom controls in the custom Attribute Editor, call the MEL procedure as follows:

AEhardwareTextureTemplate(string $nodeName, string $attrTokens)

With the following parameters:

This procedure adds controls to the Attribute Editor that allow you to select a channel to use with hardware texturing.

Example shader

For an example of a shader that implements all of the above, refer to: $MAYA_LOCATION/mentalray/devkit/docs/writingShaders/lightlink

Related topics

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