Sunday, April 19, 2009

Bumpy Spheres

Ken Perlin is a genius. Here are two images using Perlin noise to perturb the normals on the sphere to give it a bumpy feeling. Click on the images for larger versions:




The best part is that no special geometry was used. These are just two simple spheres! This is so fun! I'm inspired to sing "Come on Feel the Noise" by Quiet Riot.

Turbulence

Starting work on creating turbulent textures using Perlin noise. Click on the image for larger vesion:



I used the improved noise reference implementation and translated from Java to C++. Then I added the turbulence function on top of the noise function.



This is kinda fun. It's a black sphere with black and white turbulence on a black background, so all you see are the white and grey parts.

Friday, April 17, 2009

Assignment #7 - Dielectrics

Source code is available here

To download and build:

wget http://cs.unm.edu/~jbowles/cs413/a6/jbowles-assign6.tar.bz2
tar zxf jbowles-assign6.tar.bz2
cd jbowles-assign6
make


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 \
--outfile=ashtray_glass.ppm



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.

Hatch marks explained?

I believe that I understand the source of the hatch marks. It may not be a problem so much with regular sampling but with each ray that is traced adding energy to the scene.

For example:

1) A ray is sent out and intersects a glass sphere
2) That ray has two components: reflection and refraction
3) The refracted ray travels through the sphere, and refracts/reflects again
4) The reflected ray bounces around the sphere, adding energy. This reflected ray eventually reaches the maximum allowed tracing depth, and the color is set to black, which is resulting in what appears to be a grainy noise.


Some areas have more energy added than others. When I ignore reflected rays within the sphere, a very different image without the grid appears:



This problem isn't solved, but it show a serious problem with my implementation. A light source doesn't put out infinite energy and each bounce doesn't add energy to the scene.

Thursday, April 16, 2009

7 sphere with orthographic projection

Here are the seven spheres with an orthographic projection.


Those hatch marks look pretty regular in the center of the picture. It's almost like my sampling pattern is emerging. Hmmm.

Here's a midget in a bikini:


Is my sampling grid becoming visible in the sphere? Is this the source of the "hatch marks?"

Extracting frames from a Panasonic MTS file

MTS files are just an mpeg4 file. The command line utility ffmpeg will let you extract the frames:


Building:

svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
./configure
make && make install


Example usage with an HD camera

ffmpeg -i 00000.MTS -s hd1080 -f image2 waa-%03d.png

This will rip all the frames into waa-%03d.png.

7 spheres

Here's my image of 7 spheres. I'm completely underwhelmed.




Indices of refraction: center: 2.0, the others range from 2.1 to 2.6. The outside index of refraction is 1.0. This scene has almost as much as a vacuum as my brain. I'm just not getting this.

This image is horrible and I'm about ready to scrap my entire raytracer. You can see just how horrible it is by clicking on it to view the 1024x1024 version. There's 1000 samples/pixel and it took 1072 seconds to render.