View
4
Download
0
Category
Preview:
Citation preview
1
CS 586/480Computer Graphics II
Dr. David BreenMatheson 408Thursday 6PM Æ 8:50PM
Presentation 210/7/04
Start Upn Any questions from last time?n Presentation assignmentsn Shailajan Ilyan Dmitriy
n Programming assignment submissionsn Go over sampling image plane?
Slide Creditsn Leonard McMillan, Seth Teller,
Fredo Durand, Barb Cutler - MITn G. Drew Kessler, Larry Hodges - Georgia
Institute of Technologyn John Hart - University of Illinois
More Geometry & Intersections
2
Ray/Plane IntersectionRay is defined by R(t) = Ro + Rd*t where t ≥ 0
Ro = Origin of ray at (xo, yo, zo)Rd = Direction of ray [xd, yd, zd] (unit vector)
Plane is defined by [A, B, C, D]Ax + By + Cz + D = 0 for a point in the planeNormal Vector, N = [A, B, C] (unit vector)A2 + B2 + C2 = 1D = - N • P0 (P0 - point in plane)
Ray/Plane (cont.)Substitute the ray equation into the planeequation:
A(xo + xdt) + B(yo + ydt) + C(zo +zdt) + D = 0
Solve for t:t = -(Axo + Byo + Czo + D) / (Axd + Byd + Czd)t = -(N • Ro + D) / (N • Rd)
What Can Happen? N • Rd = 0 N • Rd > 0
t < 0
Ro
t > 0
Ro
Ray/Plane SummaryIntersection point:
(xi, yi, zi) = (xo + xdti, yo + ydti, zo + zdti)
1. Calculate N • Rd and compare it to zero.2. Calculate ti and compare it to zero.3. Compute intersection point.4. Flip normal if N • Rd is positive
3
Ray-Parallelepiped Intersectionn Axis-alignedn From (X1, Y1, Z1) to (X2, Y2, Z2)n Ray P(t)=Ro+Rdt
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
Naïve ray-box Intersectionn Use 6 plane equationsn Compute all 6 intersectionn Check that points are inside box
Ax+By+Cz+D ≤ 0y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
Factoring out computationn Pairs of planes have the same normaln Normals have only one non-0 componentn Do computations one dimension at a timen Maintain tnear and tfar (closest and
farthest so far)y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
Test if paralleln If Rdx = 0, then ray is paralleln If Rox < X1 or Rox > x2 return false
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
4
If not paralleln Calculate intersection distance t1 and t2n t1 = (X1-Rox)/Rdxn t2 = (X2-Rox)/Rdx
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
t1
t2
Test 1n Maintain tnear and tfar
n If t1 > t2, swapn if t1 > tnear, tnear = t1n if t2 < tfar, tfar = t2
n If tnear > tfar, box is missed
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
t1x t2xtnear
t1y
t2ytfar
tfar
Test 2n If tfar < 0, box is behind
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
t1xt2xtfar
Algorithm recapn Do for all 3 axes
n Calculate intersection distance t1 and t2n Maintain tnear and tfarn If tnear > tfar, box is missedn If tfar < 0, box is behind
n If box survived tests, report intersection at tneary=Y2
y=Y1
x=X1 x=X2Ro
Rd
tnear
t1y
tfar
5
Ray/Ellipsoid IntersectionRay/Cylinder Intersection
Ellipsoid's surface is defined by the set of points{(xs, ys, zs)} satisfying the equation:
(xs/ a)2 + (ys/ b)2 + (zs/ c)2 - 1 = 0
Cylinder's surface is defined by the set of points{(xs, ys, zs)} satisfying the equation:
(xs)2 + (ys)2 - r2 = 0 -z0 ≤ zs ≤ z0
Centers at origin
ß Substitute ray equation into surfaceequationsß This is a quadratic equation in t:ß At2 + Bt + C = 0
ß Analyze as beforeß Solve for t with quadratic equationß Plug t back into ray equation - Doneß Well,… not exactly
Ray/Ellipsoid IntersectionRay/Cylinder Intersection
Ray/Cylinder Intersectionß Is intersection point Pi between -Z0 and Z0?ß If not, Pi is not validß Also need to do intersection test with
z = -Z0 | Z0 planeß If (Pix)2 + (Piy)2 ≤ r2, you’ve intersected a
“cap”ß Which valid intersection is closer?
6
Superquadrics
†
xa1
Ê
Ë Á
ˆ
¯ ˜
2e 2
+ya2
Ê
Ë Á
ˆ
¯ ˜
2e 2
È
Î
Í Í
˘
˚
˙ ˙
e 2e1
+za3
Ê
Ë Á
ˆ
¯ ˜
2e1
=1
SMF Triangle Meshesv -1 -1 -1v 1 -1 -1v -1 1 -1v 1 1 -1v -1 -1 1v 1 -1 1v -1 1 1v 1 1 1f 1 3 4f 1 4 2f 5 6 8f 5 8 7f 1 2 6f 1 6 5f 3 7 8f 3 8 4f 1 5 7f 1 7 3f 2 4 8f 2 8 6
vertices
triangles
Draw data structure
Triangle Meshes (.iv) Transformations &Hierarchical Models
7
n Add an extra dimension• in 2D, we use 3 x 3 matrices• In 3D, we use 4 x 4 matrices
n Each point has an extra value, w
Homogeneous Coordinates
x'
y'
z'
w'
=
x
y
z
w
a
e
i
m
b
f
j
n
c
g
k
o
d
h
l
p
p' = M p
n Most of the time w = 1, and we canignore it
Homogeneous Coordinates
x'
y'
z'
1
=
x
y
z
1
a
e
i
0
b
f
j
0
c
g
k
0
d
h
l
1
Translate (tx, ty, tz)n Why bother with the
extra dimension?Because now translationscan be encoded in the matrix!
Translate(c,0,0)
x
y
p p'
c
x'
y'
z'
1
=
x
y
z
1
1
0
0
0
0
1
0
0
0
0
1
0
tx
ty
tz
1
x'
y'
z'
Scale (sx, sy, sz)n Isotropic (uniform)
scaling: sx = sy = sz
n You only have to implement uniform scaling
x'
y'
z'
1
=
x
y
z
1
sx
0
0
0
0
sy
0
0
0
0
sz
0
0
0
0
1
Scale(s,s,s)
x
p
p'
qq'
y
8
Rotationn About z axis
x'
y'
z'
1
=
x
y
z
1
cos f
sin f
0
0
-sin f
cos f
0
0
0
0
1
0
0
0
0
1
ZRotate(f)
x
y
z
p
p'
_
Rotation
n Aboutx axis:
n Abouty axis:
x'
y'
z'
1
=
x
y
z
1
0cos a
sin a
0
0-sin a
cos a
0
1
0
0
0
0
0
0
1
x'
y'
z'
1
=
x
y
z
1
cos q
0
-sin q
0
sin q
0cos q
0
0
1
1
0
0
0
0
1
Rotationn About (kx, ky, kz), an arbitrary unit vector (Rodrigues Formula)
x'
y'
z'
1
=
x
y
z
1
kxkx(1-c)+c
kykx(1-c)+kzs
kzkx(1-c)-kys
0
0
0
0
1
kykx(1-c)-kzs
kyky(1-c)+c
kzky(1-c)+kxs
0
kxkz(1-c)+kys
kykz(1-c)-kxs
kzkz(1-c)+c
0
where c = cos q & s = sin q
Rotate(k, q)
x
y
z
_
k
How are transforms combined?
(0,0)
(1,1)(2,2)
(0,0)
(5,3)
(3,1)Scale(2,2) Translate(3,1)
TS =2
0
0
2
0
0
1
0
0
1
3
1
2
0
0
2
3
1=
Scale then Translate
Use matrix multiplication: p' = T ( S p ) = ((TS) p)
Caution: matrix multiplication is NOT commutative!
0 0 1 0 0 1 0 0 1
9
Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p
Translate then Scale: p' = S ( T p ) = ST p
(0,0)
(1,1)(4,2)
(3,1)
(8,4)
(6,2)
(0,0)
(1,1)(2,2)
(0,0)
(5,3)
(3,1)Scale(2,2) Translate(3,1)
Translate(3,1) Scale(2,2)
TS =2
0
0
0
2
0
0
0
1
1
0
0
0
1
0
3
1
1
ST =2
0
0
2
0
0
1
0
0
1
3
1
Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p
2
0
0
0
2
0
3
1
1
2
0
0
2
6
2
=
=
Translate then Scale: p' = S ( T p ) = ST p
0 0 1 0 0 1 0 0 1
Transformations in Ray Tracing
Transformations in Modelingn Position objects in a scenen Change the shape of objectsn Create multiple copies of objectsn Projection for virtual camerasn Animations
10
Scene Description
Scene
LightsCamera ObjectsMaterialsBackground
Simple Scene Description File
Camera { center 0 0 10 direction 0 0 -1 up 0 1 0 }
Lights { numLights 1 DirectionalLight { direction -0.5 -0.5 -1 color 1 1 1 } }
Background { color 0.2 0 0.6 }
Materials { numMaterials <n>
<MATERIALS> }
Group { numObjects <n> <OBJECTS> }
Hierarchical Models
n Logical organization of sceneGroup { numObjects 3 Group { numObjects 3 Box { <BOX PARAMS> } Box { <BOX PARAMS> } Box { <BOX PARAMS> } } Group { numObjects 2 Group { Box { <BOX PARAMS> } Box { <BOX PARAMS> } Box { <BOX PARAMS> } } Group { Box { <BOX PARAMS> } Sphere { <SPHERE PARAMS> } Sphere { <SPHERE PARAMS> } } } Plane { <PLANE PARAMS> } }
Simple Example with Groups
11
Group { numObjects 3 Group { numObjects 3 Box { <BOX PARAMS> } Box { <BOX PARAMS> } Box { <BOX PARAMS> } } Group { numObjects 2 Group { Box { <BOX PARAMS> } Box { <BOX PARAMS> } Box { <BOX PARAMS> } } Group { Box { <BOX PARAMS> } Sphere { <SPHERE PARAMS> } Sphere { <SPHERE PARAMS> } } } Plane { <PLANE PARAMS> } }
Adding Materials Adding Transformations
Using Transformations
n Position the logicalgroupings of objectswithin the scene
n Transformation in group
Directed Acyclic Graphis more efficient and useful
12
Processing ModelTransformattionsn Goaln Get everything into world coordinates
n Traverse graph/tree in depth-first ordern Concatenate transformationsn Can store intermediate transformationsn Apply/associate final transformation to
primitive at leaf noden What about cylinders, superquadrics, etc.?n Transform ray!
Transform the Ray
n Map the ray from World Spaceto Object Space
World Space
r majorr minor
(x,y)
(0,0) Object Space
r = 1
pWS = M pOS
pOS = M-1 pWS
Transforming Points &Directions
n Transform point
n Transform direction
n Map intersection point and normal back toworld coordinates
Homogeneous Coordinates: (x,y,z,w)
W = 0 is a point at infinity (direction)
Why is the Normal important?n It's used for shadingn makes things look 3D!
object color only(Assignment 1)
Diffuse Shading(Assignment 3)
13
Given overlapping shapes A and B:
Union Intersection Subtraction
Constructive Solid Geometry(CSG) For example:
How can we implement CSG?
Points on A,Outside of B
Points on B,Outside of A
Points on B,Inside of A
Points on A,Inside of B
Union Intersection Subtraction
Collect all the intersections
Union Intersection Subtraction
14
Implementing CSG
1. Test "inside" intersections:• Find intersections with A,
test if they are inside/outside B• Find intersections with B,
test if they are inside/outside A
2. Overlapping intervals:• Find the intervals of "inside"
along the ray for A and B• Compute
union/intersection/subtractionof the intervals
Wrap Upn Discuss next programming assignmentn Due 10/24/04
n I am away next week. No class!n Discuss status/problems/issues with
this week’s programming assignment
Recommended