Digital Lighting: Shader Lab
return to course
One-line Shaders
Tues May 6, 10:30am

Description
In this lab, we'll create and experiment with a series of "one-line"
shaders and quickly test them out on a flat grid object.
Setup
- Create a new directory in your home area and change directory (cd) to it.
Start up your favorite text editor and create a new file
called experiment.sl. Put the following text
in the file and save it.
surface experiment()
{
Ci = color (1,0,0);
}
- The above is a complete RenderMan shader.
Compile it by using the
shader command with
the name of the shader text file experiment.sl.
> shader experiment.sl
experiment:
If the shader program prints output other than that above or it prints an error message, double
check experiment.sl to make sure it is exactly the same as the text described in step 1.
- Place a copy of the rib file patch.rib in the same directory.
-
Type the command: render patch.rib
You should see an image of a flat, red square on a black background.
The object is a simple grid (actually a bilinear patch) with the
shader you just compiled, experiment, applied to it.
Experiment Process
In each of the following experiments, do the following:
- Replace the 3rd line in experiment.sl, which looks like:
Ci = color (1,0,0);
with the new, specified line;
- Recompile the experiment shader
- Re-render the patch
- Observe the results and understand what's going on before you move
on to the next experiment. You may want to make a few notes.
Emacs Tips
These tips will save valuable time when writing & testing shaders
that are edited in Emacs.
- When you have a shader file (.sl) in the current buffer, Ctrl-c
Ctrl-c will compile that shader.
- Ctrl-c Ctrl-r will rerender your current rib file.
Experiments
Note: You should do all the experiments in order, but if at any time you feel like creating your own
experiments, do so! Experiment as much as possible!
- Ci = color "hsv" (0.5, 0.8, 0.3);
- Ci = s;
- Ci = t;
- Ci = color (s, 0, 0);
- Ci = color (0, t, 0);
- Ci = color "hsv" (s, 1, 1);
- Ci = color "hsv" (0, t, 1);
- Ci = color "hsv" (0, 1, t);
- Ci = color (s, t, 0);
- Ci = step(0.5, s);
- Ci = step(0.2, s);
- Ci = step(0.5, t);
- Ci = smoothstep(0.4, 0.6, s);
- Ci = smoothstep(0.1, 0.9, s);
- Ci = mod(s, 1.0);
- Ci = mod(s * 5, 1.0);
- Ci = step(0.5, mod(s * 5, 1.0));
- Ci = smoothstep(0.4, 0.6, mod(s * 5, 1.0));
- Ci = mix(color (1,0,0), color (0,0,1), s);
- Ci = mix(color (1,0,0), color (0,0,1), smoothstep(0, 1, s));
- Ci = spline(t, color (1,1,0), color (1,1,0), color (0,1,0), color
(0,0,1), color (0,0,1));
Extras
- A tile...
Ci = step(t, s);
- A texture map...
Ci = texture("pebbles.tex");
- Noise at low frequency...
Ci = noise(s, t);
- Noise at medium frequency...
Ci = noise(s * 10, t * 10);
- Noise at high frequency...
Ci = noise(s * 50, t * 50);
- Fancy (a 5-line shader, which could be written in 1 line, but...)
color red = color(1,0,0);
color blue = color(0,0,1);
float sp;
sp = sin(s * 2 * PI * 4) * 0.5;
Ci = mix(red, blue, smoothstep(0.3 - sp, 0.7 + sp, t));
Last updated: 5/5/97
Steve May (smay@cgrg.ohio-state.edu)