Programmable Ray Tracing I: Rayinfo
The first example uses the rayinfo() function to obtain information about rays fired in the scene. The second uses the gather() function to collect information from the points the rays hit. Both are provided as simple examples which can be extended to solve troublesome production problems that not easily solved using traditional techniques.
See the RenderMan documentation for more details on these types:
- depth - returns the current depth of the ray that caused this shader to be invoked. Depth is the sum of speculardepth, diffusedepth, and shadowdepth. Depth is 0 for camera rays (i.e. standard REYES invocation).
- type - returns the type of the ray that caused this shader to be invoked. See the RenderMan documentation for a complete list.
- label - returns the value of the user-defined label, assigned to the ray that caused this shader to be invoked.
- origin - returns the origin of the ray.
- direction - returns the normalized ray direction.
- length - returns the length of the ray.
- speculardepth, diffusedepth, shadowdepth - returns the depth of the type of ray that caused this shader to be invoked.
We are going to use rayinfo to extract information about the depth of rays flying around our scene (remember to have ray tracing enabled to get rays flying around the scene). We are going to build this code using a color SL box in Slim. We will extract the ray depth, then switch our textures based on this. The setup in Slim is straightforward. We have four texture nodes going into an SL box. They share one ST node, giving all of them the same texture coordinates. The SL box goes straight into the color channel of an incandescence layer of a Delux shader. The final palette is attached below.
color out = d0; float depth = 0; rayinfo("depth", depth); if(depth == 0) out = d0; else if (depth == 1) out = d1; else if (depth == 2) out = d2; else if (depth == 3) out = d3; else out = (1, 0, 0); //red!!! result = out;
The code above is simple and meant to illustrate the use of rayinfo. If unfamiliar with the SL box, see the HowTo here.
All we have is a color SL box with four texture inputs, d0 to d3. We create a float variable depth and use the rayinfo call to query the "depth" of the current ray, then assign it to our variable of the same name. This becomes the input for our conditional tests which switch between our textures, based on the ray depth.
In Maya, the only concern is setting up a material that traces refractions. This is not the default case using a Maya material, such as a Lambert. First, the material must be made transparent, then refraction must be enabled using the refraction checkbox in the material attributes.
The output provides insight into ray depths as specular rays trace through the scene. The depth of camera rays is zero. A reflection, or refraction, after that starts the ray depth counting. You can see the ray depth increase for rays reflected off the ground plane and through our magic transparent wall.Rayinfo Slim Palette
Project files .zip
Project files .rar Raytracing Fundamentals
HowTos - Programmable Raytracing II
Library - Programmable Ray Tracing