Homework 2
For this assignment I enhanced my stochastic ray tracer to be a distributed ray tracer. I also added a few other features in the process:
- I added support for transparent objects with index of refraction
- I parallelized portions of my code using OpenMP (although my algorithm rapily becomes memory bound, I beleive, so it does not help as much as I was hopeing)
- I implemented soft shadows from a quad light source (more details below).
- I implemented depth of field using a simple thin lens approximation (more details below).
Transparency
I implemented transparency as in the Whitted paper. When a ray hits a transparent object it, as before, reflects a ray out to the environment, but it also transmits a ray through the object (subject to bending due to the index of refraction). The weighted sum of these two values is then used to determine the color of that point on the object.
![]() |
| You can see the heavy distortion due to the refraction of the light as it passes through the transparent red sphere. |
Soft Shadows
To generate the soft shadows I modified my code used to sample light sources. For a point light, the code remained the same, however, for a quad light, with finite size, instead of sending a single shadow ray to the light source I sent a group of them. Since I was using quad shaped light sources, I was able to leverage the sampling code I had previously written. I then shot rays from the point of intersection to the samples generated on the surface of the light, averaging the values to get the final lighting.
![]() |
![]() |
| In this image you can clearly see the difference between a point light and an area light. Directly above the sphere to the left is a point light, casting a sharp shadow on the right, however, above the sphere to the right is an area light, casting a much softer shadow to the left. | In this image, the point light from above has been replaced by a small area light. The soft shadow boundaries are still visable, however, they are sharper than the larger area light. |
Depth of Field
To generate the depth of field defined an aperature for the lens and a distance from the lens that will be in focus. Using the thin lens equation, I used the distance from the eye to the lens and the distance to the perfect focus plane to calculate the focal length of the lens. From the aperature and the focal length, I could calculate the diameter of the lens required to produce the desired results. Once I had this, for every pixel on the image plane I found found the projection of that point into the plane of perfect focus and then shot rays randomly from the surface of the lens through this point, calculating the resulting color of the ray as before.
| Small Aperature (4) | Medium Aperature (8) | Large Aperature (16) | |
| Focus on Orange Sphere | ![]() |
![]() |
![]() |
| Focus on Green Sphere | ![]() |
![]() |
![]() |
| Focus on Indigo Sphere | ![]() |
![]() |
![]() |
As you can see, we can get some nice images displaying depth of field, however, using depth of field (and, in fact, more distributed ray tracing techniques) highlights the aliasing problems faced by all ray tracers. In all these sample images, I used 100 rays for each pixel and the aliasing is still quite noticable on the spheres that are more outof focus. Using an importance based sampling technique could allow you to shoot substantially more rays in the out of focus regions and aleviate this problem, however, it is never something that can be completelly eliminated when using ray tracing.
The source can be downloaded here.











