Download presentation

Presentation is loading. Please wait.

1
Ray Tracing

2
**Ray Tracing What is ray tracing? Trace the path of a ray of light.**

Model its interactions with the scene. When a ray intersects an object, send off secondary rays (reflection, shadow, transmission) and determine how they interact with the scene.

3
**Ray Tracing Capabilities**

Basic algorithm allows for: Hidden surface removal (like z-buffering) Multiple light sources Reflections Transparent refractions Hard shadows Extensions can achieve: Soft shadows Motion blur Blurred reflections (glossiness) Depth of field (finite apertures) Translucent refractions and more

4
**Ray Tracing Produces realistic images Strengths: Weaknesses:**

Specular reflections Transparency Weaknesses: colour bleeding (diffuse reflections) Time consuming References: “An Improved Illumination Model for Shaded Display,” Turner Whitted, CACM, June 1980. “Distributed Ray Tracing,” Cook, Porter, and Carpenter, Computer Graphics, July 1984, pp Green, S.A., Paddon, D.J. Exploiting Coherence for “Multiprocessor Ray Tracing”. IEEE Computer Graphics Journal, 9,6, Nov 1989, pp

5
Ray Traced Images

7
**Ray Tracing “Backward” ray tracing:**

Traces the ray forward (in time) from the light source through potentially many scene interactions Problem: most rays will never even get close to the eye Very inefficient since it computes many rays that are never seen Light Eye Image plane

8
**Ray Tracing “Forward” ray tracing:**

Traces the ray backward (in time) from the eye, through a point on the screen More efficient: computes only visible rays (since we start at eye) Generally, ray tracing refers to forward ray tracing. Light Eye Image plane

9
Ray Tracing Ray tracing is an image- precision algorithm: Visibility determined on a per-pixel basis Trace one (or more) rays per pixel Compute closest object (triangle, sphere, etc.) for each ray Produces realistic results Computationally expensive

10
Minimal Ray Tracer A basic (minimal) ray tracer is simple to implement: The code can even fit on a 3×5 card (code courtesy of Paul Heckbert): typedef struct{double x,y,z}vec;vec U,black,amb={.02,.02,.02};struct sphere{ vec cen,colour;double rad,kd,ks,kt,kl,ir}*s,*best,sph[]={0.,6.,.5,1.,1.,1.,.9, .05,.2,.85,0.,1.7,-1.,8.,-.5,1.,.5,.2,1.,.7,.3,0.,.05,1.2,1.,8.,-.5,.1,.8,.8, 1.,.3,.7,0.,0.,1.2,3.,-6.,15.,1.,.8,1.,7.,0.,0.,0.,.6,1.5,-3.,-3.,12.,.8,1., 1.,5.,0.,0.,0.,.5,1.5,};yx;double u,b,tmin,sqrt(),tan();double vdot(A,B)vec A ,B;{return A.x*B.x+A.y*B.y+A.z*B.z;}vec vcomb(a,A,B)double a;vec A,B;{B.x+=a* A.x;B.y+=a*A.y;B.z+=a*A.z;return B;}vec vunit(A)vec A;{return vcomb(1./sqrt( vdot(A,A)),A,black);}struct sphere*intersect(P,D)vec P,D;{best=0;tmin=1e30;s= sph+5;while(s-->sph)b=vdot(D,U=vcomb(-1.,P,s->cen)),u=b*b-vdot(U,U)+s->rad*s ->rad,u=u>0?sqrt(u):1e31,u=b-u>1e-7?b-u:b+u,tmin=u>=1e-7&&u<tmin?best=s,u: tmin;return best;}vec trace(level,P,D)vec P,D;{double d,eta,e;vec N,colour; struct sphere*s,*l;if(!level--)return black;if(s=intersect(P,D));else return amb;colour=amb;eta=s->ir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen )));if(d<0)N=vcomb(-1.,N,black),eta=1/eta,d= -d;l=sph+5;while(l-->sph)if((e=l ->kl*vdot(N,U=vunit(vcomb(-1.,P,l->cen))))>0&&intersect(P,U)==l)colour=vcomb(e ,l->colour,colour);U=s->colour;colour.x*=U.x;colour.y*=U.y;colour.z*=U.z;e=1-eta* eta*(1-d*d);return vcomb(s->kt,e>0?trace(level,P,vcomb(eta,D,vcomb(eta*d-sqrt (e),N,black))):black,vcomb(s->ks,trace(level,P,vcomb(2*d,N,D)),vcomb(s->kd, colour,vcomb(s->kl,U,black))));}main(){puts(“P3\n32 32\n255”);while(yx<32*32) U.x=yx%32-32/2,U.z=32/2-yx++/32,U.y=32/2/tan(25/ ),U=vcomb(255., trace(3,black,vunit(U)),black),printf("%.0f %.0f %.0f\n",U);}/*minray!*/

