Home

 

Slim Templates

 

Inside/Outside Shading

 

Translucency Shading

 

Point Clouds & Brick Maps

 

Custom Mental Ray Shaders

 

City Explosion

 

Custom Mental Ray Shaders



To gain a better understanding of the complexity involved in writing custom shaders, my class spent three weeks developing custom Mental Ray shaders and tackling any problems that arose. The process was actually very problematic and gave me a much greater appreciation for the way Pixar's Renderman renderer and the Renderman Shading Language (RSL) were designed.
Many people use Mental Ray because creating a shading network is very easy and render times are relatively low considering setup time and final image quality. However, the development of a custom Mental Ray shader would be advantageous because the user would have full control over aesthetics AND performance. While the value of control over aesthetics is obvious, rendering performance is an area of great importance too. If a scene is too complex or setup inefficiently, Mental Ray will often crash or have horrible render times. In a film production setting, single computer generated frames can take hours if not days to render. If this time were shortened, an enormous amount of money and time could be saved and surely the shader developer responsible wouldn't fret for work. In addition, having control over how a shader functions would allow a user to create effects that normally can't be achieved through Mental Ray's standard library of nodes.


One of our first tasks was to export a model out of Maya for shader testing. The object was exported as a .mi file and then manually edited. After that, we created a simple test scene. Similar to Renderman's .rib files, we edited parameters in the .mi file to better understand how the Mental Ray renderer functions and reads in values.


The shader settings applied here mimic the normal mapping coloration often used in console games.


To gain experience at writing Mental Ray shaders from scratch, we approached the development process by achieving a simple effect first and then build up the shader's functionality and complexity. The first step was implementing a sine wave. The top portion would be one color and the bottom area another.
A parameter was added that acted as a vertical offset. The sine wave could then be shifted up and down.
Some parameters that control the wave's amplitude and frequency were added too.
Lastly we experimented with a math function called "fabs" which returned the absolute value of a float number. A switch was then created that could invert the values to give the two versions below.

Problematic Issues


  1. After writing shaders with RSL, the most prominent difference in writing custom Mental Ray shaders was the amount of text editing required. I roughly estimate that it took somewhere between 6 to 8 times more coding and the syntax was much more difficult to follow. For example: Multiplying a surface's color with other values could be done within one line of text in RSL, but for a Mental Ray shader, a custom function had to be written that individually calculated the red, green, and blue components. Several lines of code were written just to achieve the same functionality as the asterick (*) in RSL.
  2. In a classroom setting, the users don't have access to Maya's system files. This created a significant problem when developing custom Mental Ray shaders and made the process even more complicated. Fortunately, our professor wrote a text editing program called Cutter that helped automate parts of the process.
  3. Our shaders couldn't be compiled within Windows. Linux was used instead for its compiler.
  4. Certain files, such as Maya's rayrc file and exported .mi files, need to be manually edited.
  5. Our custom shaders could not be imported correctly into Maya.

Conclusion


While every renderer has its strengths and weaknesses, this exercise has made me a Renderman advocate and very respectful of the software developers at Pixar. They have a great sense of foresight and design with a user's needs in mind. Prior to this experience, I knew that Renderman was stable and could create some very appealing imagery with speed. After coding for Mental Ray, RSL seems to be superior in every way. It gives an artist full control over aesthetics and performance while hiding the tedious technical tidbits that users shouldn't have to deal with. Renderman keeps things simple with impressive results.

Files Used:
Teddy Bear .mi File
Teddy Bear Test Scene
Sine Wave Custom Shader

 

Richard Sun / Rich Sun Productions 2007.