Keywords: main

Next: 3.25 Example Scene with Up: 3. Using and Writing Previous: 3.23 Automatic Source Generation

# 3.24 Shaders and Trace Functions

Trace functions are functions provided by mental ray that allow a shader to cast a ray into the scene, most of them using standard ray tracing. Not all types of tracing functions can be used in all types of shaders. Conversely, many trace functions cause shaders to be called. This chapter lists these interdependencies.

The following list shows which shaders are called from which trace functions. N means no, Y means yes. Displacement, contour, and photon shaders are never called by any of the functions, and may not call any of them.

| lens | mtl | env | light | shad | vol
mi_trace_eye | Y | Y | Y | N | N | Y
mi_trace_reflection | N | Y | Y | N | N | Y
mi_trace_refraction | N | Y | Y | N | N | Y
mi_trace_transparent | N | Y | Y | N | N | Y
mi_trace_environment | N | N | Y | N | N | Y
mi_trace_light | N | N | N | Y | N | Y
mi_sample_light | N | N | N | Y | N | Y
mi_trace_shadow | N | N | N | N | Y | N
mi_trace_shadow_seg | N | N | N | N | Y | Y

Environment rays do not have entries in this tree. The data in the tree is used for acceleration and can be overridden if a shader wants to cast rays not normally allowed, by setting the state variable state- >cache to zero. This should only be done if necessary because it reduces efficiency. The following table shows which trace functions may be called from which shaders:

|  |  |  |  |  | ray | light
| lens | mtl | env | light | shad | vol | vol
mi_trace_eye | Y | N | N | N | N | N | N
mi_trace_reflection | ** | Y | * | ** | ** | Y | **
mi_trace_refraction | ** | Y | * | ** | ** | Y | **
mi_trace_transparent | ** | Y | * | ** | ** | Y | **
mi_trace_environment | * | Y | Y | * | Y | Y | Y
mi_trace_light | * | Y | * | ** | ** | Y | **
mi_sample_light | * | Y | * | ** | ** | Y | **
mi_trace_shadow | N | N | N | Y | N | N | Y
mi_trace_shadow_seg | N | N | N | N | Y | N | N

- N no

- Y yes

- * yes, if the shader generates an artificial intersection point by setting point, normal, and normal_geom in the state.

- ** yes, if the shader removes RC's internal ray tree data by setting cache in the state to `NULL` and generates an artificial intersection point if none is present.

Next: 3.25 Example Scene with Up: 3. Using and Writing Previous: 3.23 Automatic Source Generation