11
**Minimal Ray Tracer This code implements: Multiple spheres (with**

different properties) Multiple levels of recursion: Reflections Transparency: Refraction One point light source: Hard shadows Hidden surface removal Phong illumination model typedef struct{double x,y,z}vec;vec U,black,amb={.02,.02,.02};struct sphere{ vec cen,colour;double rad,kd,ks,kt,kl,ir}*s,*best,sph[]={0.,6.,.5,1.,1.,1.,.9, .05,.2,.85,0.,1.7,-1.,8.,-.5,1.,.5,.2,1.,.7,.3,0.,.05,1.2,1.,8.,-.5,.1,.8,.8, 1.,.3,.7,0.,0.,1.2,3.,-6.,15.,1.,.8,1.,7.,0.,0.,0.,.6,1.5,-3.,-3.,12.,.8,1., 1.,5.,0.,0.,0.,.5,1.5,};yx;double u,b,tmin,sqrt(),tan();double vdot(A,B)vec A ,B;{return A.x*B.x+A.y*B.y+A.z*B.z;}vec vcomb(a,A,B)double a;vec A,B;{B.x+=a* A.x;B.y+=a*A.y;B.z+=a*A.z;return B;}vec vunit(A)vec A;{return vcomb(1./sqrt( vdot(A,A)),A,black);}struct sphere*intersect(P,D)vec P,D;{best=0;tmin=1e30;s= sph+5;while(s-->sph)b=vdot(D,U=vcomb(-1.,P,s->cen)),u=b*b-vdot(U,U)+s->rad*s ->rad,u=u>0?sqrt(u):1e31,u=b-u>1e-7?b-u:b+u,tmin=u>=1e-7&&u<tmin?best=s,u: tmin;return best;}vec trace(level,P,D)vec P,D;{double d,eta,e;vec N,colour; struct sphere*s,*l;if(!level--)return black;if(s=intersect(P,D));else return amb;colour=amb;eta=s->ir;d= -vdot(D,N=vunit(vcomb(-1.,P=vcomb(tmin,D,P),s->cen )));if(d<0)N=vcomb(-1.,N,black),eta=1/eta,d= -d;l=sph+5;while(l-->sph)if((e=l ->kl*vdot(N,U=vunit(vcomb(-1.,P,l->cen))))>0&&intersect(P,U)==l)colour=vcomb(e ,l->colour,colour);U=s->colour;colour.x*=U.x;colour.y*=U.y;colour.z*=U.z;e=1-eta* eta*(1-d*d);return vcomb(s->kt,e>0?trace(level,P,vcomb(eta,D,vcomb(eta*d-sqrt (e),N,black))):black,vcomb(s->ks,trace(level,P,vcomb(2*d,N,D)),vcomb(s->kd, colour,vcomb(s->kl,U,black))));}main(){puts(“P3\n32 32\n255”);while(yx<32*32) U.x=yx%32-32/2,U.z=32/2-yx++/32,U.y=32/2/tan(25/ ),U=vcomb(255., trace(3,black,vunit(U)),black),printf("%.0f %.0f %.0f\n",U);}/*minray!*/

