MayaMan Help Contents

Extending the MayaMan Magic Shaders Support

MayaMan has the ability to write out RenderMan shaders on-the-fly to emulate your Maya material hierarchies. We have built in support for most of Maya's native shading nodes, but with a bit of work you can extend this support for 3rd party Maya shaders too. This page will tell you how.

The maya_material_description File

In this file you will find the names of all the materials supported by MayaMan, and the names of the attributes of those materials. MayaMan uses this file when analysing the Maya material hierarchies to determine if it can support a given material node, and which attributes of that node to connect up with other nodes. In this file the material node names start in the zeroth column, and the parameters are listed below each material node indented by two spaces.

Any attributes listed under a node will be available to the RenderMan source code chunk for that node as 'cat2(_N_,PARAMNAME)', where PARAMNAME is the name of the parameter. See the example below for more details.

The maya_texture_description File

This file describes which texture shading nodes are supported by MayaMan. It is similar to the maya_material_description file, but describes textures rather than materials.

The maya_magic_shaders.h File

This file contains the logic for emulating each of the Maya shading nodes. For each Maya node, there exists an equivalent chunk of RenderMan shader language code in this file.

For each supported node you will find two macros in maya_magic_shaders.h which look like:

#define LAMBERT_SETUP(_N_)
and
#define LAMBERT_SIM(_N_)
In these macros you define your emulation code. The '_N_' parameter is used so that multiple nodes of the same time can be present in one RenderMan shader source file. MayaMan will automatically use a different number when calling each macro. The _SETUP macro is used to initialise local variables and other things that can occur at the top of a source file. The _SIM macro is called to actually do the work.

The _SIM macro is ultimately responsible for setting the 'outColor' and 'outAlpha' variables, which must be referred to by prepending the '_N_' variable passed to the macro.

An Example Extension

If you had a 3rd party shader called 'simpleColor', which had a parameter called intensity. You could extend MayaMan to support that shader by adding the following entry to the maya_material_description file:
simpleColor
  intensity
You would then add the following macros to maya_magic_shaders.h:
#define SIMPLECOLOR_SETUP(_N_) /* do nothing for setup in this case */

#define SIMPLECOLOR_SIM(_N_)                        \
  color cat2(_N_,outColor) = color (1,0,0);        \
  cat2(_N_,outColor) *= cat2(_N_,intensity)
MayaMan could then use this new information to support this shader, ensuring that the value set in Maya's Hypershade for the 'intensity' parameter is passed in correctly. Also, if this were a texture node rather than a material node, then MayaMan would ensure that the value set here for 'outColor' was passed on to any other nodes using that output. The cat2() function used throughout maya_magic_shaders.h is a simple macro that concatenates identifiers together.

There are many examples to be found in the maya_magic_shaders.h file, so please refer to it for more help if you are writing your own extensions.

TIP: You can see the shader source that is written out by MayaMan. The source file is written to the 'shaders' subdirectory under the RIB output directory set in the MayaMan Basic Options. However, this file will contain many macros. You can use the cpp.exe pre-processor command included with BMRT to view the fully expanded source with a command such as:

d:\bmrt2.6\bin\cpp -Ic:\animallogic\mayaman\shaders c:\temp\mayaman\shaders\mms_lambert1.sl > expanded.sl
... this will write a fully expanded version into 'expanded.sl'. If you scroll to the bottom of that file you will see the bulk of the shader source code. View this to see if your node emulation code seems to be doing the correct thing after a MayaMan render.

Share The Wealth

If you have extended the Maya Magic Shaders functionality in a way that could be beneficial to others, it would be great if you could email your changes to support@al.com.au or use the MayaMan mailing list to tell others about it. We would also like to know if you have made any changes to the existing code in maya_magic_shaders.h which have yielded improvements in the emulation.

MayaMan Help Contents