Before the renderer calculates the shading of an object, the surface of that object is divided up into tiny individual flat surfaces, called surface elements or micropolygons. Each element is a single plane. This allows the renderer to calculate a normal for that tiny area of the surface. The size of this area can be controlled by the Shading Rate in the Render Options Editor. If you decrease the Shading Rate, more smaller micropolygons are generated for the surface and the closer the rendered surface fits the geometrically defined surface. The purpose of a Displacement Shader is to tell the renderer the new position for each micropolygon. The only operation box required in a Displacement Shader is one of the 'Displacement' boxes:
This box outputs:
This single box can actually be a 'Displacment Shader' all by itself. If VAL is not 0, changing the amplitude, AMP will change the size of the entire object. However you may use a pattern or math function to change the micropolygons' position procedurally. Patterns and math functions return floating point values which can be used to vary the amount of displacement across the surface.
This is an example of a simple procedural Displacement Shader:
In this case we're controlling the amount of the displacement using the checks pattern. The output value is either 1 or 0, which turns the displacement on or off. You can control the amplitude of the displacement by changing the AMP value on the displacement box. As you raise the amplitude of the displacement, you will start to notice little "rips" in the rendering. These are caused when the renderer "misses" an intersection with the new surface. To solve this problem, you will want to set the Displace Bound in the Render Options Editor. This will increase the size of the bounding box by the selected percentage. The bounding box of an object is area in the scene where the renderer searches for that object. The rendered image looks like:
You may also use a texture map to control the displacement values across the surface. Since all but single channel maps return a color, you will want to use either one of the 4 channels, red, green, blue, alpha or the intensity or the luminence value of the map.
This is an example of a textured Displacement Shader:
The rendered image looks like:
It is important to remember:
The more intricate the pattern or texture used to generate the displacement is, the lower the Shading Rate needs to be set in the Render Options Editor to pick out those intricacies. This is also true in sharpening the effects of a Displacement Shader. The more micropolygons, the sharper the focus. In the above example, the Shading Rate is set to 0.25, which substantially increases the rendering time. This needs to be kept in mind when developing Displacement Shaders.
To learn more about Displacement Shaders check out the pages under the RenderMan Toolkit3.7 Application Notes, specifically Application Note #12.