CS 645 Computer Graphics Assignment 3

Ray Tracer

 

Student Name:  Zhu, Jiajun (or Isaac)

Date of submission: 09/28/2005

Download Source: Source Code.zip (130 KB) (Visual C++. Net)

Download Executable File: Executable File.zip (76 KB)

Download Art Contest Images: Art Contest.zip (297 KB)


Contents 

    1.  Basic Requirements:

        (1)     Triangle and Normal Triangle

        (2)     Sphere

        (3)     Materials

        (4)     Point Lighting

        (5)     Spot Lighting

        (6)     Directional Lighting

        (7)     Ambient Lighting

        (8)     Recursive Depth

 

    2. Extra Features:

        (9)       Cone and Cylinder

        (10)     Soft Shadow

        (11)     Transparent Object

        (12)     Depth of Field

        (13)     Motion Blur

        (14)     Texture Mapping

        (15)     3D Transformation

        (16)     Jittered Super-sampling

        (17)     Adaptive Super-sampling

        (18)     Acceleration Structure

 

    3. Writing up

    4. Art Contest

    5. References


Results   Note: following pictures have been converted to JPEG format (i.e. may looks different to what it originally is).

    (1) Triangle and Normal Triangle:

  400 x 400 JPG

Normal triangle (left) and Regular triangle (right)

Adaptive Super-sampling at 2 samples per pixel

Scene File 687 Bytes. [download]

     [ back to content ]


    (2) Sphere :

400 x 400 JPG

Three spheres with different size and position. 

Adaptive Super-sampling at 2 samples per pixel

Scene File 681 Bytes. [download]

 

[ back to content ]


  (3) Material:

400 x 400 JPG

Triangle and Sphere rendered in Materials different in diffuse,

specular colors,  cosine value, refraction, and transparent colors.

Adaptive Super-sampling at 2 samples per pixel

Scene File 1.47 KB. [download]

 

[ back to content ]


(4) Point Lighting:

400 x 400 JPG

Two spheres under a white colored point light.

Adaptive Super-sampling at 2 samples per pixel

Scene File 579 Bytes. [download]

 

[ back to content ]


(5) Spot Lighting:

400 x 400 JPG

Two spheres under a white colored spot light.

Adaptive Super-sampling at 2 samples per pixel

Scene File 596 Bytes. [download]

 

[ back to content ]


(6) Directional Lighting:

400 x 400 JPG

Two spheres under a white colored directional light.

Adaptive Super-sampling at 2 samples per pixel

Scene File 604 Bytes. [download]

 

[ back to content ]


(7) Ambient Lighting:

400 x 400 JPG

Two spheres under a white colored ambient light.

Adaptive Super-sampling at 2 samples per pixel

Scene File 642 Bytes. [download]

 

[ back to content ]


(8) Recursive Depth:

       

Both of their formats are 400 x 400 JPG

left picture: Recursive Depth = 1         right picture: Recursive Depth = 2

Four full reflection spheres and one light yellow shade transparent ball.

Adaptive Super-sampling at 2 samples per pixel

