Notes for Wednesday September 30 class -- ray tracing with reflection

Putting Phong reflection parameters into a 4x4 matrix

We used a 4x4 matrix uniform variable to store the 10 parameters for the Phong surface reflection of each of our two spheres.

This was a very simple use of 4x4 matrices, which give you a chance to get used to the structure of matrices. In coming weeks we will use 4x4 matrices in much more interesting ways.

Implementing mirror reflection

We implemented mirror reflection in the fragment shader by tracing a secondary ray from the sphere surface into the mirror reflection direction, and then mixing in the shading of first sphere that secondary ray hits, if any.

The mirror reflection direction is the direction about the surface normal which is symmetric with the direction from the surface point back to the eye. Since the direction back to the eye is -W, we can calculate that mirror reflection direction by:

Wr = 2 * N * (N • -W) + W
The secondary ray starts just outside the surface point P, so that it doesn't accidentally hit the sphere itself:
Vr = P + 0.001 * Wr

Introduction to linear transformations

We did a quick preliminary introduction to using 4x4 matrices for linear transformations.

We looked at the internal structure of translate, rotate, scale and perspective matrices, and showed how each of these can modify the points in a 3D scene.

We briefly mentioned the difference between point vectors and direction vectors. Since a point vector has a fourth (homogeneous) component of 1.0, its value changes when multiplied by a translation matrix.

Because a direction vector has a fourth (homogeneous) component of 0.0, its value does not change when multiplied by a translation matrix.

Homework

Due next Wednesday before the start of class

Start with the included code in hw4.zip.

Create a scene that is very different from the one in this example. In other words, it should not be a moon circling a planet.

This is an opportunity for you to show that you can expand ray tracing in various ways. Try to experiment and do something interesting. Some ideas:

  • Try to implement two levels of mirror reflection (reflections of reflections).

  • Use one of the unused slots in uPhong to vary the amount of mirror reflection that is mixed in.

  • Use procedural noise to vary the direction of various things, such as the mirror reflection ray, to create interesting surface reflection effects.

  • Use procedural noise to try to vary the shape of the sphere itself, so that the sphere shape is not perfectly round.
I am sure you can come up with lots of other ideas. These are just to get you started.

Do something interesting and original that I will want to show off in class. Most important, have fun with it. :-)