Shaders
Rendering means to make a model eg construct a sphere to put into your scene. Shading means to colour or change somehow the surface depending on the current lighting. ie as it moves across your scene the shiny spot on the surface moves to make it look realistic.
But the sphere is not the only thing which can be a bit blurred - Renderers seem to do a bit of their own shading as well.
Shaders can be written separately from, and included in, the renderer and that's what I'm going to show you how to do.
Calling a shader from rib
We can utilize the shader from the rib file, or using corresponding RI functions so you had better be conversant with RIB and RenderMan API respectively.
The shader language itself looks like C. It is written as a text file but guess how we compile it? We use the shaderdl compiler which once again is provided by the generosity of the 3Delight people. (See why I didin't want to tell you how to get rid of their water-mark). If you want to see where shaderdl.exe was placed when you installed d3Delight, you should find it in C:\Program Files\3Delight\bin
Make a simple shader. This shader is so simple (and boring) that it will simply give your sphere a constant colour (and make it look like a disc). It really doesn't well illustrate the concept that the shader is called by the rib every time it moves onto a new pixel on your sphere! (Not really every pixel but you get the idea.) If your sphere used a "plastic" shader rather than this (constant) shader and is illuminated, the sphere's specular highlight would move around the surface of your sphere as it bounced up and down. Very clever. For such a clever program, the code, even to make a basic shader is going to be 100's of lines long right.? Wrong. Here it is:
surface first()
{
Oi=Os;
Ci=Cs*Oi;
}
Every time that this code is called by the rib (see the Surface "first" line of code below), the renderer passes a colour of the sphere - before the lighting is taken into account - by means of the "array" of colours Cs. The shader then calculates what the colour should be- according to the lighting - for a given position of the sphere in the scene and returns it to the rederer by means of the array Ci which then draws this sphere. Os is an array of opacities provided by the renderer. As you can see, the resultant colour Ci is a product of individual multiplication by the individual opacity array values.
Make the text file shown above and save it as first.sl. Save it to a working direcory.
Making sure that your path is set so that it knows where to find your shaderdl.exe, type shadersl first.sl from the command prompt. This should produce the file first.sdl - the compiled version. Check that it is in the same folder.
Now make the following rib file and place it in the same working directory.
Display "first.tiff" "file" "rgb"
Projection "perspective" "fov" [45]
LightSource "ambientlight" 1 "intensity" [0.2]
LightSource "spotlight" 2 "from" [-1 1 0 ] "to"
[0 0 3] "intensity" [3]
Translate 0 0 3
WorldBegin
Color [1 0 0]
Surface "first"
Sphere 1 -1 1 360
WorldEnd
Since we are not using the default surface shader (defaultsurfacesdl is called when no shader is specified) you will notice that we need to provide some lighting as well. It may now be apparent why rendering also means shading sometimes - because when we render a rib, the default shader defaultsurface.sdlwill be called to do the shading as well.)
Notice also that it is calling our compiled (surface) shader named first with
the line Surface "first" -millions of times.
We have also decided to make it red (Color [1 0 0]).
We also saved the rib file as first.rib. It might have been less confusing if we had called it something else. Since we called it first.rib, evoke the renderer by typing renderdl first.rib from the command prompt.
Hey presto - you should have your dreary red disc.
Now that we have used a rib to call our shader, let's try calling it using the the RenderManAPI.
see Calling a shader using the RenderManAPI in my notes (Word document).
The only difernece here is that you get a dreary yellow sphere instead of a red one.
To learn about some more interesting 3D shaders, see RenderMan Fast Part 3.