cs 4300 computer graphics - ccs.neu.edu
TRANSCRIPT
![Page 1: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/1.jpg)
©College of Computer and Information Science, Northeastern University
CS 4300 Computer Graphics
Prof. Harriet Fell Fall 2011
Lecture 27 – November 9, 2011
![Page 2: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/2.jpg)
©College of Computer and Information Science, Northeastern University
Topics
• Ray intersections with – plane – triangle – quadrics
• Recursive Ray Tracing
![Page 3: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/3.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 3
More Ray-Tracing
Ray/Plane Intersection
Ray/Triangle Intersection
Ray/Polygon Intersection
![Page 4: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/4.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 4
Equation of a Plane
N = (A, B, C)
P0 = (a, b, c)
(x, y, z)
Given a point P0 on the plane and a normal to the plane N.
(x, y, z) is on the plane if and only if
(x-a, y-b, z-c)·N = 0.
Ax + By + Cz –(Aa + Bb + Cc) = 0 D
![Page 5: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/5.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 5
Ray/Plane Intersection
Ax + By + Cz = D P0 = (x0, y0, z0)
P1 = (x1, y1, z1)
Ray Equation
x = x0 + t(x1 - x0)
y = y0 + t(y1 - y0)
z = z0 + t(z1 - z0)
A(x0 + t(x1 - x0)) + B(y0 + t(y1 - y0)) + C(z0 + t(z1 - z0)) = D
Solve for t. Find x, y, z.
![Page 6: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/6.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 6
Planes in Your Scenes
• Planes are specified by – A, B, C, D or by N and P – Color and other coefficients are as for spheres
• To search for the nearest object, go through all the spheres and planes and find the smallest t.
• A plane will not be visible if the normal vector (A, B, C) points away from the light. – or we see the back of the plane
![Page 7: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/7.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 7
Ray/Triangle Intersection
Using the Ray/Plane intersection: – Given the three vertices of the triangle,
• Find N, the normal to the plane containing the triangle.
• Use N and one of the triangle vertices to describe the plane, i.e. Find A, B, C, and D.
• If the Ray intersects the Plane, find the intersection point and its β and γ.
• If 0 ≤ β and 0 ≤ γ and β + γ ≤ 1, the Ray hits the Triangle.
![Page 8: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/8.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 8
Ray/Triangle Intersection Using barycentric coordinates
directly: (Shirley pp. 206-208) Solve
e + td = a + β(b-a) + γ(c-a) for t, γ, and β.
The x, y, and z components give you 3 linear equations in 3 unknowns. If 0 ≤ t ≤ 1, the Ray hits the Plane. If 0 ≤ β and 0 ≤ γ and β + γ ≤ 1, the Ray hits the Triangle. (xe, ye, ze)
(xd, yd, zd) (xd, yd, zd)
a b
c
![Page 9: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/9.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 9
Images with Planes and Polygons
![Page 10: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/10.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 10
Images with Planes and Polygons
![Page 11: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/11.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 11
Ray Box Intersection
(xl, yl, zl)
(x0, y0, z0) + t (xd, yd, zd)
(xd, yd, zd) a unit vector
(xh, yh, zh)
(x0, y0, z0)
t1 = (xl - x0) / xd
![Page 12: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/12.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 12
Ray Box Intersection http://courses.csusm.edu/cs697exz/ray_box.htm
or see Watt pages 21-22 Box: minimum extent Bl = (xl, yl, zl) maximum extent Bh = (xh, yh, zh) Ray: R0 = (x0, y0, z0) , Rd= (xd, yd, zd) ray is R0 + tRd
Algorithm: 1. Set tnear = -INFINITY , tfar = +INFINITY 2. For the pair of X planes
1. if zd = 0, the ray is parallel to the planes so: if x0 < x1 or x0 > xh return FALSE (origin not between planes)
2. else the ray is not parallel to the planes, so calculate intersection distances of planes t1 = (xl - x0) / xd (time at which ray intersects minimum X plane) t2 = (xh - x0) / xd (time at which ray intersects maximum X plane) if t1 > t2 , swap t1 and t2 if t1 > tnear , set tnear = t1 if t2 < tfar, set tfar= t2 if tnear > tfar, box is missed so return FALSE if tfar < 0 , box is behind ray so return FALSE
3. Repeat step 2 for Y, then Z 4. All tests were survived, so return TRUE
![Page 13: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/13.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 13
Quadric Surfaces
2 2 2
2 2 2 1x y za b c
+ + =
ellipsoid elliptic cylinder
2 2
2 2 1x ya b
+ =
![Page 14: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/14.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 14
Quadric Surfaces
2 2 2
2 2 2 1x y za b c
+ − = −
1-sheet hyperboloid 2-sheet hyperboloid
2 2 2
2 2 2 1x y za b c
+ − =
![Page 15: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/15.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 15
Quadric Surfaces
cones
2 22
2 2
x yza b
= +
![Page 16: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/16.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 16
elliptic parabaloid
2 2
2 2
x yza b
= +2 2
2 2
y xzb a
= −
hyperbolic parabaloid
![Page 17: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/17.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 17
Quadric Surfaces
hyperbolic cylinder parabolic cylinder
2 2
2 2 1x ya b
− =2 2 0x y+ =
![Page 18: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/18.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 18
General Quadrics in General Position
![Page 19: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/19.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 19
General Quadric Equation
x t( ) = x0 + txd xd = x1 − x0
y t( ) = y0 + tyd yd = y1 − y0
z t( ) = z0 + tzd zd = z1 − z0
( ) ( ) ( )( )( ) ( )( ) ( )( )( ) ( ) ( )
2 2 20 0 0
0 0 0 0 0 0
0 0 0
2 2 2
2 2 2 0
d d d
d d d d d d
d d d
a x tx b y ty c z tz
d x tx y ty e y ty z tz f x tx z tz
g x tx h y ty j z tz k
+ + + + +
+ + + + + + + + +
+ + + + + + + =
2 2 2 2 2 2 2 2 2 0ax by cz dxy eyz fxz gx hy jz k+ + + + + + + + + =
Ray Equations
( ) ( ) ( )
2 2 2
0 0 0
0 0 0 0 0 0
2 2 20 0 0 0 0 0 0 0 0 0 0 0
2 2 22 2 22 2 2 2 2 2
2 2 2 2 2 2
d d d d d d d d d
d d d
d d d d d d d d d
A ax by cz dx y ey z fx zB ax x by y cz z
d x y x y e y z y z f x z x z gx hy jz
C ax by cz dx y ey z fx z gx hy jz k
= + + + + += + +
+ + + + + + + + +
= + + + + + + + + +
![Page 20: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/20.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 20
Ray Quadric Intersection Quadratic Coefficients
A = a*xd*xd + b*yd*yd + c*zd*zd
+ 2[d*xd*yd + e*yd*zd + f*xd*zd
B = 2*[a*x0*xd + b*y0*yd + c*z0*zd
+ d*(x0*yd + xd*y0 ) + e*(y0*zd + yd*z0 ) + f*(x0*zd + xd*z0 )
+ g*xd + h*yd + j*zd]
C = a*x0*x0 + b*y0*y0 + c*z0*z0
+ 2*[d*x0*y0 + e*y0*z0 + f*x0*z0 + g*x0 + h*y0 + j*z0] + k
![Page 21: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/21.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 21
Quadric Normals
Q x, y, z( ) = ax2 + by2 + cz2 + 2dxy + 2eyz + 2 fxz + 2gx + 2hy + 2 jz + k
∂Q∂x
= 2ax + 2dy + 2 fz + 2g = 2 ax + dy + fz + g( )∂Q∂y
= 2by + 2dx + 2ez + 2h = 2 by + dx + ez + h( )∂Q∂z
= 2cz + 2ey + 2 fx + 2 j = 2 cz + ey + fx + j( )
N =∂Q∂x
,∂Q∂y
,∂Q∂z
⎛⎝⎜
⎞⎠⎟
Normalize N and change its sign if necessary.
![Page 22: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/22.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 22
MyCylinders
![Page 23: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/23.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 23
Student Images
![Page 24: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/24.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 24
Student Images
![Page 25: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/25.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 25
Recursive Ray Tracing Adventures of the 7 Rays - Watt
Specular Highlight on Outside of Shere
![Page 26: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/26.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 26
Adventures of the 7 Rays - Watt
Specular Highlight on Inside of Sphere
Recursive Ray Tracing
![Page 27: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/27.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 27
Adventures of the 7 Rays - Watt
Reflection and Refraction of Checkerboard
Recursive Ray Tracing
![Page 28: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/28.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 28
Adventures of the 7 Rays - Watt
Refraction Hitting Background
Recursive Ray Tracing
![Page 29: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/29.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 29
Adventures of the 7 Rays - Watt
Local Diffuse Plus Reflection from Checkerboard
Recursive Ray Tracing
![Page 30: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/30.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 30
Adventures of the 7 Rays - Watt
Local Diffuse in Complete Shadow
Recursive Ray Tracing
![Page 31: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/31.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 31
Adventures of the 7 Rays - Watt
Local Diffuse in Shadow from Transparent Sphere
Recursive Ray Tracing
![Page 32: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/32.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 32
Recursive Ray-Tracing
• How do we know which rays to follow? • How do we compute those rays? • How do we organize code so we can
follow all those different rays?
![Page 33: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/33.jpg)
select center of projection(cp) and window on view plane; for (each scan line in the image ) { for (each pixel in scan line ) { determine ray from the cp through the pixel; pixel = RT_trace(ray, 1);}}
// intersect ray with objects; compute shade at closest intersection // depth is current depth in ray tree RT_color RT_trace (RT_ray ray; int depth){ determine closest intersection of ray with an object; if (object hit) { compute normal at intersection; return RT_shade (closest object hit, ray, intersection, normal, depth);} else return BACKGROUND_VALUE;
}
![Page 34: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/34.jpg)
// Compute shade at point on object, // tracing rays for shadows, reflection, refraction. RT_color RT_shade ( RT_object object, // Object intersected RT_ray ray, // Incident ray RT_point point, // Point of intersection to shade RT_normal normal, // Normal at point int depth ) // Depth in ray tree
{ RT_color color; // Color of ray RT_ray rRay, tRay, sRay;// Reflected, refracted, and shadow ray color = ambient term ; for ( each light ) { sRay = ray from point to light ; if ( dot product of normal and direction to light is positive ){ compute how much light is blocked by opaque and transparent surfaces, and use to scale diffuse and specular terms before adding them to color;}}
![Page 35: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/35.jpg)
©College of Computer and Information Science, Northeastern University
if ( depth < maxDepth ) { // return if depth is too deep if ( object is reflective ) { rRay = ray in reflection direction from point; rColor = RT_trace(rRay, depth + 1); scale rColor by specular coefficient and add to color; } if ( object is transparent ) { tRay = ray in refraction direction from point; if ( total internal reflection does not occur ) { tColor = RT_trace(tRay, depth + 1); scale tColor by transmission coefficient and add to color; } } } return color; // Return the color of the ray
}
![Page 36: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/36.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 36
Reflections, no Highlight
![Page 37: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/37.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 37
Second Order Reflection
![Page 38: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/38.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 38
Refelction with Highlight
![Page 39: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/39.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 39
Nine Red Balls
![Page 40: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/40.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 40
Refraction
N
-N
I
T θT
θI
ηT and ηI are the indexes of refraction of the two mediums.
![Page 41: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/41.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 41
Indices of Refraction Material η at λ=589.3 nm vacuum 1 (exactly) helium 1.000036 air at STP 1.0002926 water ice 1.31 liquid water (20°C) 1.333 ethanol 1.36 glycerine 1.4729 rock salt 1.516 glass (typical) 1.5 to 1.9 cubic zirconia 2.15 to 2.18 diamond 2.419
http://en.wikipedia.org/wiki/List_of_indices_of_refraction
![Page 42: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/42.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 42
One Glass Sphere
![Page 43: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/43.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 43
Five Glass Balls
![Page 44: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/44.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 44
A Familiar Scene
![Page 45: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/45.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 45
Bubble
![Page 46: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/46.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 46
Milky Sphere
![Page 47: CS 4300 Computer Graphics - ccs.neu.edu](https://reader034.vdocuments.mx/reader034/viewer/2022052306/62894207b36af178e75486ad/html5/thumbnails/47.jpg)
©College of Computer and Information Science, Northeastern University November 18, 2011 47
Lens - Carl Andrews 1999