RenderMan Shading Language

From K-3D

Jump to: navigation, search


Individual shaders are small sub-routines (functions) written in a specialised programming language called the RenderMan Shading Language. The language enables new shaders to extend the creative possibilities of the renderer; it allows computer artists to find endless ways of controlling the appearance of a 3D scene through the use of custom shaders.

RenderMan divides the rendering process into five tasks each of which uses a distinctive type of shaders.

  • Surface Shader - Describe the appearance of surfaces and how they react to the lights that shine on them.
  • Displacement Shader - Describe how surfaces wrinkle or bump.
  • Light Shader - Describe the directions, amounts, and colors of illumination distributed by a light source in the scene.
  • Volume Shader - Describe how light is affected as it passes through a participating medium such as smoke or haze.
  • Imager Shader - Describe color transformations made to final pixel values before they are output.

This is just a brief introduction to the RenderMan Shading Language, for more details please refer to the RenderMan Interface Specification.


Much like the 'C' language, the RenderMan Shading Language uses variables to store data. Each time a shader is called (used by the renderer) it gets data from these places.

  • The default values of the parameters, called instance variables, of the shader (you will set these defaults for your own shaders.)
  • The modified values of the instance variables (users of your shader may override the default values.)
  • The global variables (from the renderer itself.)

Shaders use global variables to READ data FROM the renderer (shader input), for example, the color of a surface.

Shaders use some global variables to WRITE data TO the renderer (shader output), for example, the apparent color of the light leaving the surface being shaded.

Take a look at the page for each shader type to find out what global variables are available.


The RenderMan Shading Language is strongly typed were variables can be of the following datatypes.


A float are used to store any numerical value, unlike many other languages RenderMan shaders doesn't make any difference between integers and floats.

Floating-point variables are defined as follows:

 float a, b = 1;

The initiation may be any scalar expression.


A color represents the color and intensity of a light, or the reflectivity and opacity of a surface. The RenderMan Shading Language implements color as an abstract data type independent of the numbers of samples or color space. Color components values of 0 correspond to minimum intensity, and values of 1 to maximum intensity. Values outside that range are allowed.

Color variables may be declared with:

 color c, d = 1, e = color(1,0,0);

The initiation may be any scalar or color expression. A scalar expression is duplicated to each color component.


These are (x,y,z) triplets of floats to represent positions, direction vector or normal in space. A vector hold a direction vector. A point represent a position in space. And a normal represent a surface normal.

Point-like variables are declared:

 point u, v = 1, w = point(1,1,1)

The initiation may be may be any scalar or point-like expression. A scalar expression is duplicated to each component.

Transformation Matrix

The RenderMan Shading Language has a matrix type that represents a transformation matrix required to transform points and vectors from one coordinate system to another. Matrices are represented by 16 floats, a 4x4 homogeneous transformation matrix.


A string are used to name external objects. String literals are enclosed in double quotes an may contain any if the standard escape characters.


The RenderMan Shading Language supports 1D arrays of all the basic data types.

 float a[10];
 uniform color C[4];
 float b[3] = { -1.0, 2, 3.14 };







Control Structures







Header Files


Meta Files

How does K-3D process shaders and what are those .slmeta files ?

When K-3D is launched, it scans through the shader source directory(s) that have been specified. Run "k3d --help" or check the man page to see how you can override the default shader directory.

For each *.sl file K-3D finds it:

  1. Looks for a corresponding Shading Language Metafile (*.sl.slmeta file). If the metafile exists, it loads it and parses it (the metafile is XML). The metafile contains information about the shader, its author, copyright, description, shader arguments, their types, and their default values.
  1. If the *.sl.slmeta file doesn't exist, the shader is ignored.

Testing Shaders

A note for shader authors: K-3D will recompile a shader anytime it's changed, so for shader development you can create a simple document that uses the shader, open the shader source in your favorite editor, and alternate between making changes and rendering to see the results. The only current limitation is that the shader arguments are only read from the shader metafile once at program startup, so if you add new arguments to your shader you'll have to modify the metafile and restart K-3D.

Personal tools