cs 431/636 advanced rendering techniques dr. david breen university crossings 149 tuesday 6pm ...
Post on 26-Dec-2015
213 Views
Preview:
TRANSCRIPT
CS 431/636 Advanced Rendering Techniques
Dr. David Breen
University Crossings 149
Tuesday 6PM 8:50PM
Presentation 2
4/7/09
Start Up
Any questions from last time? Go over sampling image plane? Or intersection algorithms?
Slide Credits
Leonard McMillan, Seth Teller, Fredo Durand, Barb Cutler - MIT
G. Drew Kessler, Larry Hodges - Georgia Institute of Technology
John Hart - University of Illinois Rick Parent - Ohio State University
More Geometry & Intersections
Ray/Plane Intersection
Ray 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 plane
Normal Vector, N = [A, B, C] (unit vector)
A2 + B2 + C2 = 1
D = - N • P0 (P0 - point in plane)
Ray/Plane (cont.)
Substitute the ray equation into the plane equation:
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 - N • P0 ) / (N • Rd)
What Can Happen?
N • Rd = 0N • Rd > 0
t < 0
Ro
t > 0
Ro
Ray/Plane Summary
Intersection point:(xi, yi, zi) = (xo + xdti, yo + ydti, zo + zdti)
n Calculate N • Rd and compare it to zero.
n Calculate ti and compare it to zero.
n Compute intersection point.n Flip normal if N • Rd is positive
Ray-Parallelepiped Intersection Axis-aligned From (X1, Y1, Z1) to (X2, Y2, Z2) Ray P(t)=Ro+Rdt
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
Naïve ray-box Intersection Use 6 plane equations Compute all 6 intersection Check that points are inside box
Ax+By+Cz+D ≤ 0
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
Factoring out computation Pairs of planes have the same
normal Normals have only one non-0
component Do computations one dimension at a
time Maintain tnear and tfar (closest and
farthest so far)
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
Test if parallel
If Rdx = 0, then ray is parallel If Rox < X1 or Rox > x2 return false
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
If not parallel
Calculate intersection distance t1 and t2 t1 = (X1-Rox)/Rdx
t2 = (X2-Rox)/Rdx
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
t1
t2
Test 1 Maintain tnear and tfar
If t1 > t2, swap if t1 > tnear, tnear = t1 if t2 < tfar, tfar = t2
If tnear > tfar, box is missed
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
t1x t2xtnear
t1y
t2ytfar
tfar
Test 2
If tfar < 0, box is behind
y=Y2
y=Y1
x=X1 x=X2
Ro
Rd
t1xt2xtfar
Algorithm recap Do for all 3 axes
Calculate intersection distance t1 and t2 Maintain tnear and tfar If tnear > tfar, box is missed If tfar < 0, box is behind
If box survived tests, return intersection at tnear
If tnear is negative, return tfar
y=Y2
y=Y1
x=X1 x=X2Ro
Rd
tnear
t1y
tfar
Ray/Ellipsoid Intersection Ray/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 surface equations
This is a quadratic equation in t: At2 + Bt + C = 0
Analyze as before Solve for t with quadratic formula Plug t back into ray equation - Done Well,… not exactly
Ray/Ellipsoid Intersection Ray/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?
Superquadrics
€
x
a1
⎛
⎝ ⎜
⎞
⎠ ⎟
2ε 2
+y
a2
⎛
⎝ ⎜
⎞
⎠ ⎟
2ε 2
⎡
⎣
⎢ ⎢
⎤
⎦
⎥ ⎥
ε 2ε1
+z
a3
⎛
⎝ ⎜
⎞
⎠ ⎟
2ε1
=1
Bezier Patch Patch of order (n, m) can be defined in terms of a set
of (n + 1)(m + 1) control points Pi+1,j+1 for integer indices i = 0 to n, j = 0 to m.
€
(u,v)∈ [0,1]2
p(u,v) =i= 0
n
∑ Bin (u)B j
m (v)j= 0
m
∑ Pi+1, j +1
Bin (u) =
n
i
⎛
⎝ ⎜
⎞
⎠ ⎟u
i(1− u)n−i
Tesselate Patches and Superquadrics
Tesselate Patches and Superquadrics
Utah Teapot
Modeled by 32 Bézier Patches Control points available at
http://www.holmes3d.net/graphics/teapot
SMF Triangle Meshesv -1 -1 -1v 1 -1 -1 v -1 1 -1 v 1 1 -1 v -1 -1 1 v 1 -1 1 v -1 1 1 v 1 1 1 f 1 3 4 f 1 4 2 f 5 6 8 f 5 8 7 f 1 2 6 f 1 6 5 f 3 7 8 f 3 8 4 f 1 5 7 f 1 7 3 f 2 4 8 f 2 8 6
vertices
triangles
Draw data structure
Triangle Meshes (.iv)
Transformations & Hierarchical Models
Add an extra dimension• in 2D, we use 3 x 3 matrices• In 3D, we use 4 x 4 matrices
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
Most of the time w = 1, and we can ignore 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)
Why bother with the extra dimension?Because now translations can 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) Isotropic (uniform)
scaling: sx = sy = sz
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
Rotation
About z axis
x'
y'
z'
1
=
x
y
z
1
cos
sin
0
0
-sin
cos
0
0
0
0
1
0
0
0
0
1
ZRotate()
x
y
z
p
p'
θ
Rotation
About x axis:
About y axis:
x'
y'
z'
1
=
x
y
z
1
0
cos sin
0
0
-sin cos
0
1
0
0
0
0
0
0
1
x'
y'
z'
1
=
x
y
z
1
cos 0
-sin 0
sin 0
cos 0
0
1
0
0
0
0
0
1
Rotation 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 & s = sin
Rotate(k, )
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
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 Modeling
Position objects in a scene Change the shape of objects Create multiple copies of objects Projection for virtual cameras Animations
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
Logical organization of scene
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> } }
Simple Example with Groups
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
Position the logical groupings of objects within the scene
Transformation in group
Directed Acyclic Graph is more efficient and useful
Processing Model Transformattions
Goal Get everything into world coordinates
Traverse graph/tree in depth-first order Concatenate transformations Can store intermediate transformations Apply/associate final transformation to
primitive at leaf node What about cylinders, superquadrics, etc.?
Transform ray!
Transform the Ray
Map the ray from World Space to Object Space
World Space
r major
r minor
(x,y)
(0,0) Object Space
r = 1
pWS = M pOS
pOS = M-1 pWS
Transform Ray New origin:
New direction:
originOS = M-1 originWS
directionOS = M-1 (originWS + 1 * directionWS) - M-1 originWS
originOS
originWS
directionOS
directionWS
Object SpaceWorld Space
qWS = originWS + tWS * directionWS
qOS = originOS + tOS * directionOS
directionOS = M-1 directionWS
Transforming Points & Directions
Transform point
Transform direction
Map intersection point and normal back to
world coordinates
Homogeneous Coordinates: (x,y,z,w)
W = 0 is a point at infinity (direction)
Transform Normals Why? They’re used for shading
object color only Diffuse Shading
Transforming Normals A surface normal is a property, not a
geometric entity
Correct normal transformation matrix:
See http://www.cgafaq.info/wiki/Transforming_Normals
Given overlapping shapes A and B:
Union Intersection Subtraction
Constructive Solid Geometry (CSG)
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
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
Constructive Solid Geometry
Ray Tracing CSG Models
Rick ParentOhio State U.
CSG Form object as booleans of primitive objects
Primitives: sphere, cube, cylinder, cone Boolean operators: union, intersection, difference
Tree structure used to manage operations Leaf nodes are primitive objects Intermediate nodes specify combination operator
CSE 681
Union
Min (tCmin, tB
min )
B
C +
BC
Ray intersects union: at first intersection
Possible ways for 2 spans to overlap
Intersection
++
If ((tCmin< tB
min ) and (tCmax> tB
min ) ): tBmin
Else If ((tBmin< tC
min ) and (tBmax> tC
min ) ): tCmin
Else: none
BC
B
C
First time in B and in C
Difference
-+
BC
If ((tBmin< tC
min ): tBmin
Else if (tCmax< tB
max ): tCmax
Else: none
B
C
First time in B not in C
Difference
+-
BC
If ((tCmin< tB
min): tCmin
Else if (tBmax< tC
max ): tBmax
Else: none
B
C
First time in C not in B
PrimitivesAnything that can be intersected (easily) with a ray
Conics: solve analytically using R(t)Convex polyhedraA plane (a cutting plane is useful)
can be used as a modeling tool (boolean operations) surface model (e.g., polyhedron) computed from CGS
or Can be used as a model representation
keep tree structure and ray trace directly
Controlling the Combinations
-+
+
?
Tree Structure
circlerectangle rectangle
+ +
+ -
T1T2 T3
T4
T5- +
+T1
T2
T3
Tree Structure #1
Tree Structure
circlerectangle rectangle
+ +
- +
T1T2 T3
T4
T5- +
+T1
T2
T3
Tree Structure #2
Tree Structure
• Intersect ray with leaf nodes (primitive objects)• Combine intersection spans according to intermediate nodes
• union• intersection• difference
• Might create multiple spans
Union of Spans
Intersection of Spans
Difference of Spans
Normals of CSG intersections
Normal of some surface (or its negation)
Union or intersection: positive normal of intersected surface
Difference normals
• Intersection is one of:• tmin of positive object – normal of surface• tmax of negative object – negated normal
Add transformations to tree
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/model/csg.html
CSE 681
Bounding Volumes
circlerectangle rectangle
+ +
+ -
T1T2 T3
T4
T5
Construction•Use bounding volumes at leaf nodes• Union bounding volumes at interior nodes
Traversal•Top-down•Test bounding volume at interior
Example
Example
Example (Simon Chorley)
Example (Simon Chorley)
For example:
Wrap Up
Discuss status/problems/issues with this week’s programming assignment
top related