The purpose of this tutorial is to demonstrate how Cutter is used to
compile a shader and render a simple scene. Following the steps outlined in
the tutorial will also enable the reader to check if they have set up Cutter
so that it can use mental ray properly. The recently published reference book on the subject of
shader writing is,
Creating a Custom Shader
Setp 1 - Using a Shader (MiC) Template
From Cutter's Templates menu choose "tinted_occlusion.c" - figure 1. Popups will appear as the user runs the mouse over the names of the templates.
An untitled copy of the template file will open. The source code for the shader is shown below.
Listing 1 - tinted_occlusion.c
Setp 2 - Save the Shader Code
Save the file as "tinted_occlusion.c" in your "shader_src" directory ie.
Setp 3 - Compiling & Linking
Compile and link the shader using the (execute) keyboard shortcut Alt + e, or Control + e, or Apple + e. Cutter's Process Monitor window will show any information, warning or error messages issued by the compiler - figure 2.
To see the command used by Cutter, as a result of using the keyboard shortcut, select the "Options" tab - figure 3. Cutter generates and runs a makefile (or VS8 bat file) for each shader the user compiles. Under most circumstances it will not be necessary for a user to write their own makefiles or VS8 bat files. The compiled shader will be saved in the directory specified in Cutter's preferences - refer to the tutorial "mental ray: Cutter Preferences".
In the "background" Cutter writes and saves a shader .mi (listing 2) file. A copy of the file is also saved in the users "shaders" directory.
Listing 2 - tinted_occlusion.mi (generated by Cutter)
In particular, note the values within the square brackets of the comments of tinted_occlusion.c.
miUint samples; /* default  */ miColor tint; /* default [1 1 1] */
They have been used by Cutter as default values within tinted_occlusion.mi.
integer "samples", #: min 0 max 1 default 16 # default color "tint" #: default 1 1 1 # default
Specifying values, within square brackets, in the shader source code file is a very convenient way of controlling the defaults in the .mi file.
Rendering a Simple Scene
Setp 1 - Using a Scene (Mi) Template
The next template demonstrates how the tinted_occlusion shader is referenced and used by a .mi scene file. Choose "tinted_occlusion_scene.mi" from the Templates menu - figure 4.
Setp 2 - Save the Scene
Save the file as "tinted_occlusion_scene.mi" in your "scenes" directory ie.
Setp 3 - Render the Scene
The keyboard shortcut used to compile a shader also renders a scene file. The Process Monitor will display messages issued by mental ray - figure 5. Cutter's RayView tool, figure 6, will display the image as it is being rendered by mental ray.
Shader Writing Workflow
When writing a shader it is generally best to have not only its 'C' language source code
file open but also a .mi scene file (not to be confused with a .mi shader file) that references the shader. After making a change to
the shader code, use the keyboard shortcut, alt + e, control + e or Apple + e, to compile
and link a "fresh" version of the shader. Use the same keyboard shortcut to render the
scene file. This edit-compile-render loop, all done from within Cutter, is the fastest
way to develop/experiment with a shader. Of course, once the initial development work has
been completed the shader should be tested thoroughly in Maya.
The Transforms Tool
The mental images scene description protocol does not have individual transformation commands, such as Rotate, Translate and Scale. Instead, transforms must be specified directly using a 4 x 4 transformation matrix. This makes it very difficult for a user to adjust the placement and orientation of the camera, or other "objects" in the scene. To overcome the horrors of trying to adjust transformation matrices, Cutter provides users with a floating palette, called the Transforms Tool (figure 7). It is available from the Tools menu.
With the text cursor placed in the
Some Common Errors
If the renderer reports these errors,
LINK 0.0 error 191014: tinted_occlusion.so: load failed MI 0.0 error 121417: tinted_occlusion_scene.mi, line 8: cannot find $include file "tinted_occlusion.mi"
it most likely because one or more paths in the readers custom rayrc file is incorrect - refer to
the tutorial "mental ray: Setup for CD vol III".
__________  2.59:4PM __________ WARNING (/usr/local/mi/mrdemo/bin/ray): Can't connect to 127.0.0.1 ("mi-spm"[tcp/7050]) (61: Connection refused) WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost0() ("mi-spm"[tcp/7050]) does not respond WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost1 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost2 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost3 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost4 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost5 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost6 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost7 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost8 is an unknown host WARNING (/usr/local/mi/mrdemo/bin/ray): spmhost9 is an unknown host FATAL ERROR (/usr/local/mi/mrdemo/bin/ray) at 10/14/2008 14:59:33 : Can't connect to any SPM license server. RENDERING COMPLETED: UNSUCCESSFULL Errors: 5 Warnings: 15
To restart the spm license server, open a terminal and enter these commands.
% sudo -s (enter the admin password, then enter) % /var/spm/spmd_ib
The status of the server can be querried using this command.
© 2002- Malcolm Kesson. All rights reserved.