SUNY Geneseo Department of Mathematics

Lab 7 — Mirror Reflection

Math 384
Fall 2021
Prof. Doug Baldwin

Complete by Thursday, November 18
Grade by Monday, November 22

Purpose

This exercise explores mirror-like reflection in ray tracing. It contributes to the following learning outcomes:

Background

We talked about mirror reflection in class on November 16, but the program that I presented to implement the ideas (“RT7_Mirror.py”) is incomplete. Your basic job in this exercise is to add code to this program to make it carry out the reflection calculations we developed in class, and then to extend it to explore some variations on those calculations.

Activity

Do each of the following activities. Notice that these are all basically programming tasks; there’s only a very nominal paper-and-pencil portion this time.

1. Reflections

Right now “RT7_Mirror.py” doesn’t calculate the contribution of mirror reflections to the light at a point. It has code in the traceForColor function that manages the recursive part of the process, i.e., checks to see if it should do reflections at all, but right now all it does if it should is a Python pass (i.e., “do nothing”) statement and a bunch of comments. One of those comments is a line of code that will perform a recursive call on traceForColor to get reflected colors, but in order for that line to work, new lines of code need to be written to prepare for the recursive call and/or do something with the resulting color information.

Find the place in traceForColor that needs to be completed in order to properly handle reflections, and complete it.

To help test your code, here are what the scenes already defined in “RT7_Mirror.py” look like in my solution to this lab. All of these use 3 levels of reflection:

The basic scene, produced by function basicScene:

Red ball above green rectangle and in front of blue triangle

The simple reflection scene, produced by function reflectionScene:

Blue Triangle reflected in light blue rectangle

The reflective balls scene, produced by function ballScene:

Purple and blue balls above green rectangle, with reflections

2. A Separate Coefficient for Mirror Reflection

“RT7_Mirror.py” uses the coefficient of specular reflection to scale colors reflected off mirror-like surfaces. This is physically realistic, but can be artistically annoying because getting the degree of mirror reflection you want from a surface alters its specular highlights, and vice versa.

Modify “RT7_Mirror.py” so that objects have separate coefficients of specular reflection and mirror reflection. Use existing scenes to test the change (the ball scene is the one that most prominently shows both mirror and traditional specular reflections), or create one or more new scenes of your own as tests.

3. An Alternative Reflection Model

“RT7_Mirror.py” models mirror reflection as it actually happens, i.e., the light reflected from a point arrives at that point on the opposite side of the normal from the reflection, and at the same angle to the normal. But imagine that reflections came from some different direction, for instance the direction normal to the surface at the point, a direction tangent to the surface, etc. One of the nice things about computational models such as ray tracing is that they allow you to explore alternative kinds of physics, such as these.

Change the reflection code in “RT7_Mirror.py” so that reflections come from some direction other than the actual one from our physics. You can use one of my suggestions above for the alternative direction, or devise one of your own.

4. Equations

Your solutions to Parts 2 and 3 presumably involved changes to the shading equation(s) we derived in class. Write out the equations on which your solutions are based. Write them outside of your program though, mostly as a reminder that the program follows from an underlying mathematical model and equations, but also so you can use conventional mathematical notation in the equations rather than being constrained by the syntax and character set of your programming environment.

Follow-Up

I will grade this exercise during an individual meeting with you. That meeting should happen on or before the “Grade By” date above. During the meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Sign up for the meeting via Google calendar. Please have a written solution to the exercise ready to share with me during your meeting, as that will speed the process along.