Surface Shaders
Light Source Shaders
Volume Shaders
Displacement Shaders
Imager Shaders
When a shader is attached to a geometric primitive it inherits a set of varying variables that completely defines the environment in the neighborhood of the surface element being shaded. These state variables are predefined and should not be declared in a Shading Language program. It is the responsibility of the rendering program to properly initialize these variables before a shader is executed.
All the predefined variables which are available to each type of shader are shown in:
In these tables the top section describes state variables that can be read by the shader. The bottom section describes the state variables that are the expected results of the shader. By convention, capitalized variables refer to points and colors, while lowercase variables are floats. If the first character of a variable's name is a C or O, the variable refers to a color or opacity, respectively. Colors and opacities are normally attached to light rays; this is indicated by appending a lowercase subscript. A lowercase d prefixing a variable name indicates a derivative.
All predefined variables are considered to be readonly, with the exception of the result variables, which are readwrite in the appropriate shader type, and Cs, Os, N, s and t, which are readwrite in any shader in which they are readable. Vectors are not normalized by default.
The geometry is characterized by the surface position P which is a function of the surface parameters (u,v). The rate of change of surface parameters are available as (du,dv). The parametric derivatives of position are also available as dPdu and dPdv. The actual change in position between points on the surface is given by P(u+du)=P+dPdu*du and P(v+dv)=P+dPdv*dv. The calculated geometric normal perpendicular to the tangent plane at P is Ng. The shading normal N is initially set equal to Ng unless normals are explicitly provided with the geometric primitive. The shading normal can be changed freely; the geometric normal is automatically recalculated by the renderer when P changes, and cannot be changed by shaders. The texture coordinates are available as (s,t). Figure 12.1 shows a small surface element and its associated state.
The optical environment in the neighborhood of a surface is described by
the incident ray I
and light rays L
. The incoming
rays come either directly from light sources or indirectly from other surfaces.
The direction of each of these rays is given by L
; this direction
points from the surface towards the source of the light. A surface shader
computes the outgoing light in the direction I
from all the
incoming light. The color and opacity of the outgoing ray is Ci
and Oi
. (Rays have an opacity so that compositing can be done
after shading. In a ray tracing environment, opacity is normally not computed.)
If either Ci
or Oi
are not set, they default to
black and opaque, respectively.
Figure 12.1 Surface shader state
(click on image to view a larger version)
Table 12.1 Predefined Surface Shader Variables
Name  Type  Storage Class  Description  

Cs  color  varying/uniform  Surface color  
Os  color  varying/uniform  Surface opacity  
P  point  varying  Surface position  
dPdu  vector  varying  Derivative of surface position along u  
dPdv  vector  varying  Derivative of surface position along v  
N  normal  varying  Surface shading normal  
Ng  normal  varying/uniform  Surface geometric normal  
u,v  float  varying  Surface parameters  
du,dv  float  varying/uniform  Change in surface parameters  
s,t  float  varying  Surface texture coordinates  
L  vector  varying/uniform  Incoming light ray direction*  
Cl  color  varying/uniform  Incoming light ray color*  
Ol  color  varying/uniform  Incoming light ray opacity*  
E  point  uniform  Position of the eye  
I  vector  varying  Incident ray direction  
ncomps  float  uniform  Number of color components  
time  float  uniform  Current shutter time  
dtime  float  uniform  The amount of time covered by this shading sample  
dPdtime  vector  varying  How the surface position P is changing per unit time, as described by motion blur in the scene.  
Ci  color  varying  Incident ray color  
Oi  color  varying  Incident ray opacity 
* Available only inside illuminance statements.
A light source shader is slightly different (see Figure
12.2, Light source shader state). It computes the amount of light cast along
the direction L
which arrives at some point in space Ps
.
The color of the light is Cl
while the opacity is Ol
.
The geometric parameters described above (P, du, N
, etc.) are
available in light source shaders; however, they are the parameters of the light
emitting surface (e.g., the surface of an area light source)not the
parameters of any primitive being illuminated. If the light source is a point
light, P
is the origin of the light source shader space and the
other geometric parameters are zero. If either Cl
or Ol
are not set, they default to black and opaque, respectively.
Figure 12.2 Light Source Shader State
(click on image to view a larger version)
Table 12.2 Predefined Light Source Variables
Name  Type  Storage Class  Description 

