RSL
|
Overview
Displacement shaders alter the smoothness of a surface, however, unlike
bump mapping which mimics the appearance of bumpiness by reorientating
surface normals, displacement shading genuinly effects the geometry of a
surface. In the case of Pixars prman renderer, each object in a 3D scene
is sub-divided into a fine mesh of micro-polygons after which, if
a displacement shader has been assigned to an object, each micro-polygon
is "pushed" or "pulled" in a direction that is parallel to the original
surface normal of the micro-polygon. After displacing the micro-polygon
the orientation of the local surface normal (
The following algorithm lists the four basic steps that a displacement shader
generally follows in order to set the position (
To make a meaningful decision about the distance, if any, a micro-polygon should be displaced, a shader may make reference to the micro-polygon's,
plus other less obvious attributes of a micro-polygon. Such information is either directly or indirectly available in data the renderer makes available to a shader through the use of global variables. |
Displacement Shaders & Global Variables
The following table lists the global variables accessible to a displacement
shader. For the corresponding list of global variables available to a surface
shader refer to the tutorial
"RSL: What is a Surface Shader".
|
Using Cutter for Shader WritingIt is highly recommended the reader use Cutter for their shader writing. It has many very useful time saving features. Refer to the tutorial "Cutter: Shader Writing" for information about Cutter and how it should be set up. |
Basic CodeThe experiments on displacement shading in this tutorial are based the shader shown in listing 1. Listing 1
|
Texture Coordinates
Although micro-polygons have 3D xyz positions, given by the global variable
Use Cutter's Rman Tool palette to generate a rib file to test your shaders - figure 3. The poly-plane is set up to also cover one unit in texture space ie. Polygon "P" [-0.5 0 -0.5 -0.5 0 0.5 0.5 0 0.5 0.5 0 -0.5] "st" [0 0 0 1 1 1 1 0]
The first shader, listing 2, uses a simple " |
Listing 2
The edge of the raised band is aliased. For the moment we will ignore the defect.
The next shader uses the RSL |
Listing 3
Again, the aliased rim of the circle will be ignored.
|
Smoothstep
The shader in listing 4 uses the RSL Listing 4
Listing 5 provides additional parameters, s_center and t_center, to control the placement of the circle. |
Listing 5
|
Displacement Mapping
The shader in listing 6 implements simple image embossing. Although the Listing 6
The shader was used in the rib file in the following way. Displacement "test6" "texname" ["swazi.tx"] "Km" -0.20 The texture file "swazi.tex" was converted from the image shown in figure 9. For more information about converting tif files to textures refer to the tutorial "Writing Surface Shaders".
|
Noise I
The next shader uses the RSL Listing 7
Because the inputs to the |
Animated 'st' Noise
The shader in listing 8 applies an offset to the ' Listing 8
The banding seen in figures 11 and 12 are caused by a defect in the (Perlin) noise function. In theory the displacements should be smooth in all directions but there are discontinuities at the integer lattice. The defect is particularly noticable with large displacements. |
|
|
Animated 3D Noise
The shader in listing 9 uses a micro-polygons xyz position (
Listing 9
|
The principle issue with the shader is that point ' Listing 10a
|
Displacement "test10" "space" ["object"] |
Displacement "test10" "space" ["myspace"] |
The rib file used to render figure 15 defined a user-defined coordinate system as follows. Listing 10b
|
TurbulanceA simulation of turbulance or fractal noise can be achieved by using the noise() within a loop. On each iteration of the loop the value returned from noise() is added to the result of the previous iteration. Successfully higher frequencies but smaller amplitudes are used for iteration. The visual result is richer because the shading can appear to mimic natural surfaces ie. large bumps have small bumps which in turn have enen smaller Listing 11a
The problem with applying a displacement directly with the value returned from
|
|
|
In listing 11b a constant value of 0.5 is substracted from the noise value. In general it is a good idea to always subtract 0.5 from noise. Listing 11b
Some interesting visual effects can also be created by ensuring the value returned
from noise() is always positive. Listing 11c uses the |
Listing 11c
|
Ripples
Listing 3 demonstrated the use of the RSL Listing 12a
Ripples in a pool of water, say as the result of a drop of rain, normally propogate outward as 2 or 3 concentric waves. Listing 12b applies a constraint on the ripples seen in figure 20 in order to mimic the rain-drop effect. The constraint is based on a double use of the smoothstep() function. For more information about this RSL function refer to the tutorial "RSL: Using smoothstep". Listing 12b
|
© 2002- Malcolm Kesson. All rights reserved.