12
**Ray Tracing: Types of Rays**

Primary rays: Sent from the eye, through the image plane, and into the scene May or may not intersect an object in the scene. No intersection: set pixel to background colour Intersects object: send out secondary rays and compute lighting model Light Opaque object Transparent object P1 P2 Eye

13
**Ray Tracing: Types of Rays**

Secondary Rays: Sent from the point at which the ray intersects an object Multiple types: Light Transmission (T): sent in the direction of refraction S3 S2 T2 R2 Reflection (R): sent in the direction of reflection, and used in the Phong illumination model S1 T1 R3 R1 Opaque object Transparent object Shadow (S): sent toward a light source to determine if point is in shadow or not. P Eye

14
**Ray Tracing: Types of Rays**

Light P = Primary rays R = Reflected rays T = Transmitted rays S = Shadow rays S2 S3 R2 T2 S1 T1 R1 R3 Opaque object Transparent object P Eye

15
**Ray Tracing: Ray Tree Each intersection may spawn secondary rays:**

Rays form a ray tree. Nodes are the intersection points. Edges are the secondary rays. Rays are recursively spawned until: Ray does not intersect any object. Tree reaches a maximum depth. Light reaches some minimum value. Shadow rays are sent from every intersection point (to determine if point is in shadow), but they do not spawn additional rays.

16
**Note only ambient shade on mirror and teapot**

Test Scene. Ray tree depth 1. Note only ambient shade on mirror and teapot 28/03/2017

17
**Note only ambient shade on reflection of mirror and teapot.**

Test Scene. Ray tree depth 2. Note only ambient shade on reflection of mirror and teapot. 28/03/2017

18
**Note only ambient shade on reflection of mirror in teapot.**

Test Scene. Ray tree depth 3. Note only ambient shade on reflection of mirror in teapot. 28/03/2017

19
**Test Scene. Ray tree depth 4.**

Note ambient shade on reflection of teapot in reflection of mirror in teapot. 28/03/2017

20
Test Scene. Ray tree depth 5. 28/03/2017

21
Test Scene. Ray tree depth 6. 28/03/2017

22
Test Scene. Ray tree depth 7. 28/03/2017

23
**Ray Tracing: Ray Tree Example**

Eye P O1 Light S3 S2 O3 T2 R2 R1 T1 O1 O2 S1 T1 O2 R3 R1 O1 Opaque object R2 BG R3 T2 O1 BG Transparent object P Eye Ray tree is evaluated from bottom up: Depth-first traversal The node colour is computed based on its children’s colours.

24
**Basic Ray Tracing Algorithm**

Generate one ray per pixel. For each ray: Find the first object the ray intersects. Compute colour for the intersection point using an illumination model. If the surface is reflective, trace a reflection ray. If the surface is transparent, trace a transmission ray. Trace shadow ray. Combine results of the intensity computation, reflection, transmission, and shadow information. If the ray misses all objects, set to the background colour.

25
**Tracing Rays Basic (non-recursive) ray tracing algorithm:**

1. Send a ray from the eye through the screen 2. Determine which object that ray first intersects 3. Compute pixel colour Most (approx. 75%) of the time in step 2: Simple method: Compare every ray against every object and determine the closest object hit by each ray. Very time consuming: Several optimizations possible.

26
**Viewing Ray Which coordinate space?**

The primary ray (or viewing ray) for a point s on the view plane (i.e., screen) is computed as: Origin: ro = eye Direction: rd = s – eye Which coordinate space? Want to define rays in terms world-space coordinates (x, y, z) Eye is already in specified in terms of (x, y, z) position Screen point s is easiest to define in terms of where it is on the window in viewing- space coordinates (u, v, w) s rd = s – ro ro = eye Window

27
**Viewing Ray: Screen Point**

