Looking Back at Image Formation Light is a stream of photons which move in straight lines propagating from lights we ignore wave nature of light Some rays strike the eye passing through image plane these rays form the image Light interacts with surfaces objects absorb some light reflect some of the light may bounce off many objects Incident light Reflected light Some reaches eye Some light is absorbed Simulating Rays of Light in the World We can render the scene by simulating physical light transport we hope that this produces more realistic results Simulation would look like this light source shoots rays in all directions rays bounce when they hit surfaces can ignore rays when they fly off into empty space almost all of their energy is absorbed record rays that strike the image plane we call this kind of simulation forward ray tracing But there s a big problem with this it can be extremely slow only a tiny fraction of light rays actually strike the eye 1 Backward Ray Tracing Fortunately there s a simple solution to this problem we only care about light rays that eventually strike the eye so shoot rays from the eye out into the world just reverse arrows on the ray diagram Traditionally most ray based renderers take this approach so we usually drop the backward from the name but keep in mind there are alternatives that don t Ray Casting Simple Ray Based Rendering We can formulate a very simple rendering algorithm we ll ignore all this business about rays bouncing around just shoot rays into world see what they strike and shade Ray Casting Algorithm for all pixels x y compute ray from eye through x y compute intersections with all surfaces find surface with closest intersection shade this surface point standard illumination equation write this color into pixel x y What we need to resolve how to represent rays generate rays through screen how to compute intersections with objects in the world 2 Representing Light Rays Geometrically a ray is just a starting point plus a direction the set of all points described by d x t p td where t 0 direction of ray implementation tip make sure d is unit vector p the origin of the ray Each ray will return some amount of light from the world for implementation purposes an RGB color Computing Ray Surface Intersections We start with an equation of our ray x t p td General idea write equation for point on both ray surface for an implicit surface f x 0 substitute ray equation f p td 0 for a parametric surface x h u v find location where distance between ray and surface is 0 h u v p td 0 in general both approaches can require expensive root finding 3 Ray Plane Intersection For specific surfaces can derive more efficient methods We start with the equation for the plane n x D 0 Then substitute the ray equation into it and solve for t n p td D 0 n p tn d D 0 n p D t n d To find the actual intersection point of the ray with the plane substitute the computed value of t back into the ray equation Ray Polygon Intersection First find the intersection of the ray and the polygon s plane we just need to determine whether this point is in the polygon there are many approaches to point in polygon testing For efficiency typically project to 2 D for plane computations there are several ways to do this but one of the cheapest is find component of plane normal A B C with largest magnitude drop corresponding coordinate i e A is largest drop x this works because A is proportional to projection on yz plane in other words the polygon is mostly facing the yz plane our goal in these computations minimize number of operations 4 Point in Polygon Test for Convex Polygons For general convex polygons we can use half space tests construct lines through each edge of the polygon just as with Cohen Sutherland clipping must make sure that normals are consistently oriented either they all point in or they all point out the point x y is in the polygon if ai x bi y ci all have same sign Note that this also works in 3 D construct planes through each edge perpendicular to polygon plane point must lie on inside of all of them Point in Triangle Tests With triangles can make good use of barycentric coordinates all points in triangle satisfy equation p2 p p0 p1 p 2 where 1 query point pc these coefficients are triangle area ratios Area pc p1 p 2 Area p0 p1 p 2 Area pc p 2 p0 Area p0 p1 p 2 Area pc p0 p1 1 Area p0 p1 p 2 p0 p1 5 Point in Triangle Test We can compute the 2 D area of a triangle as x0 1 Area p0 p1 p 2 y0 2 1 x1 y1 1 x2 x x0 y2 y0 x 2 x0 y1 y0 y2 1 2 1 note this is the signed area of the triangle it s positive if points are in counter clockwise order and negative if they re in clockwise order So to figure out if a given point is in the triangle compute it s three barycentric coordinates point is inside the triangle exactly when 0 note that this can also be made to work directly in 3 D Ray Sphere Intersection Consider a sphere centered at the origin x 2 y2 z 2 r 2 x x r 2 0 We substitute the ray equation p td p td r 2 0 p p 2tp d t 2 d d r 2 0 Which gives us a quadratic equation in t At 2 Bt C 0 where A d d 1 d is unit vector B 2p d C p p r2 6 Ray Sphere Intersection We can directly solve this quadratic equation At 2 Bt C 0 where A d d 1 d is unit vector B 2p d t2 C p p r2 For the two intersection locations t1 B B 2 4C 2 t2 B B 2 4C 2 t1 the smaller non negative one is the closest ray intersection a negative discriminant means that the ray missed the sphere Ray Quadric Intersection Implicit surfaces of the form x T Qx x a b y z 1 c d b e f g c f h i d x g y 0 i z j 1 Substituting the ray equation p td T Q p td d T Qd t 2 2d T Qp t p T Qp 0 Gives us a quadratic polynomial in t 7 The Geometry of Screen Space Mcamera Mpersp World Space z z Screen Space M world screen Mpersp Mcamera Generating Eye Rays Need to construct ray from eye through each pixel Start with screen space coordinates pixel q s x y 0 1 eye p s 0 0 1 0 1 Transform them to world space q w Mscreen world q s p …
View Full Document
Unlocking...