320 likes | 369 Views
CAP4730: Computational Structures in Computer Graphics. Ray Tracing. Chapter 10.11. Outline. What is raytracing? How is raytracing different than what we’ve done before? Math behind raytracing Uses of raytracing. Forward Mapping. Forward mapping is what we are used to. Forward Mapping.
E N D
CAP4730: Computational Structures in Computer Graphics Ray Tracing Chapter 10.11
Outline • What is raytracing? • How is raytracing different than what we’ve done before? • Math behind raytracing • Uses of raytracing
Forward Mapping • Forward mapping is what we are used to.
Forward Mapping • Take each primitive • Figure out where on the screen it should appear • Also known is feed-forward
Ray Tracing • Ray tracing is the “inverse” of the “forward” mapping we are used to.
Ray Tracing • Also known as inverse mapping or feed-backward
Feed-Forward vs. Feed-Backward • Pros and Cons of each
Ray-Tracing • Attempts to trace the paths of light that contribute to each pixel that make up a scene • Instead of computing visible surfaces, determine intensity contributions • Compute global illumination • Allows for: • Reflection • Refraction • Atmospheric effects • Shadows • Results in very realistic scenes • Used in movies, animations, cut-scenes
for (j=0;j<IMAGE_HEIGHT;j++) for (i=0;i<IMAGE_WIDTH;i++) result=CheckForIntersection(i,j) SetPixel(i,j,result); CheckForIntersection(i,j) ray = vector from eye through pixel on display plane if (DetermineIntersection(ray, color)) return color; • Center of Projection • Infinite Rays • Care about ones that pass through the virtual screen • For each pixel • Compute ray to a pixel • For each object in the scene • Compute the intersection between ray and object • Find closest intersection • Calculate illumination • Similar to a pinhole camera
Computational Cost of Ray Tracing • Let’s compute a formula for how much work we have to do: • O(i*j*intersection tests) • What is an intersection test? • What is the cost of an intersection test? • We test the ray going from the eye through each pixel for an intersection with any object. • How are objects specified?
Ray Triangle Intersection • Ray is specified as a vector and a starting position (camera) • There are many different methods (search the web) to do ray - triangle intersection • One solution: Intersect with the plane of the triangle. Determine if the intersection point is within the triangle
Defining objects • We don’t have to use triangles exclusively. • Let’s think about other objects and the different intersections. How would we specify: • Spheres • Cylinders • Cubes • Other base geometric objects
Ray Intersections http://www.swin.edu.au/astronomy/pbourke/geometry/sphereline/ Since performance is so closely tied to ray-object intersections, we’d like to speed it up. How can we speed things up? Break down things into two steps, detecting intersections, and determining location of intersection.
Ray Intersections • We are emulating “reality” where light reaches our eye. • We are asking “what is the path of the light that reached our eye for that pixel?” • Ray Tracing (in the way we know it), was started by Turner Whitted (1980). • With ray tracing, we can solve for global illumination.
Ray Tracing Observations • Each pixel must be evaluated • Hard for non solid objects • No screen space coherence • Difficult to do in parallel • Difficult to accelerate
Recursive Ray-Tracing • How would we compute lighting? Let’s reverse the light ray that got to our eye • Upon intersection, fire ‘secondary rays’ Vector to the light Refraction Ray Reflected Ray
Upon Intersection L, shadow ray • How do we compute each? • Why follow each ray? • Each contributes intensity to the intersection position! R T Θr N Θi u
L, shadow ray • indices of refraction R T Θr N Θi u
Ray-Surface Intersection • Ray • P=P0 + s*u • P0 - initial point of ray • u – unit vector • u = (pixel – COP)/|(pixel-COP) • s – distance along vector
Recursive Ray-Tracing • Shadows Vector to the light Refraction Ray Reflected Ray
Recursive Ray-Tracing • For each ray, we repeat the process • How many “levels of recursion” should we do? Vector to the light Refraction Ray Reflected Ray
Rercursion • How do we compute the refraction vector? • What properties would you want to include with an object? Vector to the light Refraction Ray Reflected Ray
Depth of recursion • Time vs. Accuracy • Tree Data Structure • ray-tracing tree • pg. 599 in book • How deep is the tree? • What are some end conditions? • What are some acceptable end-limits?
Lighting • So how do we compute the final color? • We can employ many lighting models • Phong Lighting • Torrence-Sparrow • BRDF models • What lighting can it not do? • Caustics (focused light like in water) • specular to specular or diffuse • diffuse to diffuse or specular
Lighting • We’ll cover lighting much more in depth later • For now: • Three terms • Ambient – global light that exists (hack) • Diffuse –contribution of a light. Dependent on light location • Specular – contribution of a light that is wrst user’s eye • L = kaIa + kd(n*L) +ks(h*N)ns
Pros Transparency Reflections Shadows Complex Primitives (math equations) Easy to write Cons Hard to accelerate Isn’t the complete global illumination Very slow per pixel calculation. Ray Tracing Pros and Cons
What is slow about Ray Tracing? • Ray Triangle intersections • Let’s talk about bounding volumes • Heirarchies? • What are some properties of the volumes that determines how “good” a bounding volume is?
Spatial Subdivision Divide space into regions Place objects into different regions Compute which regions you can “see” from your current position Only test those objects Developing a hierarchy of tests
Other Tricks • How would we do • antialiasing • texturing • transparency • different material properties Vector to the light Refraction Ray Reflected Ray
Ray Tracing • http://graphics.lcs.mit.edu/classes/6.837/F98/Lecture20/RayTrace.java • POV-Ray (www.povray.org)