1 and surrounding medium eye through each pixel flexible
play

1 and surrounding medium eye through each pixel flexible, easy - PowerPoint PPT Presentation

University of British Columbia Reading for This Module Global Illumination Models CPSC 314 Computer Graphics simple lighting/shading methods simulate FCG Sec 8.2.7 Shading Frequency Jan-Apr 2013 local illumination models FCG Chap 4


  1. University of British Columbia Reading for This Module Global Illumination Models CPSC 314 Computer Graphics • simple lighting/shading methods simulate • FCG Sec 8.2.7 Shading Frequency Jan-Apr 2013 local illumination models • FCG Chap 4 Ray Tracing • no object-object interaction Tamara Munzner • FCG Sec 13.1 Transparency and Refraction • global illumination models Advanced Rendering • more realism, more computation • Optional: FCG Chap 24 Global Illumination • leaving the pipeline for these two lectures! • approaches Advanced Rendering • ray tracing • radiosity • photon mapping http://www.ugrad.cs.ubc.ca/~cs314/Vjan2013 • subsurface scattering 2 3 4 Ray Tracing Simple Ray Tracing Reflection Refraction n d n • simple basic algorithm • view dependent method • mirror effects • happens at interface between transparent object • perfect specular reflection • well-suited for software rendering • cast a ray from viewer’s θ θ θ 1 and surrounding medium eye through each pixel • flexible, easy to incorporate new effects • e.g. glass/air boundary θ 2 • compute intersection of t • Turner Whitted, 1990 ray with first object in • Snell ’ s Law scene • c sin c sin pixel positions θ = θ • cast ray from 1 1 2 2 on projection • light ray bends based on projection intersection point on plane reference refractive indices c 1 , c 2 point object to light sources 5 6 7 8 Recursive Ray Tracing Basic Algorithm Basic Ray Tracing Algorithm Algorithm Termination Criteria • ray tracing can handle • termination criteria RayTrace (r,scene) • reflection (chrome/mirror) for every pixel p i { obj := FirstIntersection (r,scene) • no intersection • refraction (glass) generate ray r from camera position through pixel p i if (no obj) return BackgroundColor; • shadows • reach maximal depth else begin for every object o in scene { • spawn secondary rays if ( Reflect (obj) ) then • number of bounces if ( r intersects o ) reflect_color := RayTrace ( ReflectRay (r,obj)); • reflection, refraction compute lighting at intersection point, using local • contribution of secondary ray attenuated else • if another object is hit, normal and material properties; store result in p i below threshold reflect_color := Black; recurse to find its color pixel positions else if ( Transparent (obj) ) then • each reflection/refraction attenuates ray • shadow on projection projection p i = background color refract_color := RayTrace ( RefractRay (r,obj)); plane • cast ray from intersection reference else } point point to light source, check refract_color := Black; if intersects another object } return Shade (reflect_color,refract_color,obj); end; 9 10 11 12 Ray Tracing Algorithm Ray-Tracing Terminology Ray Trees Ray Tracing • all rays directly or indirectly spawned off by a single • terminology: • issues: primary ray Light Eye Image Plane • primary ray: ray starting at camera • generation of rays Source • shadow ray • intersection of rays with geometric primitives • reflected/refracted ray • geometric transformations Shadow Reflected Rays Ray • ray tree: all rays directly or indirectly spawned • lighting and shading off by a single primary ray • efficient data structures so we don’t have to • note: test intersection with every object • need to limit maximum depth of ray tree to ensure termination of ray-tracing process! Refracted Ray 13 14 www.cs.virginia.edu/~gfx/Courses/2003/Intro.fall.03/slides/lighting_web/lighting.pdf 15 16

  2. Ray Generation Ray Generation Ray Generation Ray Tracing • camera coordinate system • other parameters: • ray in 3D space: • issues: u • distance of camera from image plane: d • origin: C (camera position) • generation of rays • image resolution (in pixels): w, h R ( t ) C t ( P C ) C t v • viewing direction: v = + ⋅ − = + ⋅ • intersection of rays with geometric primitives u v i , j i , j i , j • left, right, top, bottom boundaries C • up vector: u • geometric transformations x in image plane: l , r, t, b • x direction: x= v × u • lighting and shading • then: where t= 0… ∞ v • note: O C d v l x b u • efficient data structures so we don’t have to • lower left corner of image: = + ⋅ + ⋅ + ⋅ C x test intersection with every object • pixel at position i, j ( i=0..w-1, j=0..h-1 ) : • corresponds to viewing r l t b transformation in rendering pipeline − − P j O i x j u = + ⋅ ⋅ − ⋅ ⋅ i , w 1 h 1 • like gluLookAt − − O i x x j y y = + ⋅ Δ ⋅ − ⋅ Δ ⋅ 17 18 19 20 Ray - Object Intersections Ray Intersections: Spheres Ray Intersections: Spheres Ray Intersections: Other Primitives • implicit functions • inner loop of ray-tracing • spheres at origin • to determine intersection: • spheres at arbitrary positions • must be extremely efficient • implicit function • insert ray R i,j ( t ) into S(x,y,z): • same thing • task: given an object o, find ray parameter t , such that R i,j ( t ) • conic sections (hyperboloids, ellipsoids, paraboloids, cones, is a point on the object cylinders) S ( x , y , z ) : x 2 y 2 z 2 r 2 2 2 2 2 + + = ( c t v ) ( c t v ) ( c t v ) r • such a value for t may not exist + ⋅ + + ⋅ + + ⋅ = x x y y z z • same thing (all are quadratic functions!) • solve a set of equations • polygons • ray equation • solve for t (find roots) • intersection test depends on geometric primitive • first intersect ray with plane c v c t v • simple quadratic equation • linear implicit function • ray-sphere & # & # & + ⋅ # x x x x $ ! $ ! $ ! • then test whether point is inside or outside of polygon (2D test) • ray-triangle R ( t ) C t v c t v c t v = + ⋅ = + ⋅ = + ⋅ $ ! $ ! $ ! • for convex polygons i , j i , j y y y y • ray-polygon $ ! $ ! $ ! • suffices to test whether point in on the correct side of every c v c t v + ⋅ % " % " % " z z z z boundary edge • similar to computation of outcodes in line clipping (upcoming) 21 22 23 24 Ray-Triangle Intersection Ray-Triangle Intersection Ray Tracing Geometric Transformations • method in book is elegant but a bit complex • check if ray inside triangle • issues: • similar goal as in rendering pipeline: • check if point counterclockwise from each edge (to • easier approach: triangle is just a polygon • modeling scenes more convenient using different • generation of rays its left) coordinate systems for individual objects • intersect ray with plane • intersection of rays with geometric primitives • check if cross product points in same direction as • problem normal (i.e. if dot is positive) normal: n = ( b − a ) × ( c − a ) • geometric transformations e • not all object representations are easy to transform c ray : x = e + t d • lighting and shading ( b − a ) × ( x − a ) ⋅ n ≥ 0 • problem is fixed in rendering pipeline by restriction to d c plane : ( p − x ) ⋅ n = 0 ⇒ x = p ⋅ n polygons, which are affine invariant n • efficient data structures so we don’t have to n (c − b) × (x − b) ⋅ n ≥ 0 n CCW x • ray tracing has different solution a test intersection with every object x a (a − c) × (x − c) ⋅ n ≥ 0 p ⋅ n = e + t d ⇒ t = − ( e − p ) ⋅ n • ray itself is always affine invariant b • thus: transform ray into object coordinates! n d ⋅ n b p is a or b or c • more details at http://www.cs.cornell.edu/courses/cs465/2003fa/homeworks/raytri.pdf • check if ray inside triangle 25 26 27 28 Geometric Transformations Ray Tracing Local Lighting Local Lighting • local surface information • ray transformation • issues: • local surface information (normal … ) • alternatively: can interpolate per-vertex • for intersection test, it is only important that ray is in • generation of rays • for implicit surfaces F ( x,y,z ) =0: normal n ( x,y,z ) same coordinate system as object representation information for triangles/meshes as in can be easily computed at every intersection • intersection of rays with geometric primitives rendering pipeline • transform all rays into object coordinates point using the gradient • geometric transformations • now easy to use Phong shading! • transform camera point and ray direction by inverse of F ( x , y , z ) / x ∂ ∂ & # model/view matrix • lighting and shading $ ! • as discussed for rendering pipeline n ( x , y , z ) F ( x , y , z ) / y = ∂ ∂ $ ! • shading has to be done in world coordinates (where • difference with rendering pipeline: • efficient data structures so we don’t have to $ ! F ( x , y , z ) / z ∂ ∂ light sources are given) % " • interpolation cannot be done incrementally test intersection with every object 2 2 2 2 F ( x , y , z ) x y z r = + + − • transform object space intersection point to world • have to compute barycentric coordinates for • example: coordinates 2 x & # every intersection point (e.g plane equation for $ ! • thus have to keep both world and object-space ray triangles) n ( x , y , z ) 2 y = needs to be normalized! $ ! $ ! 2 z % " 29 30 31 32

Recommend


More recommend