Overview

In this project I added onto my raytracer implementing mirror and glass surfaces as well as depth of field. Creating mirror surfaces was relatively simple as I just needed to change the bsdf to one which mirrored rays instead of diffusing them like a matte surface would. For glass materials I needed to have rays refract through the material and also bounce off of it. I used Schlick’s approximation to decide the probability of tracing a reflection or a refraction, and we used Snell’s equations to derive the refracted rays. For depth of field I changed our pinhole model to have a lens. A ray going through the original pinhole to a point on the plane of focus has corresponding rays that go through all other points on the lens to the same point on the plane of focus. Using this fact I was able to calculate how rays would refract through the lens.

1) Mirror and Glass Materials

(See overview for summary of implementation)

With zero bounces we only see the light source since anything that doesn’t emit light requires light bounces to see.

0 bounces

With one bounce we begin to see the room and the balls. They are entirely black except for exactly where light would bounce directly off the sphere toward the camera. This makes sense because everywhere else on the spheres would trivially take more than one bounce to reach the camera given that they are only reflecting and refracting light, unlike the walls which are diffusing it. Note that the right sphere’s glare spot is significantly noisier due to the fact that it only reflects sometimes and other times refracts based on a coin flip with a probability determined by Schlick’s approximation.

1 bounce

With two bounces we can now see the mirror effect of these two spheres. Again the right one is much noisier due to the same reason as prior, and it is much darker as well. We still haven’t had enough bounces to have rays refract fully through the glass, so instead we just get a very murky reflection. The left ball however looks almost perfect now. The biggest flaw right now for it is that its reflection of the glass sphere looks like our image from one bounce. This should make sense if we think of the mirror sphere as essentially just rendering its own image of the room but with one less bounce.

2 bounces

With three bounces now light has been able to refract through the glass sphere and it finally looks like the right material. We can see that it is bending rays that refract through it by the distorted and flipped image we see by looking though it. We also see a bright spot on the ground under it which is caused by this same bending effect concentrating most of the rays in a particular area. Note that the glass sphere still doesn’t look correct when looking at its reflection in the mirror sphere.

3 bounces

On the fourth bounce of light the glass sphere finally looks correct in the reflection of the mirror sphere. We begin to see a spot on the right wall which is caused from a similar magnification effect to the one below the glass sphere, but this time it is from light which originated from the light source, was reflected off of the mirror sphere, then refracted into the glass sphere, then exited the glass sphere, hit that spot on the wall, then was diffused to the camera. Lastly we also see a bit of glow underneath the glass sphere. A lot of the light that was concentrated onto the ground under the glass sphere has now bounced back onto the glass sphere, and then been reflected towards the camera.

4 bounces

With five bounces we see very little change. At this point it seems we have captured most of the major multibounce lighting effects that will take place in this scene.

5 bounces

With 100 bounces we again see little change. Slight lighting changes like the spot on the wall looks a bit more faded, and the glow on the bottom of the glass sphere seems to have faded a bit as well. Just minor changes as we converge towards the desired image.

100 bounces

4) Depth of Field

(See overview for summary of implementation)

In the pinhole camera model all rays traced from the image plane through the scene pass through the same point, the pinhole. With a lens model we instead sample a position on the lens, then have the ray refract through the lens such that the incoming ray (the ray going to the scene from the lens) passes though the same point on the focused plane that the corresponding ray that goes through the pinhole would have gone through. In this way we create a situation where everything is exactly the same when looking at something on the focused plane, but the further we go from it, the more off we will be from the pinhole model, causing a blur.

Here I show different aperture sizes. The bigger the aperture the blurrier things far away from the focused plane will be.

Pinhole model

0.05 aperture

0.1 aperture

0.15 aperture

Here I show some examples of focusing at different depths.

1.5 depth

1.8 depth

2 depth

2.2 depth