Scene File 765 Bytes. [#1:  download] [#2:  download]

 

       

Both of their formats are 400 x 400 JPG

left picture: Recursive Depth = 5         right picture: Recursive Depth = 10

Four full reflection spheres and one light yellow shade transparent ball.

Adaptive Super-sampling at 2 samples per pixel

Scene File 765 Bytes. [#5:  download] [#10:  download]

 

[ back to content ]


(9) Cone and Cylinder:

400 x 400 JPG

Pairs of pink cones and cylinders under a white colored point light.

Adaptive Super-sampling at 2 samples per pixel

Scene File 654 Bytes. [download]

 

[ back to content ]


(10) Soft Shadow:

        

Both formats are 400 x 400 JPG

left picture: hard shadow        right picture:  soft shadow

One green sphere, one transparent blue cylinder, and one transparent pink box under a white colored spot light.

In the right picture, light source area is presented by 5 lighting points bounded in a sphere which radius is 0.1

Adaptive Super-sampling at 2 samples per pixel

Scene File 824 Bytes. [right picture:  download]

 

[ back to content ]


(11) Transparent Object:

400 x 400 JPG

One green sphere, one transparent blue cylinder, and one transparent

pink box under a white colored spot light. The shadows of transparent

the objects are also colored this time. This is implemented by recursively

tracking the shadow rays. Every time the shadow rays hit an object,

the material information of hit point is used to determine the color of the shadow.

Adaptive Super-sampling at 2 samples per pixel

Scene File 824 Bytes. [download]

 

[ back to content ]


(12) Depth of Field:

400 x 400 JPG

A line of different colored spheres.

Focal plane is set to 5.0 (near to the camera). The aperture is represented by

5 points bounded in a sphere which radius is 0.1 and center is the eye position.

Adaptive Super-sampling at 2 samples per pixel. 

 

Scene File 1.45 KB. [download]

 

400 x 400 JPG

A line of different colored spheres.

Focal plane is set to 7.0.  The aperture is represented by 5 points

 bounded in a sphere which radius is 0.1 and center is the eye position.

Adaptive Super-sampling at 2 samples per pixel. 

 

Scene File 1.45 KB. [download]

 

400 x 400 JPG

A line of different colored spheres.

Focal plane is set to 9.0 (far to the camera). The aperture is represented by

5 points bounded in a sphere which radius is 0.1 and center is the eye position.

Adaptive Super-sampling at 2 samples per pixel. 

Scene File 1.45 KB. [download]

 

[ back to content ]


(13) Motion Blur:

400 x 400 JPG

Several different colored moving spheres.

In order to generate the motion blur effect, each ray is given a random timestamp which is

between 0.0 ~ 1.0. Moving objects are defined by start position, target position, start time,

and end time.  Before calculating the intersection points,  these objects update their positions

 according to  the ray timestamp. What should be noted is that this method requires much higher

sample rates to create acceptable images.

Uniform Super-sampling at 100 samples per pixel.

 

Scene File 1.64 KB. [download]

 

[ back to content ]


(14) Texture Mapping:

400 x 400 JPG

On the glass are the sun, the mars, the moon, and the earth. (obviously in wrong scales :-) )

Texture mapping for triangle, 4-sides polygon, and box are also implemented.

Adaptive Super-sampling at 2 samples per pixel.

Scene File 1.51 KB. [download]

 

[ back to content ]


(15) 3D Transformation:

        

Both formats are 400 x 400 JPG

left picture: original object        right picture:  translate transformation

Pink boxes under two white colored point lights.

In the right picture, a translate (0, 0.5, 0) matrix is performed between rendering each boxes.

Adaptive Super-sampling at 2 samples per pixel

Scene File 1.39 Bytes. [right scene:  download]

 

        

Both formats are 400 x 400 JPG

left picture: original object       right picture:  rotate + translate transformation

Pink boxes under two white colored point lights.

In the right picture, a translate (0, 0.6, 0) and a rotation of 40 degrees

along with the axis ( 1, 0, 1) are performed between rendering each boxes.

Adaptive Super-sampling at 2 samples per pixel

Scene File 1.54 Bytes. [right scene:  download]

 

        

Both formats are 400 x 400 JPG

left picture: original object        right picture:  translate + scale transformation

Pink boxes under two white colored point lights.

In the right picture, a translation (0, 0.47, 0) and a

scaling  (1.1, 1, 1) are performed between rendering each boxes.

Adaptive Super-sampling at 2 samples per pixel

Scene File 1.43 Bytes. [right scene:  download]

 

 

400 x 400 JPG

Boxes using combination of transformations.

Adaptive Super-sampling at 2 samples per pixel

Scene File 7.27 Bytes. [ download]

 

 

[ back to content ]


(16) Jittered Super Sampling:

400 x 400 JPG

A collection of full transparent, semi-transparent, and full reflecting objects.

No super-sampling technique are used. Aliasing is pretty obvious. 

Scene File 1.66 KB. [download]

 

 

        

Both formats are 400 x 400 JPG

left picture:  using Jittered Super-sampling, 2 samples per pixel

right picture:  using Jittered Super-sampling, 4 samples per pixel

A collection of full transparent, semi-transparent, and full reflecting objects.

The quality of the image is much improved by using Jittered Super-sampling, but its pretty slow.

Scene File 1.66 KB. [right scene:  download]

 

[ back to content ]


(17) Adaptive Super Sampling:

        

Both formats are 400 x 400 JPG

left picture:  using Adaptive Super-sampling, 2 samples per pixel

right picture:  super-sampled pixels are colored in white.

A collection of full transparent, semi-transparent, and full reflecting objects.

The quality of the image is also good by using Adaptive Super-sampling, while the time is much shortened.

Scene File 1.66 KB. [right scene:  download]

 

 

[ back to content ]


(18) Acceleration Structure:

400 x 400 JPG

100 spheres in different size, position and material.

non-acceleration:    10.07 sec

bounding box :       15.05 sec *

grid-based search:    4.79 sec

  bounding box + grid:  5.15 sec

* More discussion in the write up

Scene File 9.89 KB. [download]

 

 

400 x 400 JPG

1000 spheres in different size, position and material.

non-acceleration:    3 min 54 sec

bounding box :         6 min 46 sec

grid-based search:        26.52 sec

bounding box + grid:    40.71 sec

 

Scene File 93.3 KB. [download]

 

400 x 400 JPG

10000 spheres in different size, position and material.

non-acceleration:    N/A*

bounding box :         N/A*

                             grid-based search:                1 min 49 sec

      bounding box + grid:   N/A*

(N/A*: takes very long time, I have not tested them yet)

 

Scene File 929 KB. [download]

 

[ back to content ]


Write up:

 

    The most important thing is that I now realize making a ray tracer from scratch is not only doable but also very2 worth doing. In this assignment, I learnt many concepts such as geometry, lighting, color, shade, material, and a little modeling (by practice!).  The only bad thing is that I cannot really focus on other course-projects during this week. You know, compared with "branch prediction simulator",  this one is much more exciting!

 

    Testing and writing the code incrementally is very important. For example, at the very beginning, I only implemented one primitive -- sphere, and used it to test different camera positions, lighting directions, shadow rays, and material. That makes me feel comfortable when I move onto the code for other primitives, because at least I know my ray tracer works.

 

    Another important thing (I learnt it the hard way) is that the more basic ideas you understand before you start to code (not only concepts like "recursive ray tracing", but also stuffs like "grid acceleration", "depth of field", "soft shadow", and etc.), the much better code you will write. I started to write the code even before I understand how the grid, DOF, and soft shadow are implemented. This brought me a lot of troubles in modifying the code. Sometimes I feel what I am doing is to mess up what I have already done.

 

    An acceleration structure is necessary, that makes you believe there still is a hope after pressing "F5". There are many ways to do acceleration, the reason I chose Grid and Bounding Box is that they are relatively easier and can be implemented quickly.  I don't know yet why Bounding Box doesn't work very well to "spheres" (in my experiment), but it does speed up something in triangle intersections.  I divided the space into (log(num_objects) ^ 3) grids, which I think might be reasonable. With grid structure, my ray tracer can do something in less than 1 minute while it takes more than 30 minutes before.

 

    Modeling! It's so difficult to create interesting scene. I tried searching for some tools to convert popular 3d models to our format, but failed. It would be really great (and save a lot of time) if the course provides us a tool to do this job. I probably will write a tool when I have more time.

       
[ back to content ]


Art Contest:

 

              

[ back to content ]


References:

    (1) Rotate a point about an arbitrary axis (3 dimensions): http://astronomy.swin.edu.au/~pbourke/geometry/rotate/

    (2) Fast Soft Shadow Algorithm: http://www.cs.utah.edu/~bes/papers/coneShadow/shadow-node3.html

    (3) A Fast Voxel Traversal Algorithm For Ray Tracing: John Amanatides and Andrew Woo

    (4) Depth of Field: http://glasnost.itcarlow.ie/~powerk/Graphics/Notes/node12.html

    (5) Motion Blur: http://www.jasonwaltman.com/graphics/rt-motion.html

 

[ back to content ]