Lab 1: Hello, Shading!

Assigned: 03/21

Due: 03/28


Introduction

To get you started, this lab is a relatively simple one with the following goals:

Shaders

In this lab, you will be applying some predefined shaders to a scene as well as programming a number of "toy shaders". In reality, the shaders you will be writing are so simple as to be essentially useless, but the process of writing them should help you become more comfortable with the working environments of the shading systems. You will create solutions for the following tasks:

For this lab, you will need the files found in lab1files.zip. Download that file and expand it to your desktop; you should now have a folder named lab1files. This folder contains subfolders named GLSL and RenderMan; each of them contains the basic set of source files for this assignment.

You will also need to create a "solutions" folder for this lab. To assist with grading, I want this folder to have a specific structure, with the GLSL and RenderMan source code for each part in separate subfolders, and a separate subfolder containing all your results. I have created a ZIP archive named lab1template.zip which you can download. When expanded, it will create a folder named lab1results which has this hierarchical structure.

Here are images showing the hierarchies created by expanding these ZIP archives:

lab1 source folder hierarchy image           lab1 result folder hierarchy image

I will provide similar ZIP archives for every lab assignment.

What to Submit

Place your shader code for each task in the correct subfolder of lab1results for each language and task (e.g., your GLSL Intermediate code would be placed in lab1results/GLSL/Intermediate). Include all source files needed to recreate the images, but please do not include object files, binaries, etc.

Place your result images in the Results subfolder, with names of the form lang-task.suffix. For lang, use glsl or rman, as appropriate; for task, use basic, intermediate. or advanced; suffix should match the type of the image file you created (typically, tiff, png, gif, etc.). Assuming you create JPG files for all six images, the complete set of names would be:

Results/glsl-basic.jpg
Results/glsl-intermediate.jpg
Results/glsl-advanced.jpg
Results/rman-basic.jpg
Results/rman-intermediate.jpg
Results/rman-advanced.jpg

Please use all-lowercase names for your result image files, as shown here; this will simplify the grading process for me.

To submit your solution, create a ZIP archive of your lab1 results folder named lab1results.zip. (This can be done by using the "Compress" entry of the menu you can bring up using a right-click on the lab1results folder.) Submit the ZIP archive on one of the Ubuntu systems with the command

try  wrc-grd  shading-1  lab1results.zip

Tasks

Part 1 - Basic

A: RenderMan

In this exercise, you will be modifying a RIB file to make use of a set of predefined shaders. In the RenderMan folder of the files that you downloaded for this lab, you should find a number of familar shaders as well as a rib file. First try rendering the image (without shaders) by using the command

prman  rit.rib

or by using the RenderMan GUI. Unlike the Windows version of prman, the Mac version does not support rendering to the screen; instead, the image will be rendered to a file with the name specified in the RIB file. (In this example, the file name is image.tif). Note how boring the scene looks without shaders!

Your next task is to apply the shaders wood2, brick, and plastic to the back wall, floor, and ball respectively. To do this, you must edit the rib file and set the shaders appropriately. Once complete, compile your shaders using the command (ignore compiler wanings)

shader *.sl

(or using the GUI). Next, rerender the scene with shaders. The result should resemble the familar image shown below.

familiar rendered image

Place your shader code and the image produced by the shader in the appropriate places in the submission hierarchy described above.

B: GLSL

For the GLSL part of this lab, using all the info you learned in the in-class exercise, you will render a similar scene using OpenGL and GLSL shaders. If you need a refresher, you may want to review the tutorials from Lab 0:

In the GLSL folder of the files that you downloaded for this lab, you will find a sample scene (lab1.cpp) and a set of shaders (one vertex and one fragment for each of the following effects: wood2, brick, and plastic).

As with the RenderMan part of this task, first compile the code with no shaders (just to see how boring it is).

Next, modify the code to add the shaders. As you are now well aware, setting up OpenGL to make use of shaders takes a bit of coding. All of the code required to define a "shader program" has been incorporated into the function ShaderSetup() which you can find in the source file ShaderSetup.cpp. (Be sure to compile and include this when creating the executable for your shader application.) This function will return a handle to a shader program that you can later use when drawing. As you recall, the function glUseProgram() is used to set a shader program as the "current" shader.

Modify your code to use the brick, wood2, and plastic shaders (recall that each shader requires a vertex and fragment shader pair). In each of these shaders, the instantiation parameters have been hard coded in the shader. If all goes well, you should get an image that looks like this:

simple GLSL image 1

After success with those shaders, replace brick with brick2. brick2 contains a uniform variable that must be set in the OpenGL code using the glGetUniformLocation() and glUniform() functions (see the GLSL tutorial for a refresher). Using this, set the brick color to yellow. You need only submit the code for the code for the "yellow brick" (using the brick2 shader).

simple GLSL image 2

Place your shader code and the image produced by the shader in the appropriate places in the submission hierarchy described above.

Part 2 - Intermediate

For this exercise, you will write your first shader from scratch. You are to write an extremely simple shader named 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 GLSL you can start with the code that you wrote in Part 1.

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

Part 3 - Advanced

For the advanced shader, you will 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., the points whose distance you are comparing to the range must both be in the same coordinate system. Both GLSL 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 GLSL, modify the code used in Part 2.

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


RenderMan® is a registered trademark of Pixar.
Ubuntu® is a registered trademark of Canonical Ltd.