Ray Tracing Kjetil Babington 21.10.2011 1
Introduction What is Ray Tracing? Act of tracing a ray through some scene Not necessarily for rendering Rendering with Ray Tracing Ray Tracing is a global illumination based rendering method for generating realistic images 2
Overview Forward Ray tracing Rays from light source bounce of objects before reaching the camera Computational wastage Backward Ray tracing Track only those rays that finally made it to the camera 3
Ray Casting Ray Casting visible surfaces of objects are found by throwing (or casting) rays of light from the viewer into the scene Ray Tracing Extension to Ray casting Recursively cast rays from the points of intersection 4
Tree of Light Contributions of light grows at each contact point 1 is the sum of reflected component R 4, transmitted component T 1 and the local component L 1 Local component is the ambient, diffuse and specular reflections at P h 5
Ray Tracing Sometimes a ray misses all the objects created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991 6
Ray Tracing (contd.) Sometimes the Ray hits an objects created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991 7
Phong Traditional shading model Improved model 8 n j s j d a H N k k I I L N ) ( ) ( k T S k k I I t s j d a L N ) (
Ray Tracing (contd.) Is the intersected point in shadow? Send Shadow Rays to light source created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991 9
Adding shadows P is not in shadow with respect to L 1 P is in the shadow of the cube with respect to L 2 Self-shadowing of P with respect to L 3 Shadow rays Spawn a ray from P to the light sources If there is an intersection of the shadow ray with any object then P is in shadow Courtesy F.S. Hill, Computer Graphics using OpenGL 10
Ray Tracing (contd.) Reflected ray generated at point of intersection Tested with all the objects in the scene created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991 11
Reflection Given a surface normal n and incident ray a you can find the reflected ray r 180 1 adapted from F.S. Hill, Computer Graphics using OpenGL 12
Ray Tracing (contd.) Transparent object Spawn a transmitted ray and test against all objects in the scene created by Michael Sweeny, et al for ACM SIGGRAPH Education slide set 1991 13
Refraction Bending of light rays as it crosses interface between media having different refractive indices Snell s Law c sin c sin 1 1 2 2 c 1,c 2 Refractive index Courtesy F.S. Hill, Computer Graphics using OpenGL 14
Requirements for Ray tracing Send a ray into the scene for each 2D image pixel Compute the intersection point of ray with nearest object in scene Test each primitive in the scene for intersection Find nearest intersection Recursively spawn rays from the point of intersection Shadow Rays Reflected rays Transmitted rays Accumulate the color from each of the spawned rays at the point of intersection 15
Reflection Created by David Derman CISC 440 16
Reflection Created by David Derman CISC 440 17
Reflection Created by David Derman CISC 440 18
Reflection Created by David Derman CISC 440 19
Ray tracing flow Local Phong illumination Figure out reflected/ refracted ray direction and recurse Adapted from F.S. Hill and CISC 640/440, Fall 2005 20
Super-sampling Ray tracing is a point-sampling process Take discrete looks at the scene along individual rays passing through each pixel Reduce aliasing due to this discrete signal sampling 21
Super-sampling Instead of shooting one ray per pixel, shoot four rays through the corners of a pixel Color at the pixel is the average of the colors at each corners Adaptive super-sampling Compute the intensity variation between the four corners with the average Shoot more rays through corners with higher intensity variation Compute final color as a weighted average rather than the regular average Courtesy F.S. Hill, Computer Graphics using OpenGL 22
Using bounding boxes Most of the time is spent in computing intersections Each ray should be intersected with every object in the scene Each ray, spawns out reflected/transmitted rays which have to be interested with the objects in the scene 23
Bounding box Bounding box of an object is a shape that encloses a object Compute complicated intersections if and only if the ray hits the bounding box Two shapes most commonly used as bounding boxes Sphere specified by a center and radius (C, r) Box specified by sides aligned to the coordinate axis 24
Real time ray tracing using nvidia Optix Paper by H. Ludvigsen and A. C. Elster Presented at Eurographics 2010 Optix, a ray tracing framework Showed that Optix can achieve real time ray tracing performance Optix can give near perfect speed up by using 2 GPUs 25
References Papers I presented An Improved Illumination Model for Shaded Display http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.156.1534 Real-Time Ray Tracing Using Nvidia OptiX. H. Ludvigsen1 and A. C. Elster http://www.idi.ntnu.no/~elster/pubs/eurographics-ludvigsen-elster.pdf 26