Next: 3.1 Dynamic Linking of
Up: No Title
Previous: 2.9 Scene Example
All color, displacement, contour, and other computation in mental ray
is based on shaders. There are various types of shaders for different
situations, such as material shaders to evaluate the material
properties of a surface, light shaders to evaluate the light-emitting
properties of a light source, lens shaders to specify camera properties
other than the default pinhole camera, and so on.
There are external shader libraries that support compatibility with
Alias, Autodesk 3D Studio MAX, Dassault CATIA, SOFTIMAGE, SolidWorks,
Wavefront, and others. Much of the power of mental ray relies on the
possibility to write custom shaders and link them dynamically to mental
ray at runtime. Custom shaders are written in C or C++, using the full
language and library support available in these languages.
Here are the steps necessary to create a new shader:
-
Write a .mi declaration for the shader, providing the shader
name, return type, shader parameter names and types, and the
version to mental ray.
-
Write a C shader parameter data structure that agrees exactly
with the .mi parameter declaration. (The mkmishader
utility can do this translation.)
-
Write the shader function in C or C++, using the correct
signature. The shader computes a result from its shader
parameters and the state, and by calling shader interface
functions provided by mental ray.
-
Write a version shader (same name with _version appended
to the name) that returns a version number that matches the
version number in the .mi declaration.
-
If required, write initialization and exit shaders (same name
as the shader with _init and _exit appended,
respectively).
-
Compile and link the shader, and create a shared library (DSO
or DLL). This step can be omitted but DSO/DLLs are easiest to
use and much faster to link than objects or sources. Libraries
must be installed on all machines on the net that are used as
clients or network rendering servers.
-
Use a $include statement in the scene .mi file to load
the .mi declaration and a link (or code or $code) statement to load the shader DSO/DLL (or source code).
Note that if the shader is expected to work on Windows NT, all four
function definitions (the shader, the version function, and the init
and exit shaders) must be preceded with DLLEXPORT. This is a
pseudo type specifier that makes the functions visible to users of
the generated shader library. On Unix systems DLLEXPORT
evaluates to an empty word.
The shader is then ready to be used in the scene. These steps are
described in detail below.
Next: 3.1 Dynamic Linking of
Up: No Title
Previous: 2.9 Scene Example
Copyright 2000 by mental images