410 likes | 915 Views
An Introduction to Ray Tracing. Photo-Realism. Introduction. What is Ray Tracing? Ray Tracing is a global illumination based rendering method for generating realistic images on the computer In ray tracing, a ray of light is traced in a backwards direction.
E N D
Introduction • What is Ray Tracing? • Ray Tracing is a global illumination based rendering method for generating realistic images on the computer • In ray tracing, a ray of light is traced in a backwards direction. • We start from the eye or camera and trace the ray through a pixel in the image plane into the scene and determine what it intersects • The pixel is then set to the color values returned by the ray. • If the ray misses all objects, then that pixel is shaded the background color
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
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
Ray Tracing • Sometimes a ray misses all objects
Ray Tracing (contd.) • Sometimes a ray hits an object
Ray Tracing (contd.) • Is the intersected point in shadow? • “Shadow Rays” to light source
Ray Tracing (contd.) • Shadow rays intersect another object • First intersection point in shadow of the second object
Ray Tracing (contd.) • Shadow rays intersect another object • First intersection point in shadow of the second object
Ray Tracing (contd.) • Reflected ray generated at point of intersection • Tested with all the objects in the scene
Ray Tracing (contd.) • Local illumination model applied at the point of intersection
Ray Tracing (contd.) • Transparent object • Spawn a transmitted ray and test against all objects in the scene
Requirements for Ray tracing • Compute 3D ray into the scene for each 2D image pixel • Compute 3D 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
Ray object intersection • Equation of a ray • “S” is the starting point and “c” is the direction of the ray • Given a surface in implicit form F(x,y,z) • plane: • sphere: • cylinder: • All points on the surface satisfy F(x,y,z)=0 • Thus for ray r(t) to intersect the surface • The hit time can be got by solving
Ray object intersection • Ray polygon intersection • Plug the ray equation into the implicit representation of the surface • Solve for “t” • Substitute for “t” to find point of intersection • Check if the point of intersection falls within the polygon
Ray object intersection • Ray sphere intersection • Implicit form of sphere given center (a,b,c) and radius r • Intersection with r(t) gives • By the identity • the intersection equation is a quadratic in “t” • Solving for “t” • Real solutions, indicate one or two intersections • Negative solutions are behind the eye • If discriminant is negative, the ray missed the sphere
Adding shadows • P is not in shadow with respect to L1 • P is in the shadow of the cube with respect to L2 • “Self-shadowing” of P with respect to L3 • “Shadow Feelers” • 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 NOTE: Intersection should be between the point and light source and not behind light source
Adding shadows • “Self-Shadowing” • Always an intersection of shadow feeler with object itself • Move start point of the shadow ray towards the eye by a small amount • No intersection with itself
Reflection • Given surface normal “n” and incident ray “a” find the reflected ray “r”
Refraction • Bending of light rays as it crosses interface between media having different refractive indices • Snell’s Law c1,c2 – Refractive index
Refraction • Estimation the refracted ray T, given u and N (unit vectors) • If we assume that ni and nr are the refractive indices of the medium having the incoming ray and refracted ray respectively • Let and be the corresponding angle of incidence and refraction • Let k be a unit vector perpendicular to N • By Snell’s Law we have
Refraction • Decomposing the incident ray (u) • Decomposing the refracted ray (T) • Solving for k from u
Refraction • Substituting in T • From Snell’s Law • Solving for T
Tree of Light • Contributions of light grows at each contact point • I is the sum of reflected component R1, transmitted component T1 and the local component L1 • Local component is the ambient, diffuse and specular reflections at Ph • R1 is the sum of R3, T3 and local L3 and so on ad infinitum
Ray tracing flow Local Phong illumination Figure out reflected/ refracted ray direction and recurse
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
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 (Whitted’s approach) • 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
Using Extents • Ray tracing is slow, performing the same functions. • 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
Using Extents • Extent of an object is a shape that encloses the object • Compute complicated intersections if and only if the ray hits the extent • Two shapes most commonly used as extents • Sphere – specified by a center and radius (C , r) • Box – specified by sides aligned to the coordinate axis
References • Textbooks • F. S. Hill, “Computer Graphics Using OpenGL” • Commonly used ray tracing program (completely free and available for most platforms) • http://www.povray.org/ • Interesting Links • Interactive Ray Tracer – Alyosha Efros • http://www.cs.berkeley.edu/~efros/java/tracer/tracer.html • Ray Tracing explained • http://www.geocities.com/jamisbuck/raytracing.html • http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtrace0.htm