CS6620 Advanced Graphics 2 University of Utah
Prof: Peter Shirley Ray Tracing Sem: Spring 2002



Assignment 02 - Basic Ray Tracer 2

On top of the framework I built for Assignment 01 - Basic Ray Tracer 1, I've added lighting, shadows, triangles and viewing.

The lighting uses a fixed ambient term and adds that to the contribution of each light in the scene. Each lights contribution is computed by modulating the diffuse material color by the light color, then multiplying that result by the normal at a point on the surface dotted with the light direction:

  diffuse = Kd * Id * ( n.Dot( l ) );
Lights are specified in the scene file as follows:
  light  X Y Z  Radius  R G B
(the radius is currently ignored.)

Shadows are computed by sending a ray toward each light in the scene from a point on a surface and determining whether something in the scene is blocking the light.

Triangle intersection is computed using barycentric coordinates and Cramer's Rule. Because triangle intersection is expensive, I cull any triangles whose normal faces away from the gaze direction. Triangles are specified in the scene file as follows:

  triangle  Ax Ay Az  Bx By Bz  Cx Cy Cz  R G B
Where A is the first vertex, B the second and C the third. Triangles are assumed to be wound counter-clockwise. Support for triangle meshes is forthcoming.

Viewing is specified by providing the eye position, a position to gaze at and an up vector. The field of view is currently fixed at 45 degrees, but I hope to implement support for varying fov's soon. The view is specified in the scene file as follows:

  view  Ex Ey Ez  Gx Gy Gz  Ux Uy Uz
Where E is the eye position, G the position to be gazed at and U the up vector. Note that the view specification must come before any triangle specifications for the triangle culling to work properly.


Timings are for 256x256 pixel images on a PentiumIII 733Mhz with 384MB SDRAM
(unless otherwise noted).


sphereflake1 sphereflake2
sphereflake3 sphereflake4
Four images of a sphereflake at four different stages of "bloom".

1: 10 spheres, 2 lights: 0.24 seconds.
2: 91 spheres, 2 lights: 1.59 seconds.
3: 820 spheres, 2 lights: 15.65 seconds.
4: 7381 spheres, 2 lights: 286.78 seconds.

(click on each of the images for a larger view).


dolphins-1 dolphins-2
dolphins-3 dolphins-4
A scene with dolphins from four different views.

1: 1692 tris (847 culled), 2 lights: 14.12 seconds.
2: 1692 tris (859 culled), 2 lights: 19.67 seconds.
3: 1692 tris (750 culled), 2 lights: 20.44 seconds.
4: 1692 tris (801 culled), 2 lights: 17.53 seconds.

(click on each of the images for a larger view).


colorcube-01 colorcube-02 colorcube-03 colorcube-04
colorcube-05 colorcube-06 colorcube-07 colorcube-08
colorcube-09 colorcube-10 colorcube-11 colorcube-12
colorcube-13 colorcube-14 colorcube-15 colorcube-16
My color cube scene - 125 spheres with 6 lights (one on each side). Each scene was rendered in ~5.7 +/-0.3 seconds (depending on the view).
I created an animation from these frames (in quality order):
Poor: Indeo Video (155 Kb)
Good: Intel IYUV (2.307 Mb)
Better: DivX MPEG (182 Kb)
Best: Uncompressed (4.611 Mb)

(click on each of the images for a larger view).

I thought that there was a weird lighting bug in my code when I saw the flecks of light on the corner spheres. But, I realized that these are bits of the spheres that are not in any shadow and the highlights are caused by the lights on the sides peeking through the sliver of air between the outside slabs of spheres.



Other Images (timed & rendered at 800x800).


al f-16 flowers porsche
al (capone)

7124 triangles
3262 culled
2 lights
1220.92 seconds
(00:20:20.9)
f-16

4592 triangles
2414 culled
2 lights
400.841 seconds
(00:06:40.8)
flowers

7625 triangles
3982 culled
2 lights
946.095 seconds
(00:15:46.1)
porsche

7322 triangles
3294 culled
2 lights
1278.17 seconds
(00:21:18.2)


rose+vase soccerball galleon teapot
rose+vase

3360 triangles
1844 culled
2 lights
257.479 seconds
(00:04:17.5)
soccerball

3516 triangles
1761 culled
2 lights
451.698 seconds
(00:07:31.7)
galleon

4698 triangles
2547 culled
2 lights
491.149 seconds
(00:08:11.1)
teapot

6320 triangles
3168 culled
2 lights
836.533 seconds
(00:13:56.5)


2x2x2 3x3x3 4x4x4 5x5x5
8 spheres
1 light
1.76382 seconds
(00:00:01.8)
27 spheres
1 light
4.38312 seconds
(00:00:04.4)
64 spheres
1 light
9.41299 seconds
(00:00:09.4)
125 spheres
1 light
17.8478 seconds
(00:00:17.8)


6x6x6 7x7x7 8x8x8 9x9x9
216 spheres
1 light
30.7222 seconds
(00:00:30.7)
343 spheres
1 light
51.0782 seconds
(00:00:51.1)
512 spheres
1 light
83.9632 seconds
(00:01:23.0)
729 spheres
1 light
116.999 seconds
(00:01:56.0)


10x10x10 15x15x15 20x20x20 25x25x25
1000 spheres
1 light
153.043 seconds
(00:02:33.0)
3375 spheres
1 light
526.735 seconds
(00:08:46.7)
8000 spheres
1 light
2503.54 seconds
(00:41:43.5)
15625 spheres
1 light
4890.18 seconds
(01:21:30.2)


All of the images above can be regenerated by specifying the appropriate scene file on the command line of the rayn program rayn-02.zip (1.42 Mb). The source code is included in the zip file. Here is a description of the command line parameters for rayn.
rayn [@response] [options]

  options:
    -output     <output_file>      output image filename (string).
    -size       <width,height>     size of output image (int,int).
    -background <red,green,blue>   background color (int,int,int).
    -scene      <scene_file>       file containing scene description (string).

  @reponse:
    Specifies a file from which options are to be read,
    one option per line.  Options which are specified on
    the command line override those in the response file.

Questions/comments to nate@pobox.com.



January 2002
© Nate Robins