CSE168 Final Project: Shrine

Aaron Barany

For my final project, I decided to render a scene of a shrine, cut in the ground to produce a cave. The hole in the cieling illuminates the statue during the moning hours, though also allows rain water to enter, periodically flooding the bottom of the cavern. Here is an image of the final render. (click for a larger image)



This image used Monte-Carlo ray tracing with a photon map for the global illumination and ray marching was used to add a little atmosphere. It took around 33 hours to render the final image with 500 samples/pixel, mostely thanks to the ray marching, on a dual 2.7 GHz PowerMac G5, multithreaded to run on both processors.

The following features were present in the renderer: Nearly all of these features were used for the final image.

Sampling

All of the sampling techniques (soft shadows, anti-aliasing, glossy reflections and refractions, and depth of field) are done using Monte-Carlo integration. The samples are jittered based on the PDF of the effect being used, and the final result is the average of many such samples. In the case of soft shadows, the shadow rays have their direction randomly changed based on the shape and size of the area light. Anti-aliasing is accomplished using a Gaussian distributed sample around the center of each pixel to make sure edges would be smoothed out. Glossy reflections and refractions are accomplished with a Phong lobe, which offsets from the perfect reflection or refraction. Finally, depth of field is implemented by finding the camera direction, then offsetting the eye point of the camera, while keeping the intersection of the ray with the focal plane the same as before offsestting the eye.

Using Monte-Carlo methods sucha as these accomplished realistic images without aliasing such as Miore patterns, though it does require a large number of samples to get rid of noise. Here are some test images of the sampling methods. (all of the test images were rendered using 100 samples/pixel)

 
Depth of field (somewhat exaggerated) on the 2 different spheres.


Glossy reflections and refractions.

Photon Mapping

Photon mapping adds a great deal of realism to the scene, as it adds indirect lighting as well as caustics. Without phton mapping, anything not directly illuminated by the light source wouldn't be illuminated at all. Also, the ground underneath the water would be black, since any shadow rays would hit the water instead of the light source. (since it has no concept of transparency) When rendering, the direct lighting and caustics are sampled directly, then gathering rays are shot randomly in a hemisphere to sample the photon map for indirect lighting. Here is an example image that shows how caustics can be used to render an object completely within another object.


Participating Media

Participating media, or media that scatter light as it passes through, are implemented using a combination of scattering the photons traveling through the medium at the photon mapping stage and using ray marching to sample the light within the medium during the rendering stage. Two methods have been implemented: participating media that scatter photons and store them in a volume for indirect lighting within the medium, and participating media that scatter the photons, but don't store them for sampling, so only direct lighting is sampled when rendering the medium itself. Essentially, both methods act the same during the photon mapping stage, as photons can be scattered or absorbed by the medium during the tracing, which effects the lighting on the surfaces. However, the difference is shown in the rendering pass during the ray marching: the first method stores the photons that interact with the volume, so multiple scattering is taken into account when rendering the medium itself, rather than the second method that only handles the light that was scattered once from the light source. Since the ray marching step is incredibly slow on its own, due to the sheer number of times it must shoot a shadow ray to the light for direct lighting, and indirect lighting has very little influence in such a thin medium as a hazy atmosphere, no indirect lighting was sampled for the medium in the final image. The following images show the difference betwen multiple and single scattering during the ray marching, respectively, using 10 samples/pixel.

 


Though there is a noticeable difference, it isn't a great distance, and multiple scattering is also 4x slower than single scattering alone. Since the final image used a medium that is less dense, and therefore the difference would be less, and I valued more samples over better sampling of the medium at that point, I opted to stay with single scattering.

Texturing

Procedural textures through Perlin and Worley noise are implemented. Each of the textures shown in the final image, however, were implemented using Perlin noise, including the bump maps. Various functions were used on several octaves of the noise (such as the classic sin(x + turbulance) for marble) to implement the textures. This also ensured that the textures didn't have any discernable pattern, at least within the scale of the scene, while not requiring any extra memory. The bump mapping was also able to add extra detail without having to deal with extra geometry. For example, the water in the final image was rendered using a plane with only 2 triangles, but a bump map was used to give it the detail of a mesh with much higher geometry, still capable of reflecting and refracting at different angles compared to the geometry, change the values of the Fresnel equations, and even cause the caustics.

Modeling

In the provided basecode, obj model loading was implemented, so that was the format of choice. In the statue was a free model available on the internet. The cavern was modeled using Blender, and consisted of cutting a sphere in half, cutting a hole in it, adding a plane, and using the "subdivide fractal" feature. Complicated, I know. :-) Here is a shot of the cavern model as a whole.


Putting it all together.

I had my cavern, statue, and all my effects, so it was then time to put the final scene together. Since there were only a few parts to the scene, it wasn't too difficult to put it all together: just load he models and apply the textures with the proper parameters. However, there was the problem of placing the light. In order to get the streaming effect the way I wanted, I used a rectangular light larger than the hole in the ceiling, and moved it relatively far back from the scene. That way the light would be mostly parallel by the time it would hit the hole in the cieling, causeing the occlusion seen in the final scene. The light was also set to be a yellowish color, which adds the warmth seen in the final image. Once the parameters for the atmosphere were set, I was ready to begin the rendering.