Friday, April 17, 2009

Assignment #7 - Dielectrics

Source code is available here

To download and build:

tar zxf jbowles-assign6.tar.bz2
cd jbowles-assign6

Here is the requested seven spheres image. It took 1838 seconds to render. This is a 1024x1024 image with 1000 samples per pixel. Click on the image to view the full size version. The following command line was used to generate the image:

./raytracer --width=1024 --height=1024 \
--maxdepth=20 --eye=0,0,1000 \
--up=0,1,0 --lookat=0,0,0.0 \
--reflections --shadows --samples=1000

Without dielectrics, it took 2235 seconds. What? That doesn't make any sense.

Here's an interesting up close image of the center sphere. It has an index of refraction of 2.0. The reflections are particularly nice, but those bands are not. Click on the image to view the 1024x1024 version.

The obj model I used was an ashtray. My obj model reader chokes on anything that isn't a triangle, so the model ends up with some weird holes.

The index of refraction is 1.2, image is 512x512 with 1000 samples per pixel. This took 1512 seconds to render.

./raytracer --width=512 --height=512 --maxdepth=20 \
--eye=0,60,-60 --up=0,0,1 --lookat=0,0,0.0 \
--reflections --shadows --samples=1000 \

I'm not too happy with my choice of a background. Some Perlin noise would have been nice, but I haven't implemented it yet.

Here's the same ashtray, but without dielectrics. It took 2655 seconds to render. What's up with things taking longer to render with less rays? That doesn't sound right to me. I'm beginning to question my timings.

This image really shows the lack of quality of my .obj model viewer.

Implementing the reflection / refraction pairs was fairly straightforward, after much reflection (ha!) on the math. Initially, I was not careful in my implementation of Snell's law and the Fresnel term and had some pretty strange images.

The refracted ray is determined by Snell's law. If total internal reflection is found, the no refracted ray is computed and its "power" is set to zero and all energy is devoted to the reflected ray.

If there is a refracted ray, the power of both the reflected and refracted rays are computed and multiplied by the color of the resulting rays.

Another field was added to the Ray class: index of refraction. This allows the code to easily keep track of the current index of reflection with regard to whether or not the incoming ray originated inside of an object or not.

I believe I understand the banding issue: rays are sent out and bounce round the sphere a few times, each contributing a little bit more to the scene. Some areas have more bounce than others and reveal the sampling pattern used to sample the image.

I'm not sure about the best way to fix this problem. Each ray shouldn't increase its contributing each time it reflects or refracts.

No comments:

Post a Comment