Lighting and Shading
Update existing classes in your ray tracer
Please download these additional Java files. Then you will need to
modify the World.java class:
- import raytracer.Lights.*;
- add two new instance variables: a Vector<Light> called "lights" and a single Light called "ambient".
- modify the World constructor to create an empty Vector lights and the default Ambient Light.
- implement the addLight method:
public void add_light(Light light)
You should base it on the addObject method.
- implement the addAmbient method:
public void set_ambient_light(Light light_ptr)
You should base it on the setCamera method.
- add a hit_objects method (see page 262):
public ShadeRec hit_objects(Ray ray)
- modify your Compound class from the last homework assignment, so
it also creates SmoothMeshTriangles.
Write a few new classes
Implement the following classes:
- a PointLight class (child of the Light class), described in chapter 14 (especially pages 253-258)
Hint: use the Directional class as a model
- a GlossySpecular class (child of the BRDF class), described in chapters 13 and 15 (especially pages 228-230 and 283-284)
Hint: use the Lambertian class as a model
- a Phong class (child of the Material class), described in chapters 13 and 15 (especially pages 268-269 and 280-285)
Hint: use the Matte class as a model
- a BlinnSpecular class (child of the BRDF class), described on page 288. This class should be identical to the GlossySpecular class, except it will have a different f method.
- a RayCast class (child of the Tracer class), described on pages 262-264. This class should be very similar to the MultipleObjects class, except it will have a different trace_ray method. WARNING: the textbook has errors on page 258. You should make location a Point3D, not a Vector3D. In addition, sr.hitPoint should be sr.hit_point in the get_direction method.
Finally, you will need to add a Material to the GeometricObject class, as described in sections 14.4 and 14.5 of your textbook. Materials will not be modified by the GeometricObject, so the instance variable should be a pointer. In other words, the Material class should be set to null in the GeometricObject default constructor. The get_material method and set_material method do not need to call a copy constructor; they can just set the instance variable to the same material.
Render images
Once you should have all the code necessary for both rendering matte and glossy materials, you should test your code by rendering:
- Figure 14.21 on page 272. This image lights two matte spheres and a plane with a single point light source. Turn in this image (Figure14-21.jpg)
- Figures 14.22 and 14.23 on pages 274-275. You should create all FOUR of these images to make sure you understand tone mapping, but you do not need to turn in these images.
- Experiment with modifying the Matte parameters. Then create an image without ambient lighting (ka = 0). In your reflection, describe what you found about ambient lighting.
- Experiment with colored lights (ambient, directional and point lights). We are not used to seeing colored lights in the real world, so you may find your results unexpected. Turn in the most striking of your images (ColoredLights.jpg)
- Create an image with two rows of five sphere (ten spheres total). The top row should consist of five GlossySpecular spheres, all with the same coefficients and colors, EXCEPT the exponent. The bottom row should consist of five BlinnSpecular spheres, all with the same coefficients and colors, except again, the exponents. Use 8 for the exponent in the first column, then 32, 128, 512, and 2048. Call this image Specular.jpg.
- Create two images demonstrating the difference between flat shading and smooth shading. The first image should use flat shading (using FlatMeshTriangle, call this image FlatShading.jpg) and the second should use smooth shading (use SmoothMeshTriangle and call it SmoothShading.jpg). You should choose any smf object that clearly demonstrates the difference.
Questions
Answer the following questions:
- Questions 14.2 and 14.3 on pages 276-277.
- Question 15.2 on page 290.
- Question 23.7 on page 490.
Last modified: Thu Mar 10 10:56:09 MST 2011