 |
Arts College 755
Call No 02463-2
Req: 752
OSC 1224 Kinnear
Fishbowl (rm205)
TR 2-348
Winter 2008
05 credits
Instructor:
Matthew Lewis
|
 |
 |
 |
Shader Basics
Due date: 01/10, before class.
Section 1: Function Graphing
Graph each of the following functions over the specified
domain. Plot x along the x-axis and f(x) along the
y-axis. Under each graph, write the range of the function over the
specified domain. See the Regular
Patterns section of RManNotes
for definitions of step,
smoothstep,
and mod
(mod(a, b) returns the remainder of a/b).
- f(x) = 2
x domain: [0,1]
- f(x) = 2 * x - 1
x domain: [0, 1]
- f(x) = (x + 1) * 0.5
x domain: [-1, 1]
- f(x) = step(0.5, x)
x domain: [0,1]
- f(x) = smoothstep(0.4, 0.5, x)
x domain: [0,1]
- f(x) = smoothstep(0.1, 0.9, x)
x domain: [0,1]
- f(x) = mod(x, 1.0)
x domain: [0,4]
- f(x) = mod(x * 4, 1.0)
x domain: [0,1]
- f(x) = step(0.5, mod(x * 4, 1.0))
x domain: [0,1]
Section 2: "One-line" shaders experiments
In this part, you will experiment with a series of "one-line"
shaders, rendered on a flat grid object.
- In your favorite text editor create a 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:
Z:\> shader experiment.sl
experiment: compiled.
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.
- Save the file square.rib in the
same folder. Look inside and see that it defines a single patch, with
the shader "experiment" applied to it.
- Render the file by typing, "prman square.rib" on a command line. You should see an image of a flat, red square. The object is a
simple grid (actually a bilinear patch) with the shader you just
compiled, experiment, applied to it.
Experiment Process
For each of the following experiments, do the following:
- Replace the 3rd line in experiment.sl, which looks like:
Ci = color (1,0,0);
with each new, specified line;
- Recompile the experiment shader
- Re-render the grid
- Observe the results, investigate and understand what's going on.
Experiments
- 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));
- Ci = step(t, s);
- Ci = noise(s, t);
- Ci = noise(s * 10, t * 10);
- Ci = noise(s * 50, t * 50);
- Ci = 0.5+0.5*sin(s*2*PI*4);
- Ci = mix(color(1,0,0), color(0,0,1), smoothstep(0.3-0.5*sin(s*8*PI), 0.7+0.5*sin(s*8*PI), t));
After trying them all and figuring out why each does what it does,
choose several and write brief explanations about why they do what they do.
Section 3: make your own!
Using what you've learned above, write a few one-line functions of
your own. Render 256x256 images. See how visually complex an image
you can make using the shortest expression you can.

Ci = mod(s,t-.5*t*noise(t*8))
Results:
Hand in your function graphs and your experiment descriptions from
sections one and two on paper.
On your Hw1 web page, show the new one-line shaders you created for
Section 3 (both the resulting 256x256 images and the one-line math
expressions that generated them.)
Recommended bonus reading if you thought section three was great fun:
why write complex image expressions when you can breed
them?
(Original version of this assignment by
Steve May)
|