RManNotes

previous | next | regular patterns: contents | rmannotes: top

Shape Generation

Simple, geometric shapes can be made in the RenderMan Shading Language using smoothstep or pulse often with one of two shading language distance functions:

Further, simple geometric shapes can be combined to generate more complex shapes using boolean set operations (union, intersection, difference, and complement).

RenderMan Shading Language function

float distance(point p1, p2)
float ptlined(point a, b, p)


Graphic interpretation of (a) d = distance(p1,p2); and (b) d = ptlined(a,b,p).

Rectangles

Rectangular shapes can be made by intersecting (multiplying) a vertical pulse and a horizontal pulse. (In fact you can use intersection instead of the multiplication operator.)


rect.sl

Disks and Rings

Disks and rings can be generated using distance and either smoothstep (for a disk) or pulse (for a ring). The idea for disks is simple: if the distance between the current shading point and the center of the disk is less than the radius of the disk, then the current shading point is inside the disk. In terms of a pulse, we have:

where d is the distance between the current shading point and the center of the disk. Note that this pulse is generated by 1 - smoothstep(radius - fuzz, radius, d). The corresponding shader is shown below.


disk.sl

The idea for rings is identical, except that a pulse is used instead of smoothstep.


ring.sl

Lines

Lines are generated like disks except that the distance is computed from the current shading point to the nearest point on the line using ptlined.


line.sl

Boolean Operations

Constructive solid geometry (CSG) is used in solid modeling systems to create complex shapes from the union, intersection, or difference of 2 simpler shapes. These are referred to as "boolean" operations since they operate on only 2 shapes at a time (with the exception of "complement"). While CSG is difficult to do with 3D b-reps, it's trivial to do with procedural shapes in shaders.


moon.sl

RManNotes function

float union(float a, b)
float difference(float a, b)
float intersection(float a, b)
float complement(float a, b)

Boolean operations. Each returns a value between 0 and 1 and requires inputs between 0 and 1. The implementations are from [Perlin89].

Below are illustrations of the various boolean operations based on disk and square shapes.

disk = D square = S
union(D,S) intersection(D,S)
difference(D,S) difference(S,D)
complement(difference(D,S)) union(difference(S,D), difference(D,S))

Finally, the disk_ring shader illustrates a masking effect between different shapes repeated at different scales.


diskring.sl

previous | next | regular patterns: contents | rmannotes: top

RManNotes is Copyright © 1995, 1996 Stephen F. May

Any comments or suggestions appreciated.

Steve May (smay@pixar.com)

Last Modified: 4/15/96