Download presentation
Presentation is loading. Please wait.
Published byBonnie Craig Modified over 9 years ago
1
computer graphics & visualization Ray-Tracing – A Quick review
2
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Colored rays Ray is a straight path followed by a photon of light Multiple photons can travel along the same ray at the same time Need to know the color of photons hitting the eye along some path Photons originate at some light source and bounce around the geometry in the scene until they are either completely absorbed or hit the eye
3
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Bouncing rays
4
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Forward or backward Tracing photons out from each light source would lead to an excellent picture of the scene But most photons will never hit the eye We want to know what photons certainly contribute to the image If we consider a pixel on the image plane, we know where photons hitting that pixel must be coming from Therefore, we trace rays backwards from the eye into the scene
5
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group The ray tracing camera Infinite viewing frustum Infinite viewing frustum
6
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray tracing The basic ray-tracing method The basic ray-tracing method – Recursive search for paths to the light source Interaction with matter Interaction with matter Point-wise evaluation of an illumination model Point-wise evaluation of an illumination model Shadows, reflection, transparency Shadows, reflection, transparency Viewpoint Point light source R2R2 R1R1 R3R3 N2N2 N1N1 N3N3 T1T1 T2T2 L2L2 L1L1 L3L3 N: surface normals R: reflected rays L: shadow rays T: transmitted rays
7
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray tracing The basic ray-tracing method The basic ray-tracing method
8
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray tracing Recursive ray traversal results in a tree-like computation order Recursive ray traversal results in a tree-like computation order – Depth of recursion can be arbitrary – More work in branches but less contribution to the final image due to absorption – I = I direct + k s I reflected + k t I refracted – I direct = I ambiant + I diffuse + I specular Viewpoint L1L1 L2L2 R1R1 T1T1 R2R2 R3R3 T2T2
9
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray tracing The basic ray-tracing program The basic ray-tracing program – Define the camera ( Cam(o,d,f,x,y,X,Y) ) O: point of view O: point of view D: viewing direction D: viewing direction f: focal distance (distance to the view plane) f: focal distance (distance to the view plane) x,y: size of the image plane x,y: size of the image plane Up vector U (orientation of the image plane) Up vector U (orientation of the image plane) – Define the viewport X,Y: resolution of the viewport (the pixel raster) X,Y: resolution of the viewport (the pixel raster) – Sampling the image plane with at least one ray per pixel
10
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray tracing Sampling the image plane For (each pixel ) { Define the ray from the viewpoint through that pixel Trace the ray through the scene [ compute ray-object intersections recursively accumulate object colors along the ray ] Set accumulated color as the pixel color }
11
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray tracing Sampling the image plane Sampling the image plane – A continuous sphere sampling at varying viewport resolution
12
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-object intersections Implicit surfaces – Implicit equations implicitely define a set of points on the surface by the equation F([x,y,z] T ) = 0 – For a possible intersection point it must hold: f(o + td) = 0 – Example: ray-plane(Ax+By+Cz+D = 0) intersection A(o x +td x )+B(o y +td y )+C(o z +td z )+D=0 t = -(P n o + D) / (P n d) Check the denominator for ray || plane
13
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-object intersections For implicit surfaces the normal at the intersection point is given by n = f(p) = ( f(p)/ x, f(p)/ y, f(p)/ z ) n = f(p) = ( f(p)/ x, f(p)/ y, f(p)/ z ) Example: sphere (x-c x ) 2 +(y-c y ) 2 +(z-c z ) 2 - R 2 = 0 f(p)/ x = 2(x-c x ) f(p)/ y = 2(y-c y ) f(p)/ z = 2(z-c z ) n = 2(p-c), the vector from the center to the point
14
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-object intersections Ray-sphere(c,R) intersection – Implicit equation of the sphere (x-c x ) 2 +(y-c y ) 2 +(z-c z ) 2 - R 2 = 0, which is equal to (p-c)(p-c) – R 2 = 0 – With the parametric ray: (o+t d – c) (o+t d – c) – R 2 = 0 (dd)t 2 + 2d(o-c)t + (o-c)(o-c) – R 2 = 0 Quadratic equation in t Discriminant determines the number of solutions
15
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-object intersections Parametric surfaces – A mapping from R 2 (u,v) to R 3 (x,y,z) x = f(u,v), y = g(u,v), z = h(u,v) A parametric unit sphere: : [0:2pi]Azimuth : [0:pi]Zenith x = cos( )*sin( ) y = sin( )*sin( ) z = cos( )
16
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-object intersections Parametric surfaces – Intersecting the ray with a parametric surface o x + t d x = f(u,v) o y + t d y = g(u,v) o z + t d z = h(u,v) -> Yields 3 equations and 3 unknowns -> solve it -> Might be complicated for non-simple f,g and h – The normal is given by N(u,v) = ( f/ u, g/ u, h/ u) X ( f/ v, g/ v, h/ v)
17
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-object intersections Ray-triangle intersection – Given a triangle defined by the three points A, B and C – Any point within the triangle can be defined by means of barycentric coordinates u,v,w P = uA+vB+wC, with u+v+w=1 and u,v,w > 0 P B A C (u,v,w) AaAa AbAb AcAc
18
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Given a Ray … … R(t) by ist origin o and direction d R(t)=o+td … R(t) by ist origin o and direction d R(t)=o+td Intersection: (1-u-v)V 0 +uV 1 +vV 2 =O+tD -tD+ uV 1 -uV 0 +vV 2 -vV 0 =O-V 0 [-D,V 1 -V 0, V 2 -V 0 ][t,u,v] T =O-V 0 Intersection: (1-u-v)V 0 +uV 1 +vV 2 =O+tD -tD+ uV 1 -uV 0 +vV 2 -vV 0 =O-V 0 [-D,V 1 -V 0, V 2 -V 0 ][t,u,v] T =O-V 0
19
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Geometric Interpretation [-D,V 1 -V 0, V 2 -V 0 ][t,u,v] T =O-V 0
20
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Solving the System of Equations
21
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Implementation bool IntersectTriangle( const VECTOR3& orig, const VECTOR3& dir, VECTOR3& v0, VECTOR3& v1, VECTOR3& v2, float* t, float* u, float* v ) { // Find vectors for two edges sharing vert0 VECTOR3 edge1 = v1 - v0; VECTOR3 edge2 = v2 - v0; // Begin calculating determinant - also used to calculate U parameter VECTOR3 pvec; Cross( &pvec, &dir, &edge2 ); // If determinant is near zero, ray lies in plane of triangle float det = Dot( &edge1, &pvec ); VECTOR3 tvec; if( det > 0 ) tvec = orig - v0; else { tvec = v0 - orig; det = -det; } if( det < 0.0001f ) return false; // Calculate U parameter and test bounds *u = Dot( &tvec, &pvec ); if( *u det ) return false; // Prepare to test V parameter VECTOR3 qvec; Cross( &qvec, &tvec, &edge1 ); // Calculate V parameter and test bounds *v = Dot( &dir, &qvec ); if( *v det ) return false; // Calculate t, scale parameters, ray intersects triangle *t = Dot( &edge2, &qvec ); float fInvDet = 1.0f / det; *t *= fInvDet; *u *= fInvDet; *v *= fInvDet; return true; }
22
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-tracing shadows Shadow rays Shadow rays – For each ray-object intersection cast a ray toward the light sources – Check for intersections in-between object and light source Take care of finite-precision arithmetic Take care of finite-precision arithmetic Shadow ray might intersect object it originates from at t = Shadow ray might intersect object it originates from at t = – Acceleration by means of pre-computed shadow maps or shadow volumes (to be discussed later)
23
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-tracing shadows Soft-shadows (Penumbras) Soft-shadows (Penumbras) – Occur where an area light source is partially occluded
24
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Ray-tracing shadows Soft-shadows (Penumbras) Soft-shadows (Penumbras) – Reflected intensity is proportional to the solid angle of the visible portion of the light Complex computation Complex computation – Distribute multiple shadow rays across the region – Weight shadow contributions
25
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Object representation Polygonal approximation of continuous objects
26
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Object representation Polygonal approximation of continuous objects – Approximation of shape by polygonal patches – Modelling by hand, scanning, surface evaluation
27
computer graphics & visualization Image Synthesis – WS 07/08 Dr. Jens Krüger – Computer Graphics and Visualization Group Object representation For display we need: The objects shapeThe objects shape i.e. geometric representation including normali.e. geometric representation including normal 3D Object coordinates (vertices)3D Object coordinates (vertices) 3D normal vectors3D normal vectors Topology (connectivity information)Topology (connectivity information) The objects appearanceThe objects appearance i.e. material properties like color reflection, texture etc.i.e. material properties like color reflection, texture etc.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.