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.
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.
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.
+ 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.
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.
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 :
The scene is subdivided to a uniform grid of 3D voxels, each voxel stores an index to a list of triangles that intersect it.
The scene is represented an hierarchical structure based on a binary tree. Leaf nodes correspond to voxels containing triangle lists and internal nodes corresponds to a region partition of space.
The BVH is a hierarchical scene partitioning structure based on a binary tree. However in contrast to KD/OC trees, the subdivision of the BVH into two sub hierarchies is based on object partitioning and not volume partitioning. Leaf nodes correspond to a triangle lists and internal nodes corresponds to the bounding volume of the sub hierarchies.
Implementing a GPU based BVH Ray-Tracer which includes :
Shadows (try using shadow-maps to accelerate ray-tracing shadow-rays).
Using a model viewer to browse the scene before ray-tracing.
Using OpenSceneGraph library for importing scenes to the viewer. Supported formats include : 3dmax , osg, vrml.
Export ray-tracer output to file as png/bmp.
Project Summary : CG_Project_GPU_Ray_Tracing_Summary.rar
Source & Binaries : CGProjectRayTracer.rar
Models : Models.rar
project (Visual studio 7.1 solution).
External packages :
(Visual studio 7.1 solution) :
The Project uses the OSG (OpenSceneGraph) open source library for loading the variant model types : OSG , 3DS, VRML.
This OSG version is not standard as I have added a couple of methods in the osg::Vec3f class and a png writer plugin As well as the VRML plugin which is provided seperatly by a contributer of OSG.
(binaries only) :
used parsing VRML files.
Provided is a binary directory containing all the needed dlls and exe files including a sub directory containing the shaders, which must be in the GLSL_RAYTRACER.exe level.
libraries (3rd party) :
Needed for compilation of the GLSL RAYTRACER project are Provided in a directory called lib.
Hardware Requirements :
The Application was tested on a NVidia GeForce FX 6200 Graphic card and should work on more advanced NVidia cards.
No support for ATI Graphic cards.
Main Frame :
=> Load Model from file
Supported model types: osg, vrml, open flight, light wave, 3dmax, directX.
=> Save Screen to file
Supported formats: bmp, png.
View => Tool Bar
Enable / Disable the Tool Bar.
View => Status
Enable / Disable the Status Bar.
Translate / Rotate Eye
Translate along a given axis or Rotate the line of sight in around a given axis. Scene center is always in the middle of the scene.
The Translation/Rotation is triggered when pressing the left mouse button and moving horizontally.
Action => GPU /
CPU Ray tracing (blue/ green running man):
Render using GPU / CPU Ray tracing.
Both methods use the BVH representation. CPU is given as reference to check integrity of the GPU.
Action => Anti Aliasing :
When rendering using GPU / CPU apply Anti Aliasing.
Anti Aliasing is 2x2 multi sample implemented as rendering each frustum quarter as a full image to temp buffer, shrink it 2x2 and insert it to the output image.
Axis => X / Y/ Z
The axis for Translation / Rotation.
Lighting => Material
Control for each object the diffuse/specular/ambient color.
Control for each object the Reflect/Refract ratio and the Refraction index.
When marking an object the material will light with emissive cyan color.
Control up to three point lights.
For each light source Control the diffuse/specular/ambient color.
For each light source Control the position of the light.
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.
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
- Ingo Wald and Philipp Slusallek, State of the art in interactive ray tracing, Saarland Univeristy. 2001
- Nathan A. Carr, Jesse D. Hall, and John C. Hart. The ray engine.
In Proc.Graphics Hardware 2002, pages 37–46, Sep. 2002.
- Timothy J. Purcell, Ian Buck, William R. Mark, and Pat Hanrahan. Ray tracing on programmable graphics hardware.
In Proc. SIGGRAPH, 2002.
- Filip Karlsson and Carl Johan Ljungstedt. Ray tracing fully implemented on programmable graphics hardware.
Master’s thesis, Chalmers Univ. of Technology, 2004.
- Martin Christen. Ray tracing on GPU.
Master’s thesis, Univ. of Applied Sciences Basel (FHBB), 2005.
- Niels Thrane and Lars Ole Simonsen. A comparison of acceleration structures for GPU assisted ray tracing.
Master’s thesis, University of Aarhus, Denmark, 2005.
- Nathan A.car 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