The goal of this lab is explore ways of defining customized lights using 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:
BASIC: Basic definition of the spotlight cone
INTERMEDIATE: Focus control
ADVANCED: Use of textures to simulate the use of gobos
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:
lab5files.zip
expands into a folder named lab5 which contains "starter"
code for your GLSL and RenderMan®
implementations.
In addition, there is a textures subfolder which contains
a texture image for use in the Advanced part of this assignment.
lab5results.zip
expands into a folder named lab5results which is a framework
into which you should place your solutions and resulting images.
As with previous assignments, please place your solutions in the
lab5results folder, as follows:
Place your source code (not object files or binaries) in the appropriate
subfolder (e.g., your GLSL basic source files in the
GLSL/Basic folder, your RenderMan intermediate source
files in the RenderMan/Intermediate folder, 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.
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
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%.
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.
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.
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.
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.