raytracing - CAP4730: Computational Structures in Computer...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CAP4730: Computational Structures in Computer Graphics Ray Tracing Ray Tracing Chapter 10.11 Outline Outline What is raytracing? s How is raytracing different than what we’ve done before? s Math behind raytracing s Uses of raytracing s Forward Mapping Forward Mapping s Forward mapping is what we are used to. Forward Mapping Forward Mapping Take each primitive s Figure out where on the screen it should appear s Also known is feed­forward s Ray Tracing Ray Tracing s Ray tracing is the “inverse” of the “forward” mapping we are used to. Ray Tracing Ray Tracing s Also known as inverse mapping or feed­ backward Feed­Forward vs. Feed­Forward vs. Feed­Backward s Pros and Cons of each Ray­Tracing Ray­Tracing s s s s 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: – – – – s Reflection Refraction Atmospheric effects Shadows Results in very realistic scenes – Used in movies, animations, cut­ scenes s Center of Projection – Infinite Rays – Care about ones that pass through the virtual screen – For each pixel s s Compute ray to a pixel For each object in the scene – Compute the intersection between ray and object s s s Find closest intersection Calculate illumination Similar to a pinhole camera 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; Computational Cost of Ray Computational Cost of Ray Tracing s s s s s s 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 Triangle Intersection s s s 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 Defining objects We don’t have to use triangles exclusively. s Let’s think about other objects and the different intersections. How would we specify: s – Spheres – Cylinders – Cubes – Other base geometric objects Ray Intersections 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 Ray Intersections We are emulating “reality” where light reaches our eye. s We are asking “what is the path of the light that reached our eye for that pixel?” s Ray Tracing (in the way we know it), was started by Turner Whitted (1980). s With ray tracing, we can solve for global illumination. s Ray Tracing Observations Ray Tracing Observations s s s s s 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 Recursive Ray­Tracing How would we compute lighting? Let’s reverse the light ray that got to our eye s Upon intersection, fire ‘secondary rays’ s Vector to the light Reflected Ray Refraction Ray Upon Intersection Upon Intersection L, shadow ray R T Θr N u s s Θi How do we compute each? Why follow each ray? – Each contributes intensity to the intersection position! R = u − ( 2u • N ) N L, shadow ray R T Θr N u s Θi indices of refraction ηi ηi T = u − cos θ r − cos θ i N ηr ηr ηi cos θ r = 1 − η r 2 1 − cos 2 θ i Ray­Surface Intersection Ray­Surface Intersection s 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 Recursive Ray­Tracing s Shadows Vector to the light Reflected Ray Refraction Ray Recursive Ray­Tracing Recursive Ray­Tracing For each ray, we repeat the process s How many “levels of recursion” should we do? s Vector to the light Refraction Ray Reflected Ray Rercursion Rercursion s s 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 Depth of recursion s s Time vs. Accuracy Tree Data Structure – ray­tracing tree – pg. 599 in book – How deep is the tree? s s What are some end conditions? What are some acceptable end­ limits? Lighting Lighting s s s 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 Lighting s s We’ll cover lighting much more in depth later For now: – Three terms s s s 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 Ray Tracing Pros and Cons Ray Tracing Pros and Cons s Pros Transparency Reflections Shadows Complex Primitives (math equations) – Easy to write – – – – s Cons – Hard to accelerate – Isn’t the complete global illumination – Very slow per pixel calculation. What is slow about Ray What is slow about Ray Tracing? s s s s 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 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 Other Tricks s How would we do – – – – antialiasing texturing transparency different material properties Vector to the light Refraction Ray Reflected Ray Ray Tracing Ray Tracing http://graphics.lcs.mit.edu/classes/6.837 /F98/Lecture20/RayTrace.java s POV­Ray (www.povray.org) s ...
View Full Document

Ask a homework question - tutors are online