This page contains links to the the source code for all the shaders in Writing mental ray shaders, organized by chapter. The source
code can also be downloaded from a single ZIP file described in the “Downloading examples from the book”
page.
Besides the source code for all the shaders, the ZIP file also
contains a shader library called “newblocks” that contains geometry
shaders used in many of the scenes in the
book. (These shaders are used for the construction of scene objects
and are not part of the book’s discussion of geometry shaders. I plan
to include techniques for procedural object construction in the “Additional shaders”
page.)
The shader catalog
All the shaders of the book are listed below by chapter, divided by
the five major parts in the book. For each shader page, the
declaration in .mi syntax is listed first, followed by the full C
source code. The declaration and C code are themselves links to an
unformatted file that can be downloaded individually. You can also
copy and paste individual sections of those pages.
If the shader contains miaux auxiliary functions (as introduced in
Chapter 7 with shader
depth_fade_tint_2),
they are listed after the shader source
code. For convenience, the miaux functions used in the shader are
contained in a separate file that for which the page also provides a
link. However, all miaux utility functions are declared together in miaux.h
and defined in miaux.c.
To see all the scene files in which a shader is used, click on the
“Scenes” link in the upper right corner of the shader source code page.
For example, shader one_color is used in many scenes in the book,
as you can see in this page.
A description of shader compilation is contained in the page “Shader
compilation on various platforms.”
The DLLEXPORT macro is declared in
the mental ray header file shader.h. This macro is is required for
compilation on Microsoft “Windows,” but is ignored during compilation
under other operating systems.
Part 2: Color
Chapter 5: A single color
Chapter 6: Color from orientation
Chapter 7: Color from position
Chapter 8: The transparency of a surface
Chapter 9: Color from functions
Chapter 10: The color of edges
Part 3: Light
Chapter 11: Lights
Chapter 12: Light on a surface
Chapter 13: Shadows
Chapter 14: Reflection
Chapter 15: Refraction
Chapter 16: Light from other surfaces
Part 4: Shape
Chapter 17: Modifying surface geometry
Chapter 18: Modifying surface orientation
Chapter 19: Creating geometric objects
Chapter 20: Modeling hair
Part 5: Space
Chapter 21: The environment of the scene
Chapter 22: A visible atmosphere
Chapter 23: Volumetric effects
Part 6: Image
Chapter 24: Changing the lens
Chapter 25: Rendering image components
Chapter 26: Modifying the final image
22 April 2008 23:52:09