Lab 5: Lighting

Assigned: 04/21

Due: 05/02


Introduction

The goal of this lab is explore ways of defining customized lights using shaders.

Shaders

In this lab, you will build a shader that models a spotlight used in the theater and cinema. As in the previous lab, you will develop your shader in phases, with each phase adding an additional feature to the light shader.

The three phases are as follows:

For each submission you should include the shader code and an example image which illustrates the effect. It should be clear that the later submissions are extensions of the code written for the earlier submissions of this lab.

As with the previous assignments, two ZIP archives have been provided for you:

What to Submit

As with previous assignments, please place your solutions in the lab5results folder, as follows:

Create a ZIP archive of your results folder by using the "Compress" entry of the right-click menu for the folder; to submit it, run the command

try  wrc-grd  shading-5  lab5results.zip

Part 1 - Basic

For this first part, you are to define a basic spotlight. In addition to the position (from), direction (to), and color (intensity) of the light, your shader should allow, as parameters, the field angle and beam angle for the light. The intensity of the light should also fall off based on the distance from the light to the surface being illuminated (the basic 1/d^2 falloff can be used). Just as a reminder, as illustrated in the diagram below, the beam angle is the angle, measured from the direction vector, at which the intensity of the light falls off to 50%. The field angle is the angle at which the intensity falls off to 10%.

spotlight beam falloff

A smooth interpolation of the intensity (from 100% to 50%) should be performed for angles from 0 degrees to the beam angle. Interpolation of the intensity (from 50% to 10%) should be performed for angles between the beam angle and the field angle. (You may wish to use the smoothstep function for this interpolation.) Any point outside of the range of the field angle should be considered as not being illuminated by the light.

Remember that GLSL does not have an illuminate construct. Thus you will have to write a GLSL function to emulate that; see the lighting lecture notes for an example.


Part 2 - Intermediate

In the real world, many lighting instruments provide a focus control that will enable the light to have a hard beam or a soft beam. Introduce a new parameter to your shader called "focus" which will control variability within the region between the beam and field angles. A focus of 0.0 indicates a soft focus; in this case, the field and beam angles should be unaffected. At the other extreme, a focus of 1.0 indicates a sharp focus; in this case, the effective beam angle should extend to the end of the field (in essence, replacing the field angle effect). Any value between 0 and 1 would move the effective beam angle part way into the region between the field and beam areas.


Part 3 - Advanced

In Part 3, you will be adding a gobo to your lighting instrument. The gobo acts as a filter and is used to shape the beam. You can use a texture image for the representation of the gobo pattern. Unlike previous labs, this texture will not be mapped on any piece of geometry the scene; instead, you will have to determine the s and t values based on the direction of the light and the vector from the light to the surface point being illuminated. The mapping should be set up so that the entire beam fills the texture image as indicated below.

beam texture illustration

The lab5files.zip archive contains a subfolder named textures; in this folder you will find the files star.bmp and star.tiff, which contain a star image that is suitable for use as the gobo pattern. Please do not submit a copy of these files with your solution.

You are also free to experiment with other pattern images; if you submit results based on other patterns, please do submit copies of those pattern images.


RenderMan is a registered trademark of Pixar.