Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann.

Similar presentations


Presentation on theme: "CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann."— Presentation transcript:

1 CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann

2 Michael Eckmann - Skidmore College - CS 376 - Spring 2007 Today’s Topics Questions? Illumination equation correction (affects a slide that appears on 3/23, 3/26 and 3/30.) Raytracing –computing the intersection of a ray and a plane –computing the intersection of a ray and a polygon Go over the pseudocode for ray tracing

3 Illumination Change this equation: I R = I aR k a O R + Sum all i [f radatten (d L ) I pRi (k d L ● N + W(theta)cos ns (phi))] which is INCORRECT to this one: I R = I aR k a O R + Sum all i [f radatten (d L ) I pRi O R (k d L ● N + W(theta)cos ns (phi))] which is CORRECT The above equation is for the red channel, do the same for green and blue channels. Recall... Ambient light as 3 components: I aR I aG I aB Point lights each as 3 components: I pR I pG I pB Objects with color: O R O G O B

4 Ray / Sphere Intersection The normal to the sphere at the intersection point is to be used for illumination of that point and the further computation of rays (reflected and refracted). If the ray's starting point is inside the sphere, then we want to use the direction of the normal at the intersection towards the center of the sphere (that makes us use the inside of the sphere that the ray hits). Compute the unit normal to the sphere at the intersection P I = (x I, y I, z I ) to be: N = [(x I -x c )/r, (y I -y c )/r, (z I -z c )/r] Just use the negation of N, if the ray starts inside the sphere.

5 Ray / Sphere Intersection There are several things we can do to increase efficiency that we will cover later –for instance, we should be able to figure out that a sphere and a ray do not intersect without having to go through the whole process just described.

6 Ray / Plane Intersection Calculating a plane and a ray intersection is the first step in calculating a polygon and a ray intersection. So, let's discuss this process first.

7 Ray Equation again The ray equation again is: P(s) = P 0 + R d s where P 0 is the starting point of the ray, R d is a unit directional vector and s is the parameter which represents the distance from P 0 If P = (x,y,z) and P 0 = (x 0, y 0, z 0 ) and R d = (x d, y d, z d ) this ray equation can be rewritten as 3 equations like so: x = x 0 + x d s y = y 0 + y d s z = z 0 + z d s

8 Ray / Plane Intersection The plane equation, as we've seen before is Ax + By + Cz + D = 0 Normal vector N = [A,B,C] We can get the equation of the plane to have [A,B,C] be a unit vector (magnitude 1). How could we do that? Then A 2 + B 2 + C 2 = 1 What do you think we do next?

9 Ray / Plane Intersection Substitute the ray equation into the plane equation to find the value for s (the distance along the ray where the intersection occurs). A(x 0 + x d s) + B(y 0 + y d s) + C(z 0 + z d s) + D = 0 Solve for s on the board. This will work out to be s = - (N P 0 + D) / (N R d ) Compute the intersection point based on s which is (x 0 + x d s, y 0 + y d s, z 0 + z d s)

10 Ray / Plane Intersection The normal to the plane at the intersection point is to be used for illumination of that point and the further computation of rays (reflected and refracted). The normal to the plane at the intersection that we need to use is the one that points towards the side that the ray came from (that makes us use the side of the plane that the ray hits). Example on board. You already have a unit plane normal N = [A,B,C]. To determine if it is the correct one to use, just check the sign of (N R d ). –if (N R d ) < 0 then keep N as is –if (N R d ) > 0 then negate N to be [-A, -B, -C]

11 Ray / Plane Intersection Let's see some possible situations on the board. –(ray/plane parallel (N R d )=0), –(N R d ) < 0 ( keep N as is ) –(N R d ) > 0 ( negate N ) –s > 0, (ray does intersect) –s < 0, (ray doesn't intersect)

12 Ray / Polygon Intersection The first step in Ray/Polygon intersection is to compute the intersection of the ray with the plane that the polygon lives on. At this point we have –the plane equation Ax+By+Cz+D = 0 –the point of intersection P I = (x I, y I, z I ) of the ray and plane –the vertices V = (x j, y j, z j ) of the polygon on that plane A technique that makes computation easier at this point is to orthographically project the polygon onto either the x-y, y-z, or z-x plane. To do this we just have to ignore the same coordinate of all of the vertices of the polygon and we end up with 2d points. The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.)

13 Ray / Polygon Intersection The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.) Why do you think this would be the best one to ignore?

14 Ray / Polygon Intersection The best coordinate to ignore is the one whose corresponding coefficient in the plane equation is dominant (largest absolute value.) Why do you think this would be the best one to ignore? –it gives us a polygon in 2d with the largest area of the 3 choices –Why is the largest one best?

15 Ray / Polygon Intersection Note: this technique is a combination of ideas from –Computer Graphics Principles and Practive by Foley, Van Dam, Feiner and Hughes, 1996 Addison-Wesley –Dr. G. Drew Kessler's csc313 course 1999, Lehigh Univ. and –Dr. Xiaoyu Zhang's Advanced Computer Graphics & Visualization page http://courses.csusm.edu/cs697exz/ray_polygon.htm Example: If the plane equation is –0.2 x +0.4 y –0.8945 z +5 = 0 we would orthographically project the polygon onto the x-y plane (ignore the z coordinate of each vertex) This will yield the largest (area) projection. Once we have done this projection, we can translate the intersection point P I to the origin of this new 2d space (call it u-v coordinates). Then determine whether the origin is inside or outside the polygon by counting the number of polygon edge crossings with the positive u axis.

16 Ray / Polygon Intersection The n vertices of the polygon are (u i, v i ) where i goes from 0 to n-1. Pseudocode to determine if the origin is inside the polygon initialize numCross to 0 if v 0 > 0 then signHold1 = +1 else signHold1 = -1 for each edge (u a, v a ) to (u b, v b ) { if v b > 0, signHold2 = +1, else signHold2 = -1 if signHold1 != signHold2 { if u a and u b are both > 0, then numCross++ if one of u a or u b is > 0, then { if (crossPosUAxis(u a, v a, u b, v b ) then numCross++ } } signHold1 = signHold2 } if numCross is odd, then the ray and polygon intersect

17 Ray / Polygon Intersection pseudocode for crossPosUAxis recall the parametric equations of a line: u = u b + (u a - u b )t v = v b + (v a - v b )t = 0 (because we're looking for intersection with u axis) so, use the second equation to solve for t then solve the first for u and get u = (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) crossPosUAxis(u a, v a, u b, v b ) if ( (u b + ( u a - u b ) * ( v b / (v b -v a ) ) ) > 0 ) return true else return false


Download ppt "CS 376 Introduction to Computer Graphics 04 / 06 / 2007 Instructor: Michael Eckmann."

Similar presentations


Ads by Google