Given: Our scene in world-coordinates A camera position in world-coordinates (x, y, z) A pixel (i, j) in the viewport We need to: Compute the point on the view plane window that corresponds to the (i, j) point in the viewport Transform that point into world-coordinates

28
**View-reference coordinates**

y LookAt point LookFrom point w x u z World coordinates View reference coordinates

29
**Transform the Ray pWS = M pOS pOS = M-1 pWS World Space Object Space**

Move the ray from World Space to Object Space r minor r major (x,y) r = 1 World Space (0,0) Object Space pWS = M pOS pOS = M-1 pWS

30
**Transform Ray World Space Object Space New origin: New direction:**

originOS = M-1 originWS directionOS = M-1 (originWS + 1 * directionWS) M-1 originWS directionOS = M-1 directionWS originWS directionWS qWS = originWS + tWS * directionWS originOS directionOS qOS = originOS + tOS * directionOS World Space Object Space

31
**What to do about the depth, t**

If M includes scaling, directionOS ends up NOT being normalized after transformation Two solutions: Normalize the direction Don't normalize the direction

32
**Don't normalize direction**

Highly recommended Don't normalize direction tOS = tWS convenient! But you should not rely on tOS being true distance during intersection routines tWS tOS World Space Object Space

33
**View-reference to World transform**

Given the screen point in terms of viewing- space coordinates (u, v, w), transform to world-space (x, y, z): The viewing transform takes a point from world space to view space (change of basis, CoB): y v s w Window u x z

34
**View-reference to World transform**

Given the screen point in terms of viewing-space coordinates (u, v, w), transform to world-space (x, y, z): We want to reverse this: y v s w Window u x z or sWorld = LookAt + usu + vsv + wsw

35
**Ray/Object intersection**

Can intersect ray with many objects Planes, Spheres, Cylinders, Cones Boxes (axis-aligned or otherwise) Even procedural/implicit objects! Constructive solid geometry (CSG) Implicit surfaces / equations

36
**Remember: Ray Representation**

A ray can be represented explicitly (in parametric form) as an origin (point) and a direction (vector): Origin: Direction The ray consists of all points: r(t) = ro + rdt

37
**Ray-Object Intersections**

Many objects can be represented as implicit surfaces: Sphere (with center at c and radius R): fs (p) = ||p – c||2 - R2 = 0 Plane (with normal n and distance to origin d): fp (p) = p · n + D = 0 To determine where a ray intersects an object: Plug the ray equation into the surface equation and solve for t: f(ro + rdt) = 0 Substitute t back into ray equation to find intersection point p: p = r(t) = ro + rdt

38
**Ray-Sphere Intersections**

To find the intersection points of a ray with a sphere: Sphere is represented as: center: c = (xc, yc, zc) radius: R The sphere is the set of all points (x, y, z) such that: (x-xc)2 + (y - yc)2 + (z - zc)2 = R2

39
**Ray-Sphere Intersections**

First, split the ray into its component equations: x = xo + xdt y = yo + ydt z = zo + zdt Then substitute the ray equation into the sphere equation: (x-xc)2 + (y - yc)2 + (z - zc)2 = R2 Giving: (xo + xdt - xc)2 + (yo + ydt - yc)2 + (zo + zdt - zc)2 = R2

40
**Ray-Sphere Intersections**

Next multiply out the squared terms: (x0 + xdt - xc)2 + (y0 + ydt - yc)2 + (z0 + zdt - zc)2 = R2 Þ (xd2 + yd2 + zd2)t2 + 2(xdxo - xdxc+ ydyo - ydyc+ zdzo - zdzc)t + (xo2- 2xoxc+ xc2+ yo2- 2yoyc+ yc2+ zo2-2zozc+ zc2) = R2 How do we solve for t? Use the Quadratic Equation

41
**Ray-Sphere Intersections**

