Presentation is loading. Please wait.

Presentation is loading. Please wait.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics Part 2 of 2.

Similar presentations


Presentation on theme: "I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics Part 2 of 2."— Presentation transcript:

1 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics Part 2 of 2

2 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 25/42 Normal Vectors at Intersection For illumination we need to find a way, given a point on the object in object-space, to determine the normal vector to the object at that point so that we can calculate angles between the normal and other vectors If a surface bounds a solid whose interior is given by then we can find the normal vector at a point(x, y, z) via the gradient at that point: Recall that the gradient is a vector with three components: Normal vector to implicit surfaces Points (1/4)

3 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 26/42 Normal Vectors at Intersection Sphere normal vector example Points (2/4) For the sphere, the equation is The partial derivatives are So the gradient is Normalize n before using in dot products! In some degenerate cases, the gradient may be zero, and this method fails…use nearby gradient as a cheap hack

4 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 27/42 Normal Vectors at Intersection Transforming back to world-space Points (3/4) We have an object-space normal vector We want a world-space normal vector To transform the object to world coordinates, we just multiplied its vertices by M, the object’s CTM Can we treat the normal vector the same way? Answer: NO Example: say M scales in x by.5 and y by 2 See the normal scaling applets in Applets  Lighting and Shading n object Mn object Wrong! Normal must be perpendicular

5 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 28/42 Normal Vectors at Intersection Points (4/4) Why doesn’t multiplying the normal work? For translation and rotation, which are rigid body transformations, it actually does work Scale, however, distorts the normal in exactly the opposite sense of the scale applied to the surface, not surprising given that the normal is perpendicular -scaling y by 2 causes normal to scale by.5: -We’ll see this algebraically in the next slides

6 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 29/42 Transforming Normals (1/4) Take the polygonal case, for example Let’s compute the relationship between the object-space normal n obj to a polygon H and the world-space normal n world to a transformed version of H, say MH If v is a vector in world space that lies in the polygon (e.g., one of the edge vectors), then the normal is perpendicular to the vector v: But v world is just a transformed version of some vector in object space, v obj. So we could write But we’d be wrong, because v is a tangent vector it’s transformed by the derivative… …which includes a 3D->4D->3D mapping… Object-space to world-space

7 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 30/42 Transforming Normals (2/4) So we want a vector n world such that We will show in a moment that this equation can be rewritten as We also already have Therefore Left-multiplying by (M t ) -1, Object-space to world-space(cont.)

8 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S So how did we rewrite this: As this: Recall that if we think of vector as nx1 matrices, then switching notation, Rewriting the formula above, we have Writing M = M tt, we get Recalling that (AB) t = B t A t, we can write this: Switching back to dot product notation: Andries van Dam, John Alex October 28, 2003 Raytracing 31/42 Transforming Normals (2/4) Object-space to world-space(cont.)

9 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 32/42 Transforming Normals (4/4) So we ended up with Fortunately, “invert” and “transpose” can be swapped, to get our final form: Why do we do this? It’s easier! A hand-waving interpretation of (M 3 -1 ) t -M 3 is a composition of rotations and scales, R and S (why no translates?). Therefore -so we’re applying the transformed (inverted, transposed) versions of each individual matrix in their original order -for a rotation matrix, this transformed version is equal to the original rotation, i.e., normal rotates with object -(R -1 ) t =R; the inverse reverses the rotation, and the transpose reverses it back -for a scale matrix, the inverse reverses the scale, while the transpose does nothing: -(S(x,y,z) -1 ) t = S(x,y,z) -1 =S(1/x,1/y,1/z) Applying inverse-transpose of M to normals

10 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 33/42 Summary P = eyePt For each sample of image Compute d for each object Intersect ray P+td with object Select object with smallest non-negative t-value(this is the visible object) For this object, find the object-space intersection point Compute the normal at that point Transform the normal to world space Use the world-space normal for lighting computations Simple, non-recursive raytracer

11 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 34/42 What about pixels? We’ve used “samples” rather than “pixels” In the simplest case, can choose our sample points at the centers of each pixel For better results, can supersample: take multiple samples per pixel -e.g., at the corners and at the center Even better techniques do adaptive sampling: increase sample density in areas of rapid change (in geometry or lighting) Can also do stochastic sampling: samples are taken probabilistically For fast results, can subsample: fewer samples than pixels take as many samples as time permits How to convert samples to pixels? This is a resampling problem, hence we filter to get weighted average of samples Pixels aren’t samples

12 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 35/42 Recursive Raytracing By recursively casting new rays into the scene, we can look for more information Start from the point of intersection We’d like to send rays in all directions Send rays in directions we predict will contribute the most: -toward lights (shadow) -bounce off objects (specular reflection) -through the object (transparency) For more info on recursive ray tracing, see section 16.12 of the textbook. Simulating global lighting effects (Whitted, 1979)

13 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 36/42 Shadows Each light in scene makes contribution to the color and intensity of a surface element… Iff it reaches the object! -could be occluded by other objects in the scene -could be occluded by another part of the same object Construct a ray from the surface to each light Check to see if ray intersects other objects before it gets to the light -if ray does NOT intersect that same object or another object on its way to the light, then the full contribution of the light can be counted -if ray does intersect an object on its way to the light, then no contribution of that light should be counted -what about transparent objects?

14 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 37/42 Transparent Surfaces (1/2) For a partially transparent polygon Nonrefractive transparency I λ2 I λ1 polygon 1 polygon 2

15 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S We model the way light bends at interfaces with Snell’s Law Andries van Dam, John Alex October 28, 2003 Raytracing 38/42 Transparent Surfaces (2/2) Refractive transparency medium 1 medium 2

16 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 39/42 Recursive Raytracing (1/2) Trace ‘secondary’ rays at intersections: -light: trace ray to each light source. If light source blocked by opaque object, it does not contribute to lighting, and object in shadow of blocked light at that point -specular reflection: trace ray in mirror direction by reflecting about N -refraction/transparency: trace ray in refraction direction by Snell’s law -recursively spawn new light, reflection, refraction rays at each intersection until contribution negligible -Your new lighting equation… -note: intensity from recursed rays calc’d with same eqn -light sources contribute specular and diffuse lighting -Limitations -recursive interobject reflection is strictly specular: along ray reflected about N -diffuse interobject reflection handled by radiosity Informative videos: silent movie on raytracing, A Long Ray’s Journey into Light Recap

17 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 40/42 Recursive Raytracing (2/2) Light-ray Trees indirect illumination

18 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 41/42 Raytracing Pipeline Raytracer produces visible samples from model -samples convolved with filter to form pixel image Additional pre-processing -pre-process database to speed up per-sample calculations (done once, sometimes must be redone if objects transformed (resize, translate)) Pipeline smallest t generate secondary rays

19 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 42/42 POV-Ray: Pretty Pictures Full-featured raytracer available online: http://www.povray.orghttp://www.povray.org Obligatory pretty pictures (see http://www.irtc.org for more!):http://www.irtc.org Free Advanced Raytracer


Download ppt "I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Raytracing Basics Part 2 of 2."

Similar presentations


Ads by Google