Computer Graphics Project

GPU Ray Tracing


By : Amit Ben-David






Ray tracing is a popular algorithm used to create photo realistic images by correctly simulating the interaction of a light ray with the life like material.
Ray tracing involves tracing the path of light as it bounces around the scene.  The most time consuming operation of ray tracing is that of determining which piece of the scene is hit by a given ray of light.
Ray-tracing has always been thought of as the domain of the CPU. However since Ray-tracing is “trivial parallel” it can better utilize the parallel hardware resources of the GPU (16+ fragment pipelines in modern GPUs). Harnessing the strength of the GPU for parallelism have only recently been feasible due to programmable hardware – commonly known as shader (vertex/fragment) programs.



Implementing Ray-Tracing using the GPU :

Most citations on the subject use the following Streaming computation to map
Ray-Tracing to the GPU :


The Ray-Tracing algorithm is divided into kernels which can be executed iteratively until the outputted final color.  Each kernel is actually a fragment program.

The Ray-tracing is done in a backward manner, instead of ray-tracing light rays to the camera we are tracing the camera rays (each screen pixel) to the light which is less expensive.

        i.  Generating camera primary rays :
The camera rays are generated using a view-port size quad, for each pixel a fragment is created and a kernel calculating the origin and direction is executed, output is stored in a 2D texture.

        ii. Traverse + intersect :
The traversal/intersection kernel takes as input ray origins and directions along with a representation of the scene in an acceleration structure (described in section 3) . If the ray intersects - the kernel return the point of intersection, distance of the intersection point from the origin, and a reference to the triangle material intersected.

        iii.Shading :
Having computed the intersection status for all the primary rays, we can look up the surface normals and material properties needed for shading. Each intersection record stores an index into the material texture that contains the triangle normals and material color and type.
The final pixel color can now be calculated according to the lighting equation. Now, depending on the type of material we have hit (diffuse or specular), we need to generate secondary rays to account for shadows and reflections, we can also generate refracted rays for transparent surfaces.
Having generated the appropriate secondary rays for each pixel, we can perform another traversal/intersection pass, if needed. Each invocation of the shading kernel returns both a color and a new ray for each pixel. The shading kernel also takes as input the color buffer output by previous shading passes. This makes it possible to combine the colors of successive specular surfaces as we trace successive rays.



Acceleration structures:
In the master thesis of Thrane and Simonsen, titled a “A Comparison of Acceleration Structures for GPU Assisted Ray Tracing” The authors present 3 acceleration structures :

Project details :

Implementing a GPU based BVH Ray-Tracer which includes :

Project Summary  :  CG_Project_GPU_Ray_Tracing_Summary.rar

GPU Ray Tracing Application :

Source & Binaries :     CGProjectRayTracer.rar

Models :   Models.rar

      Contents :

        Hardware Requirements :


Ray Tracer Application Manual




When marking an object the material will light with emissive cyan color.







The following images were created on an Intel Pentium 3.2GHZ machine with 2GB RAM and using NVidia Geforce FX 6800 Graphic Card.
Along with each image are GPU & CPU rendering times for comparison, both using the BVH acceleration structure.

Basic Reflections

GPU : 2.15 sec , CPU : 3.2 sec

Reflections with 3 Light Sources with no Antialiasing

GPU : 4.1 sec , CPU : 6.8 sec


Reflections with Antialiasing

GPU : 10.3 sec , CPU : 21.9 sec

Reflections with Texture Mapping

GPU : 3.2 sec , CPU : 7.5 sec

Reflections with Texture Mapping with Antialiasing

GPU : 24.6 sec , CPU : 148.9 sec

Reflections and Refractions

GPU : 9 sec , CPU : 8.5 sec

Reflections and Refractions

GPU : 9 sec , CPU : 8.5 sec


References :

  1. Ingo Wald and Philipp Slusallek, State of the art in interactive ray tracing, Saarland Univeristy. 2001
  2. Nathan A. Carr, Jesse D. Hall, and John C. Hart. The ray engine.
    In Proc.Graphics Hardware 2002, pages 37–46, Sep. 2002.
  3. Timothy J. Purcell, Ian Buck, William R. Mark, and Pat Hanrahan. Ray tracing on programmable graphics hardware.
    In Proc. SIGGRAPH, 2002.
  4. Filip Karlsson and Carl Johan Ljungstedt. Ray tracing fully implemented on programmable graphics hardware.
    Master’s thesis, Chalmers Univ. of Technology, 2004.
  5. Martin Christen. Ray tracing on GPU.
    Master’s thesis, Univ. of Applied Sciences Basel (FHBB), 2005.
  6. Niels Thrane and Lars Ole Simonsen. A comparison of acceleration structures for GPU assisted ray tracing.
    Master’s thesis, University of Aarhus, Denmark, 2005.
  7. Nathan and Jared Hoberock and Keenan Crane and John C.Hart, Fast GPU Ray Tracing of Dynamic Meshes using Geometry images.
    Univeristy of Illinois, Urbana-Champaign, 2006