Let A = xd2 + yd2 + zd2 = 1 B = 2(xdxo - xdxc+ ydyo - ydyc+ zdzo - zdzc) C = xo2- 2xoxc+ xc2+ yo2- 2yoyc+ yc2+ zo2-2zozc+ zc2 - r2 So At2 + Bt + C = 0 and we can solve this using the quadratic equation:

42
**Ray-Sphere Intersections**

3 possibilities: Case 1: B2 – 4C < 0 Zero real roots. No intersection. Case 2: B2 – 4C = 0 One real root t0 = t1 = -B/2 Case 3: B2 – 4C > 0 Two real roots Subcase a: t0 < 0, t1 > 0 t1 is the correct answer Subcase b: 0 < t0 < t1 t0 is the correct answer case 1 case 2 t1 case 3a t0 t0 t1 case 3b

43
**Ray-Sphere Intersections**

If the discriminant B2 – 4C < 0, the ray misses the sphere. The smaller positive root (if one exists) is the closest intersection point. We can save time by computing the small root first and only computing the large root if necessary.

44
**Ray-Sphere Intersections: Algorithm**

Algorithm for ray-sphere intersection: Calculate B and C of the quadratic Calculate the discriminant: D = B2 – 4C If D < 0 return false (no intersection point) Calculate smaller t-value t0: If t0 0 then calculate larger t-value t1: If t1 0 return false (intersection is behind ray) else set t = t1 else set t = t0 Return intersection point: p = r(t) = ro + rdt

45
**Ray-Sphere Intersections: Normal**

The normal n at an intersection point p on a sphere is: n p R c

46
**Ray-Sphere Intersections**

Computation time per ray-sphere test: 17 additions / subtractions 17 multiplies 1 square root Can we reduce the number of intersection calculations? Yes, use a geometric approach (not here).

47
**Ray-Plane Intersections**

To find the intersection point of a ray with a plane: Plane equation: ax +by +cz +d = 0 with a2 + b2 +c2 = 1 normal n = (a, b, c) distance from (0, 0, 0) to plane is d Ray equation: Origin: ro = (xo, yo, zo) Direction: rd = (xd, yd, zd) Substitute the ray equation into the plane equation: a(x0 + xdt) + b(y0 + ydt) + c(z0 + zdt) + d = 0 Þ ax0 + axdt + by0 + bydt + cz0 + czdt + d = 0 Solving for t we get: t = -(ax0 + by0 + cz0 + d) / (axd + byd + czd)

48
**Ray-Plane Intersections**

In vector form: If the ray is parallel to the plane and does not intersect If the plane’s normal points away from the ray and thus the plane is culled. If t 0 then intersection point is behind the ray, so no real intersection occurs Otherwise, compute intersection: p = ro + rdt

49
**Ray/Plane Intersection**

Basic Algorithm: vd = n·rd if vd ³ 0 and plane has one side then return if vd = 0 then return (ray is parallel to plane) t = -(n·ro + d) / vd if t < 0 then return return r = (xo + xdt, yo + ydt, zo + zdt)

50
**Ray/Polygon Intersection**

Assume planar polygons First, intersect the plane the polygon is on with the ray. Next, determine if the intersection is within the polygon. How do we quickly tell if the intersect is within the polygon?

51
**Ray/Polygon Intersection**

Idea: shoot a ray from the intersection point in an arbitrary direction if the ray crosses an even number of polygon edges, the point is outside the polygon if the ray crosses an odd number of polygon edges, the point is inside the polygon 11 crossings - point inside polygon 4 crossings - point outside polygon

52
**Ray/Polygon Intersection**

a set of N points Pj = (xj, yj, zj), j = 0, 1, … N-1 Plane: ax + by + cz + d = 0, with normal n = (a, b, c) Intersection point: pi = (xi, yi, zi), pi on the plane

53
**Ray/Polygon Intersection Algorithm**

Step 1: Project the polygon onto a coordinate plane Simply discard one of the coordinates. This will project the polygon onto the plane defined by the other two coordinates. This doesn’t preserve area, but does preserve topology. Discard the coordinate whose magnitude in the plane normal is the largest. If n = (3, -1, -5) we would throw away the z coordinates.

