Extend your ray tracer from Project 2 to implement lighting and shading. First, implement shadows, diffuse shading, Phong shading, and reflection. Then, add support for at least one type of procedural texture that includes noise. As there is a large variety of topics to cover, before beginning the project, read the following sections in the textbook and class notes.
As you cast rays into the scene, when an intersection is found, cast a shadow ray from the point of intersection to each light source, in turn. If a shadow ray hits another object before reaching a light source, then that light source is blocked. If a light source is behind a surface, i.e., in a direction opposite to the surface normal, then that light source is blocked. Each light source that is not blocked should contribute to the local surface illumination.
The surface illumination includes diffuse (aka Lambertian) and specular (aka Phong) components. The NFF format does not allow for an ambient component. Each light that is not blocked should contribute color according to:
where lightColor, Kd, surfaceColor, and Ks are determine from the values in the NFF file, diffuse is calculated according to Lambert's law, and specular is calculated according to the Blinn-Phong shading model (use the half vector in place of the reflection vector). Where there are multiple lights, you should add the results for each light together. Since the NFF format does not define intensities for light sources, you may find it useful to scale each light's contribution by 1 / sqrt(# of lights).localColor = lightColor * (Kd * surfaceColor * diffuse + (Ks * specular)^Shine),
You should cast reflection rays from each intersection point into the scene whenever Ks is greater than zero. The total color of a point in the scene (i.e., what you should write to your output) is:
This is a recursive process, since the color of the reflection rays is the color of whatever they hit. To avoid infininite recursion, limit the ray tree depth (i.e. number of bounces) to 5. You may skip the reflection ray if the contribution to the final color would be less than 1/255, but that optimization is not necessary.totalColor = localColor + Ks * reflection
This is based on Ken Perlin's reference implementation./afs/umbc.edu/users/r/h/rheingan/pub/435/Proj6/Noise.cpp / .h
You are expected to complete assignment 5 by modifying your code for assignment 2. If you did not complete assignment 2, or if you think you will be unable to modify your code, you can request a working implementation from the TA.
There are a few sample input files located at:
The files balls1.nff, balls2.nff, and balls3.nff are identical to the sample files from project 2, except that they include lighting commands. As before, the files correspond to different levels of recursion for fractally defined spheres./afs/umbc.edu/users/r/h/rheingan/pub/435/Proj5/samples
As in project 2, the input file will use a subset of the NFF file format. You should support the commands below, in addition to the ones used in project 2 ("f" has been repeated since this assignment uses additional features of it). You will need to modify the format to add support for selecting a texture. You are free to modify the input format in any way you see fit, but you should document your changes in your readme file. An example of how you might specify a texture is given below.
Positional light. A light is defined by XYZ position. Description: "l" X Y Z [R G B] Format: l %g %g %g [%g %g %g] All light entities must be defined before any objects are defined (this requirement is so that NFF files can be used by hidden surface machines). Lights have a non-zero intensity of no particular value, if not specified (i.e. the program can determine a useful intensity as desired); the red/green/blue color of the light can optionally be specified.
Fill color and shading parameters. Description: "f" red green blue Kd Ks Shine T index_of_refraction Format: f %g %g %g %g %g %g %g %g RGB is in terms of 0.0 to 1.0. Kd is the diffuse component, Ks the specular, Shine is the Phong cosine power for highlights, T is transmittance (fraction of contribution of the transmitting ray). Usually, 0 <= Kd <= 1 and 0 <= Ks <= 1, though it is not required that Kd + Ks == 1. Note that transmitting objects ( T > 0 ) are considered to have two sides for algorithms that need these (normally objects have one side). The fill color is used to color the objects following it until a new color is assigned.
Procedural texture. Description: "t" N [scale] Format: t %d [%g] The parameter N specifies which procedural texture should be used. Valid choices are 0 to 3. The optional scale parameter influences the calculation of texture coordinates (default is 1.0). Like the fill color, the texture is applied to the objects following it until a new texture is assigned.
Students in 634 should have added support for (convex) polygons in assignment 2, using the "p" command from the NFF specification. For assignment 5, you should add lighting for polygons, and also add support for the "pp" command, which includes a unique normal for each vertex. You should interpolate between normals when performing lighting calculations. There are several ways to do this:
Instead of point lights, treat each light source as a sphere with a specific radius and center given by the NFF "l" command. Then, instead of casting a single shadow ray, cast multiple rays to each light, to sample different points on the surface of the sphere. This allows points in the scene to be partially shadowed with respect a single light.
You may distribute the shadow rays in any sensible way (for exmaple, projected through a uniform grid). Also, you may consider light to emanate omnidirectionally from points on the surface of a spherical light, so you do not need to worry about doing any calculations with the sphere's normal vector.
You should use command line flags to control the radius of the spherical lights and the number of samples.
Simulate haze by attentuating light/reflection along ray. Use the command line flags to turn haze on.
As an alternative to Phong shading, add support for the artistic shading techniques described by Shirley in section 9.3 (line drawing and cool-to-warm shading). You should use separate command line flags to enable either effect. Each technique is worth 5 points individually.
Add antialiasing to your ray-tracer. Five points for implementing regular supersampling with a box reconstruction filter. Additional points for adding more sophisticated sampling or reconstruction: one point for jitter, two points for a pseudo-Poisson distribution (random with minimum distance is fine), two points for Gaussian reconstruction.
Use a command line flag to control the number of samples per pixel, as well as the selection of sampling and reconstruction technique.
Implement at least one texture based on turbulence, i.e. multiple levels of noise at different scales.
Vary the normal vector in at least one of your textures. This can be used to give the shading effect of a bumpy surface.
Implement displacement mapping to actually generate displaced geometry based on a texture specification. Unlike bump mapping, displacement mapping will change the appearance of the silhouette.
Find your own interesting materials and create procedural textures to model them. You should submit a picture of each material for comparison along with your project (if you are unable to obtain a picture, contact the TA for options).
Note that checkerboards are not interesting. Any materials you choose should be at least as complex as those given out in class. It would be best to get your bonus materials approved in advance.
More sample scenes in NFF format can be created using a set of programs called the "Standard Procedural Database", which is freely downloadable. A copy of the SPD is also located at:
/afs/umbc.edu/users/r/h/rheingan/pub/435/Proj2/spdThe sample files listed above were created using the SPD program 'balls', which writes an NFF file to standard output. For example:
balls -s 1 > balls1.nffThe -s option controls the level of recursion. Note that the output of the SPD programs typically includes NFF commands other than the ones required for this assignment (balls outputs a single polygon which was removed from the sample files). Therefore, if you want to test your ray tracer using the SPD programs, you should be able to handle the presence of such commands in your input file (you should simply ignore any commands you do not implement).
The program 'shells' outputs many spheres, similarly to balls; 'lattice' and 'jacks' output cylinders and cones, 'tetra' and 'teapot' output primarily convex polygons, and 'gears' includes concave polygons.
Submit your assignment as 'Proj5' using cvs. Include your source code and makefile. Please do not submit PPM files, as they can be very large. If you must submit images, convert them to a compressed format such as .jpeg. The 'convert' program is available on the GL servers, so for example you can do:
convert image.ppm image.jpg
Also include a readme file with a description of what hardware / software environment you used to develop your project, and a description of any help you received or outside resources you used. (If you received no help beyond the text and course staff, state as much.) Your readme should also include any instructions necessary for using your program.