270 likes | 413 Views
Image Synthesis. Ray- Tracing – A Quick review. Colored rays. Bouncing rays. 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
E N D
Image Synthesis Ray-Tracing – A Quick review
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 backwardsfrom the eye into the scene
The ray tracing camera • Infinite viewing frustum
Ray tracing • The basicray-tracingmethod • Recursivesearchforpathstothelightsource • Interaction with matter • Point-wiseevaluationof an illumination model • Shadows, reflection, transparency N: surface normals R: reflected rays L: shadow rays T: transmitted rays T2 R2 R3 T1 N2 R1 N3 L3 L2 L1 N1 Point light source Viewpoint
Ray tracing • The basic ray-tracing method
Ray tracing • Recursiveraytraversalresults in a tree-likecomputation order • Depthofrecursioncanbearbitrary • More work in branches but lesscontributiontothe final image due toabsorption • I = Idirect+ ksIreflected+ ktIrefracted • Idirect= Iambiant+ Idiffuse+ Ispecular Viewpoint L1 R1 T1 L2 R2 R3 T2
Ray tracing • The basic ray-tracing program • Define the camera ( Cam(o,d,f,x,y,X,Y) ) • O: point of view • D: viewing direction • f: focal distance (distance to the view plane) • x,y: size of the image plane • Up vector U (orientation of the image plane) • Define the viewport • X,Y: resolution of the viewport (the pixel raster) • Sampling the image plane with at least one ray per pixel
Ray tracing Sampling theimage plane For (eachpixel) { Definetherayfromtheviewpointthroughthatpixel Tracetheraythroughthescene [ computeray-objectintersections recursivelyaccumulateobjectcolorsalongtheray ] Set accumulatedcolorasthepixelcolor }
Ray tracing • Sampling the image plane • A continuous sphere sampling at varying viewport resolution
Ray-object intersections Implicitsurfaces • Implicitequationsimplicitelydefine a setofpoints on thesurfacebytheequation F([x,y,z]T) = 0 • For a possibleintersectionpointit must hold: f(o + td) = 0 • Example:ray-plane(Ax+By+Cz+D = 0) intersection A(ox+tdx)+B(oy+tdy)+C(oz+tdz)+D=0 • t = -(Pn o + D) / (Pn d) Check thedenominatorforray || plane
Ray-object intersections Forimplicitsurfacesthe normal attheintersectionpointisgivenby n = f(p) = ( f(p)/x, f(p)/y, f(p)/z ) Example: sphere (x-cx)2 +(y-cy)2 +(z-cz)2 - R2 = 0 f(p)/x = 2(x-cx) f(p)/y = 2(y-cy) f(p)/z = 2(z-cz) n = 2(p-c), thevectorfromthecentertothepoint
Ray-object intersections Ray-sphere(c,R) intersection • Implicitequationofthesphere (x-cx)2 +(y-cy)2 +(z-cz)2 - R2 = 0, whichisequalto (p-c)(p-c) – R2 = 0 • Withtheparametricray: (o+t d – c) (o+t d – c) – R2 = 0 • (dd)t2 + 2d(o-c)t + (o-c)(o-c) – R2 = 0 • Quadraticequation in t • Discriminantdeterminesthenumberofsolutions
Ray-object intersections Parametricsurfaces • A mappingfromR2(u,v)toR3(x,y,z) x = f(u,v), y = g(u,v), z = h(u,v) A parametricunitsphere: : [0:2pi] Azimuth : [0:pi] Zenith x = cos()*sin() y = sin()*sin() z = cos()
Ray-object intersections Parametricsurfaces • Intersectingtheraywith a parametricsurface ox + t dx = f(u,v) oy + t dy = g(u,v) oz + t dz = h(u,v) -> Yields 3 equationsand 3 unknowns -> solveit -> Mightbecomplicatedfor non-simple f,gand h • The normal isgivenby N(u,v) = (f/u, g/u, h/u) X (f/v, g/v, h/v)
Ray-object intersections Ray-triangleintersection • Given a triangledefinedbythethreepoints A, B and C • Anypointwithinthetrianglecanbedefinedbymeansofbarycentriccoordinatesu,v,w P = uA+vB+wC, withu+v+w=1 andu,v,w> 0 B (u,v,w) Aa Ac P Ab A C
Given a Ray … • … R(t) by ist originoanddirectiondR(t)=o+td • Intersection: (1-u-v)V0+uV1+vV2=O+tD-tD+ uV1-uV0+vV2-vV0=O-V0 [-D,V1-V0, V2-V0][t,u,v]T=O-V0
Geometric Interpretation [-D,V1-V0, V2-V0][t,u,v]T=O-V0
Implementation boolIntersectTriangle( 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 < 0.0f || *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 < 0.0f || *u + *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; returntrue; }
Ray-tracing shadows • 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 • 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)
Ray-tracing shadows • Soft-shadows (Penumbras) • Occur where an area light source is partially occluded
Ray-tracing shadows • Soft-shadows (Penumbras) • Reflectedintensityis proportional tothe solid angle ofthevisibleportionofthelight • Complexcomputation • Distribute multiple shadowraysacrosstheregion • Weightshadowcontributions
Object representation Polygonal approximationofcontinuousobjects
Object representation Polygonal approximationofcontinuousobjects • Approximation ofshapeby polygonal patches • Modellingbyhand, scanning, surfaceevaluation