54
**Ray/Polygon Intersection Algorithm**

Step 2: Translate the polygon so that the intersection point is at the origin. Translate all its vertices. Step 3: Send a ray down a coordinate axis and count the number of times it intersects the polygon. This can be done simply by counting the number of edges that cross the coordinate axis.

55
**Ray/Polygon Intersection Algorithm**

Problems: Vertices that lie exactly on the ray Edges that lie exactly on the ray

56
**Ray/Polygon Intersection Algorithm**

How do we handle these cases? Essentially, shift the vertex or edge up by e so that it will be just above the axis.

57
**Ray/Polygon Intersection Algorithm**

The effect of doing this e shift is: These cases all work correctly now.

58
**The Complete Algorithm - part 1**

Find the coordinate of n with the largest magnitude. For each vertex (xj, yj, zj), j = 0, 1, …, N-1 of the polygon, project the vertex onto the coordinate plane of the other two coordinates. This gives us a new coordinates system (uj, vj). Project the intersection point (xi, yi, zi) onto the same coordinate plane as the vertices. Translate all polygon vertices by (-ui, -vi). (uj’, vj’) = (uj, vj) - (ui, vi). 5. Set numCrossings = 0

59
**The Complete Algorithm - part 2**

If v0’ < 0, set sign = -1, otherwise set sign = 1 For i = 0 to N-1 (let uN = u0, vN = v0 ) if vi+1’ < 0 set nextSign = -1 else set nextSign = 1 if (sign ≠ nextSign) if (ui’ > 0 and ui+1’ > 0) numCrossings++ else if (ui’ > 0 or ui+1’>0) \\ the edge might cross +u’ \\ compute the intersection with the u’ axis uc = ui’ - vi’ * (ui+1’ -ui’)/(vi+1’ -vi’) if uc > 0 numCrossings++ sign = nextSign If numCrossings is odd, the intersection is inside the polygon.

60
**Example Given a polygon: and intersection point**

Ri = (-2, -2, 4) Does the intersection point lie within the polygon? P0 P1 P2

61
**Example Step 1: Get the plane normal, determine dominant coordinate**

n can be computed from the cross product of two vectors in the plane The vertices of the polygon can be used to compute vectors in the plane P0 P1 P2 P0 = (-3, -3, 7) P1 = (3, -4, 3) P2 = (4, -5, 4) Ri = (-2, -2, 4)

62
**Example Compute the Normal: v1 = P0 - P1 = (-3, -3, 7) - (3, -4, 3)**

First, compute edge vectors from the vertices P0 P1 v1 = P0 - P1 = (-3, -3, 7) - (3, -4, 3) = (-6, 1, 4) P2 P0 = (-3, -3, 7) P1 = (3, -4, 3) P2 = (4, -5, 4) Ri = (-2, -2, 4) v2 = P2 - P1 = (4, -5, 4) - (3, -4, 3) = (1, -1, 1)

63
**Example The plane normal is then v2 x v1 n = (-6, 1, 4) x (1, -1, 1)**

= (5, 10, 5) P0 n P1 So the dominant coordinate is y P2 P0 = (-3, -3, 7) P1 = (3, -4, 3) P2 = (4, -5, 4) Ri = (-2, -2, 4)

64
**Example Step 2: Project the vertices**

Step 3: Project the intersection point project P0 = (-3, -3, 7) Þ (-3, 7) project P1 = (3, -4, 3) Þ (3, 3) project P2 = (4, -5, 4) Þ (4, 4) u’ P1’ Ri P2’ P0’ v’ project Ri = (-2, -2, 4) Þ (-2, 4)

65
**Example Step 4: Translate the vertices**

Ri’ = (-2, 4) - (-2, 4) Þ (0, 0) P1’ Ri u’ P2’ P0’ v’

