The goal of this lab is explore ways of performing volumetric rendering using shaders.
In this lab, you will build a sequence of shaders that render volumetric effects. The lab exercises mirror the topics covered in lecture; you may want to refer to the lecture notes while working on this assignment.
You will write the following shaders:
BASIC: A basic uniform fog
INTERMEDIATE: Ray casting through a sphere (to generate a basic fog)
ADVANCED: Ray casting through a hypertexture / sphere, or light scattering
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 previous assignments, two ZIP archives have been provided for you:
lab6files.zip
expands into a folder named lab6files which contains "starter"
code for your GLSL and RenderMan®
implementations.
lab6template.zip
expands into a folder named lab6results which is a framework
into which you should place your solutions and resulting images.
As with previous assignments, please place your solutions in the
lab6results 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. Submit this ZIP archive on one of the Ubuntu systems with the command
try wrc-grd shading-6 lab6results.zip
Important note: because of grading time constraints, there is no late period for this lab - late submissions will not be accepted.
For this first part, you will be implementing a shader that implements a basic uniform fog. Please use the specification mentioned in lecture (i.e. parameters to your shader should be fog color and the constant fog density). Both texts show examples of a fog function.
When implementing this in RenderMan, there are few things to note.
First, there is a standard "fog" shader in RenderMan.
This means you must name your fog shader something other than
fog (myFog, fog2TheSagaContinues,
theFogStrikesBack, etc.).
Another thing to note is that although fog is an atmospheric effect, it
must be bound to a particular primitive.
In RenderMan, this means that each primitive must have your fog shader
defined as the Atmosphere shader for the primitive.
This means that it's actually possible to selectively apply fog (e.g.,
in our classic scene, you could apply fog to the sphere and not to the
wall and floor); however, this will probably not give you the resulting
effect you're looking for.
The
lab6files.zip ZIP archive
contains two RIB files that draw a scene containing four spheres at
various distances from the camera; they also show
proper binding using the standard RenderMan fog shader, which implements
a simple distance-based fade to a background color (see page 315 in the
Advanced RenderMan textbook for its implementation).
The file rit6.rib shows fog applied with a distance value of
40; rit6b.rib is the same scene, but with a fog distance of 10.
To apply your fog shader in GLSL, you simply keep the shaders bound when you draw all three of the objects in the scene Recall that GLSL only knows about verticies and fragments; it does not have the concept of "atmospheric" shaders. Thus, the GLSL shaders must not only implement the fog, but apply it to whatever other surface characteristics the shader is calculating. You should feel free to use whatever past shaders you have written.
Finally, you may have to play with the density parameter a bit to get a decent effect. Provide an image using a decent value for this parameter. Playing with the fog color could also prove to be interesting. Experiment; be creative!
For this part, you will be implementing the basic ray marching algorithm and using it to calculate the same fog that you created in Part 1. You may wish to write a general ray marching function since you will be needing one again for Part 3. In this routine, you should call additional functions that determine the density at a point (which is constant for uniform fog) as well as one that does the lighting for a point (which, once again, will be constant for fog).
The ray marching algorithm given in the lecture notes is from
Chapter 12 (page 315) of the Advanced Renderman text.
The version in some printings of that book has two typographical errors:
in the Cvol and Ovol equations inside the loop,
the subexpression "+ stepsize"
should be "* stepsize" (i.e.,
the expression should use multiplication, not addition).
The version of the algorithm given in the lecture notes is correct.
Ray marching is also discussed in Chapter 9 of The RenderMan Shading Language Guide. The algorithm given there is slightly different; you may find it helpful to compare the two.
In Part 3, you will have the choice of either creating a Hypertexture or creating stage fog simulating Mie or Rayleigh Scattering.
If you select the Hypertexture option, you will be creating a Hypertexture fireball or cloud. Use the ray marching routine written for Part 2 to implement this. You can use a basic turbulence for the definition of the density function. You can implement this as a surface rather than an interior shader if you prefer. You may want to (re-)read Ken Perlin's Hypertexture paper. Feel free to experiment with different density functions and colorings.
If you select the stage fog option, your goal is to use fog to accentuate a beam coming from a spotlight. Use either a constant density or a noise based density function, and use the Mie Scattering or Rayleigh Scattering model to simulate the scattering. Once again, be creative! (See the lecture notes for equations for the Mie and Rayleigh Scattering models.)