next up previous contents
Next: 3.4 State Variables Up: 3. Using and Writing Previous: 3.2 Coordinate Systems

3.3 Shader Type Overview

There are many types of shaders, all of which can be substituted by user-written shaders:

 

 

 

 

 

 

 

 

 

 

The following diagram illustrates the path of a ray cast by the camera. It first intersects with a sphere at point A. The sphere's material shader first casts a reflection ray that hits a box, then a refraction ray that intersects the sphere at its other side T, and finally it casts a transparency ray that also intersects the sphere, at D. (This example is contrived, it is very unusual for a material shader to cast both a refraction and a transparency ray.) The same material shader is called at points A, T, and D. In this example, the reflection trace depth may have prevented further reflection rays to be cast at T and D.





The annotations set in italics are numbered; the events described happen in the sequence given by the numbers.

Since material shaders may do inside/outside calculations based on the surface normal or the parent state chain (see below), the volume shaders are marked (1) and (2), depending on whether the volume shader left by A or by T/D in the refraction volume field of the state. The default refraction volume shader is the one found in the material definition, or the standard volume shader if the material defines no volume shader. For details on choosing volume shaders, see the section on writing material and volume shaders. Note that the volume shaders in this diagram are called immediately after the material shader returns.

   The next two diagrams depict the situation when the material shader at the intersection point M requests a  light ray from the light source at L, by calling a function such as  mi_sample_light. This results in the light shader of L to be called. No intersection testing is done at this point. Intersection testing takes place when shadows are enabled and the light shader casts shadow rays by calling mi_trace_shadow. This function is called only once but may result in more than one shadow shader call. There are four different modes for shadow casting, listed in the order of increased computational cost:

Note that the shadow segment mode requires complex shadow shaders to behave differently. Every shadow shader must be able to work with all these modes, so shadow shaders that deal with volumes or depend on the ray direction must test state - > options - > shadow to determine the mode. In case an incorrectly implemented shadow shader fails to call mi_trace_shadow_seg to evaluate other shadows, mental ray will call mi_trace_shadow_seg and then call the shadow shader again, thus simulating the effect.

The first diagram shows the ray casting order and the ray directions for the shadow on and shadow sort modes:





The next diagram shows the same situation in shadow segments mode:





The following diagram illustrates the path of a photon shot from the light source in the  caustics or  global illumination2.1preprocessing phase. First a photon is traced from the light source. It hits object A, and the photon material shader of object A is called. The photon material shader stores energy at the intersection point and determines how much energy is reflected and how much is refracted, and the directions of reflection and transmission. It then traces a new photon from A, in the reflection direction, or in the transmission direction, or both. The reflected photon hits object B, and the photon material shader of object B is called. The photon material shader of object B stores energy at the intersection point and shoots a new photon.





The remainder of this chapter describes how to write all types of shaders. First, the concepts of ray tracing state parameter passing common to all shaders are presented, followed by a detailed discussion of each type of shader.


next up previous contents
Next: 3.4 State Variables Up: 3. Using and Writing Previous: 3.2 Coordinate Systems
Copyright 2000 by mental images