Example use of gridpattern()

gridpattern() is a shading language function which returns a one or zero for each (varying) shading point on a shading grid according to a specified pattern.

Here is an example in which gridpattern is used to create a sort of poor-man's “wireframe” rendering. As noted in the gridpattern description, the precise size and shape of shading grids depends on many interacting factors, so specific resulting images will differ.

surface gridframe (float width=1;)
{
    varying float ctx = 0;
    varying float g = 0;
    uniform float w;
    for (w=0; w < width; w += 1) {
        g += gridpattern("concentric", ctx);
    }
    Ci = g + (1-g) * Cs * 0.8;

    Ci *= Os;
    Oi = Os; /* or less for see-thru "wireframe" */
}
##RenderMan RIB
FrameBegin 1
Display "gridframe.tif" "tiff" "rgba"
Format 256 192 1

# note: ShadingRate and gridsize greatly affect
# the density and size of grids, of course.
ShadingRate 2
Option "limits" "gridsize" [1000]
ShadingInterpolation "constant"

Projection "perspective" "fov" [30]
Translate 0 0 4
WorldBegin

Surface "gridframe" "float width" [1]

AttributeBegin
  Translate -20 -20 10
  Scale 40 40 40
  Color .2 .2 .4
  Patch "bilinear" "P" [0 1 0  1 1 0  0 0 0  1 0 0]
AttributeEnd
AttributeBegin
  Translate -0.75 -.35 -1
  Rotate -30 0 1 0
  Color .6 .6 .2
  Patch "bilinear" "P" [0 1 0  1 1 0  0 0 0  1 0 0]
AttributeEnd
AttributeBegin
  Translate .5 -.5 -1
  Rotate 80 0 1 0
  Translate 0 -.1 0
  Color 0 0 1
  Patch "bilinear" "P" [0 1 0  1 1 0  0 0 0  1 0 0]
AttributeEnd

WorldEnd
FrameEnd
 

Pixar Animation Studios
(510) 752-3000 (voice)   (510) 752-3151 (fax)
Copyright © 1996- Pixar. All rights reserved.
RenderMan® is a registered trademark of Pixar.