Shader Execution Environment

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 lower-case 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 read-only, with the exception of the result variables, which are read-write in the appropriate shader type, and Cs, Os, N, s and t, which are read-write in any shader in which they are readable. Vectors are not normalized by default.

Surface Shaders

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 ClassDescription
Cs colorvarying/uniform Surface color
Oscolorvarying/uniformSurface opacity
P pointvaryingSurface position
dPdu vectorvaryingDerivative of surface position along u
dPdv vectorvaryingDerivative of surface position along v
N normalvaryingSurface shading normal
Ng normalvarying/uniformSurface geometric normal
u,v floatvaryingSurface parameters
du,dv floatvarying/uniformChange in surface parameters
s,t floatvaryingSurface texture coordinates
L vectorvarying/uniformIncoming light ray direction*
Cl colorvarying/uniformIncoming light ray color*
Ol colorvarying/uniformIncoming light ray opacity*
E pointuniformPosition of the eye
I vectorvaryingIncident ray direction
ncomps float uniformNumber of color components
time floatuniform Current shutter time
dtimefloatuniformThe amount of time covered by this shading sample
dPdtimevectorvaryingHow the surface position P is changing per unit time, as described by motion blur in the scene.
Ci colorvaryingIncident ray color
Oi colorvaryingIncident ray opacity

* Available only inside illuminance statements.


Light Source Shaders

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 ClassDescription
P pointvaryingSurface position
dPdu vectorvaryingDerivative of surface position along u
dPdv vectorvaryingDerivative of surface position along v
N normalvaryingSurface shading normal
Ng normalvarying/uniformSurface geometric normal
u,v floatvaryingSurface parameters
du,dv floatvarying/uniformChange in surface parameters
s,t floatvaryingSurface texture coordinates
L vectorvarying/uniformIncoming light ray direction*
PspointvaryingPosition being illuminated
E pointuniformPosition of the eye
ncomps floatuniformNumber of color components
time floatuniform Current shutter time
dtime floatuniform The amount of time covered by this shading sample.








Cl colorvarying/uniform Outgoing light ray color
Ol colorvarying/uniform Outgoing light ray opacity

* Only available inside solar or illuminate statements.


Volume Shaders

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 P-I. 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 ClassDescription
P pointvaryingLight ray origin
E pointuniformPosition of the eye
I vectorvaryingIncident ray direction
CicolorvaryingRay color
Oi colorvaryingRay opacity
ncomps floatuniformNumber of color components
time floatuniform Current shutter time
dtime floatuniform The amount of time covered by this shading sample.








Ci colorvaryingAttenuated ray color at origin
Oi color varyingAttenuated ray opacity at origin

Displacement Shaders

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 ClassDescription
P pointvaryingSurface position
dPdu vectorvaryingDerivative of surface position along u
dPdv vectorvaryingDerivative of surface position along v
N normalvaryingSurface shading normal
Ng normalvarying/uniformSurface geometric normal
I vectorvaryingIncident ray direction
E pointuniformPosition of the eye
u,v floatvaryingSurface parameters
du,dv floatvarying/uniformChange in surface parameters
s,t floatvaryingSurface texture coordinates
ncomps floatuniformNumber of color components
time floatuniform Current shutter time
dtime floatuniform The amount of time covered by this shading sample.








P pointvaryingDisplaced surface position
NpointvaryingDisplaced surface shading normal

Imager Shaders

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 TypeStorage ClassDescription
P pointvaryingSurface position
Ci colorvaryingPixel color
Oi colorvaryingPixel opacity
alpha floatuniformFractional pixel coverage
ncomps float uniformNumber of color components
time floatuniformCurrent shutter time
dtime floatuniform The amount of time covered by this shading sample.








Ci colorvaryingOutput pixel color
Oi colorvaryingOutput 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
(510) 752-3000 (voice)   (510) 752-3151 (fax)
Copyright © 1996- Pixar. All rights reserved.
RenderMan® is a registered trademark of Pixar.