66
**Example Step 5: Set numCrossings = 0 Step 6: v0’= 3, so sign = 1 P1’**

Ri v’ P2’ P0’ u’

67
**Example Since numCrossings is even, the point is outside the polygon**

(Figure is drawn upside-down. Sorry. The positive v’ axis points down. Step 7: i sign nextSign numCrossings intersection point For i = 0 to N \\ (let uN = u0, vN = v0 ) if vi+1’ < 0 set nextSign = -1 else set nextSign = 1 if (sign ≠ nextSign) if (ui’ > 0 and ui+1’ > 0) numCrossings++ else if (ui’ > 0 or ui+1’>0) \\ the edge might cross +u’ \\ compute the intersection with the u’ axis uc = ui’ - vi’ * (ui+1’ -ui’)/(vi+1’ -vi’) if uc > 0 numCrossings++ sign = nextSign P1’=(5,-1) Ri u’ P2’ = (6,0) P0’=(-1,3) v’ +1 -1 1 -1-3*(5-(-1))/(-1-3) = 3.5 1 -1 +1 2 2 +1 +1 Since numCrossings is even, the point is outside the polygon

68
**Shadows Send a shadow ray from intersection point to the light:**

Compute the following shadow ray properties: Shadow ray direction: sd = (l – p) / ||l – p|| Distance to the light from the intersection point: tl = ||l – p|| Test if shadow ray intersects an object before reaching the light: In theory, the possible range of t-values is t [0, tl] Due to numerical (floating-point) error, test in the range t [e, t1] where e is some small value (such as 2–15)

69
Recursive Ray Tracing Basic ray tracing results in basic Phong illumination plus hidden surfaces. Shadows require only one extra ray per light source Shadow rays do not reflect or refract. No need to find the closest object, only need to hit once before reaching the light. Reflection and refraction rays add a lot to the images. Reflection and refraction can spawn many new rays since light can keep bouncing.

70
**Computing ray colours How to get the final pixel colour? End result:**

Every material has local colour c Define reflexivity, refraction factors ρ (i.e. between 1.0 (mirror) and 0.0 (no reflection) Each hit returns its colour down the chain End result: colour = (1 –ρ) c1 + ρ1 ( (1- ρ2)c2 + ρ2 (c3 …. ))) Local colour also influenced by shadow rays!

71
**Computing reflection rays**

Reflection is pretty simple Incident angle = Exit angle Incident ray: x + t*d Reflection ray: a + t*(d – 2*n*dot(n,d)) (careful, assumes n and d normalized!) n a

72
Specular Reflection Perfect reflection: angle of reflection = angle of incidence Light continues to bounce: Typically, some energy is lost on each bounce n and l are unit vectors n r l

73
Specular Reflection Implement specular reflection with a recursive call: colour = ambient + diffuseobj + specularobj + ks reflectedcolour where ks represents how “perfect” the mirror is and reflected colour is the recursive call Limit recursion: max depth or when the contribution of a ray is negligible

74
**Refraction (transparency)**

Light transmits through transparent objects. Light bends when moving from one medium to another according to Snell’s law: n1 air glass n2

75
**Refraction Indices Material Index Vacuum 1.0 Air 1.0003 Water 1.33**

Alcohol Fused quartz 1.46 Crown glass 1.52 Flint glass 1.65 Sapphire 1.77 Heavy flint glass 1.89 Diamond 2.42

76
**Refraction Total internal reflection**

When going from a dense to less dense medium, the angle of refraction becomes more shallow If the angle of incidence is too shallow, it can get trapped in the dense material Optical cable Diamonds Calculating the transmitted vector requires: Incident ray direction Normal Indices of refraction Some trigonometry air d glass n

77
Ray Tracing Ambient Light only

78
Ray Tracing With shadows

79
Ray Tracing Primary rays only

80
Ray Tracing With Phong shading

81
Ray Tracing With reflections

82
Ray Tracing With transmissions

83
**Other Ray Traced Images**

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google