P  point  varying  Surface position 
dPdu  vector  varying  Derivative of surface position along u 
dPdv  vector  varying  Derivative of surface position along v 
N  normal  varying  Surface shading normal 
Ng  normal  varying/uniform  Surface geometric normal 
u,v  float  varying  Surface parameters 
du,dv  float  varying/uniform  Change in surface parameters 
s,t  float  varying  Surface texture coordinates 
L  vector  varying/uniform  Incoming light ray direction* 
Ps  point  varying  Position being illuminated 
E  point  uniform  Position of the eye 
ncomps  float  uniform  Number of color components 
time  float  uniform  Current shutter time 
dtime  float  uniform  The amount of time covered by this shading sample. 
Cl  color  varying/uniform  Outgoing light ray color 
Ol  color  varying/uniform  Outgoing light ray opacity 
* Only available inside solar or illuminate statements.
A volume shader is not associated with a surface, but rather attenuates a
ray color as it travels through space. As such, it does not have access to any
geometric surface parameters, but only to the light ray I
and its
associated values. The shader computes the new ray color at the ray origin
PI
. The length of I
is the distance traveled
through the volume from the origin of the ray to the point P
.
Table 12.3 Predefined Volume Shader Variables
Name  Type  Storage Class  Description 

P  point  varying  Light ray origin 
E  point  uniform  Position of the eye 
I  vector  varying  Incident ray direction 
Ci  color  varying  Ray color 
Oi  color  varying  Ray opacity 
ncomps  float  uniform  Number of color components 
time  float  uniform  Current shutter time 
dtime  float  uniform  The amount of time covered by this shading sample. 
Ci  color  varying  Attenuated ray color at origin 
Oi  color  varying  Attenuated ray opacity at origin 
The displacement shader environment is very similar to a surface shader,
except that it only has access to the geometric surface parameters. It computes
a new P
and/or a new N
. In rendering
implementations that do not support the
Displacement capability, modifications to P
will not
actually move the surface (change the hidden surface elimination calculation);
however, modifications to N
will still occur correctly.
Table 12.4 Predefined Displacement Shader Variables
Name  Type  Storage Class  Description 

P  point  varying  Surface position 
dPdu  vector  varying  Derivative of surface position along u 
dPdv  vector  varying  Derivative of surface position along v 
N  normal  varying  Surface shading normal 
Ng  normal  varying/uniform  Surface geometric normal 
I  vector  varying  Incident ray direction 
E  point  uniform  Position of the eye 
u,v  float  varying  Surface parameters 
du,dv  float  varying/uniform  Change in surface parameters 
s,t  float  varying  Surface texture coordinates 
ncomps  float  uniform  Number of color components 
time  float  uniform  Current shutter time 
dtime  float  uniform  The amount of time covered by this shading sample. 
P  point  varying  Displaced surface position 
N  point  varying  Displaced surface shading normal 
An imager shader manipulates a final pixel color after all of the
geometric and shading processing has concluded. In the context of an imager
shader, P
is the position of the of the pixel center in raster
space, with the z
component being 0.
Table 12.5 Predefined Imager Shader Variables
Name  Type  Storage Class  Description 

P  point  varying  Surface position 
Ci  color  varying  Pixel color 
Oi  color  varying  Pixel opacity 
alpha  float  uniform  Fractional pixel coverage 
ncomps  float  uniform  Number of color components 
time  float  uniform  Current shutter time 
dtime  float  uniform  The amount of time covered by this shading sample. 
Ci  color  varying  Output pixel color 
Oi  color  varying  Output pixel opacity 
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of Pixar. The information in this publication is furnished for informational use only, is subject to change without notice and should not be construed as a commitment by Pixar. Pixar assumes no responsibility or liability for any errors or inaccuracies that may appear in this publication.
Pixar Animation Studios
