Procedural Shading

4003 590-01 / 4005-769-01

SPRING 2006

Lab 1 -- Hello Shader


Introduction

This is your basic "Hello World!" Lab.   The goals of this lab are:

Shaders

In this lab, you will be programming a number of "toy shaders".  In reality, the shaders are pretty lame and useless, but it is hoped that the process of writing them will get you comfortable in working within the working environments of the shading systems.  The shaders that you will write:


Part 1 -- BASIC

The BASIC part of this lab is to test the shader/rendering envrionment on your machine.   In this section you will download / compile some predefined shaders and generate some images that make use of these shaders.

A:  RenderMan

We'll be using Pixar's RenderMan implementation prman for this, and for most, if not all, of the labs.    The Pixar RenderMan server comes with a variety of tools, but we will be keeping things basic and will be making use of the command line tools.   You can find  prman on our system  in the following paths.  Please be sure that  the bin directory is in your path so that you can run the compiler and tools from the commandline.

Testing prman

To assure that your can actually compile and run a shader, please download lab1.zip and extract in the public directory on the ICL6 machines.  You probably will recognize these files as these were the files for the RenderMan assignment in CG2.   After extracting, try executing the following commands in a command window.

shader *.sl
prman ritwindow.rib

The shader command is the shader language compiler and will compile the shaders needed for the scene.  The prman command will perform rendering of a scene that uses the shaders compiled in the first step.  You may wish to take a look at ritwindow.rib to see a description of the scene.  If all is well, you should see an image that looks like this:



Once you are convinced that the programming environment is set up correctly, go into the RIB file and experiment by modifying some of the parameters passed to the shaders.    You submission for this section should be the result of these modifciations as well as the modified RIB file.  Please indicate in your README, what parameters were modified.

B:  Cg

Cg shaders get compiled as part of development of a graphics application using DirectX or OpenGL.  In our labs, we will be using OpenGL as the basic 3D API.     The location of Cg on our machines is:


To test out the Cg path,  I will ask you to copy the examples folder C:\Program Files\NVIDIA Corporation\Cg\examples to the C:\public folder and to build and run the example in the folder runtime_ogl.  You may find yourself having to modify the properties of the Visual Studio project to point to the proper include and library directories.    Once you are convinced that all is set up correctly,  modify some of the parameters (You may wish to look at the drawCube() function) and submit the results of the modification.


Part 2 - Intermediate

Time to write your first shader from scratch.    For this part, you are to write an extremely simple shader, oneColor,  that colors a surface a single color.    The color to draw should be passed in as an argument to the shader.    

For RenderMan, please modify the RIB file used in Part 1.   Change the shader on the back wall from wood2, to oneColor.  

For Cg, you can start with the OpenGL / GLUT application demo2.c.    Note the commented lines in the function colorcube.  

For both RenderMan and Cg, please submit the shader code and the image produced by the shader.

Part 3 - Advanced

For the advanced shader, I will ask you to modify your oneColor shader to create a new shader named target which will color all points on a surface within a given neighborhood one color, and all points outside the neighborhood another color.   The target shader should have the following parameters:
Please take special note of coordinate systems.  i.e. assure that the points whose distance you are comparing to range are both in the same coordinate system.    Note that both Cg and RenderMan have a function that calculates the distance between two points, and both have a means to transform points from one coordinate system to another if needed.     Please refer to the documentation to find these functions.    

Once again, for Renderman, apply the new shader on the back wall.     For Cg, feel free to use the colorcube example found in demo2.c.  


For both RenderMan and Cg, please submit the shader code and the image produced by the shader.


last updated: 03/22/06