Lab 1: Hello, Shading!

Assigned: 03/17

Due: 03/26


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 lab1. This folder contains subfolders named GLSL and RenderMan; each of them contains the basic set of source files for this assignment:

lab1 source folder hierarchy image

What to Submit

To assist with grading, please organize your solutions in a folder named lab1results which contains a hierarchy that looks like this:

lab1 result folder hierarchy image

For your convenience, I have created a ZIP archive named lab1results.zip which you can download and expand to create this hierarchy.

Place your shader code for each task (basic, intermediate, advanced) for each language (GLSL, RenderMan) in the appropriate subfolder (e.g., GLSL Intermediate code in 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. For example, the result image for the Basic RenderMan task might be named rman-basic.tiff, and the Advanced GLSL task result image might be named glsl-advanced.png.

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 lab1 folder.) Move that ZIP archive to your main CS account (if necessary), and submit it from there 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 assn2.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 OpenGL using XCode tutorial and/or the GLSL tutorial.)

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 setUpAShader() 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.