Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 431/636 Advanced Rendering Techniques Dr. David Breen University Crossings 149 Tuesday 6PM  8:50PM Presentation 2 4/7/09.

Similar presentations


Presentation on theme: "CS 431/636 Advanced Rendering Techniques Dr. David Breen University Crossings 149 Tuesday 6PM  8:50PM Presentation 2 4/7/09."— Presentation transcript:

1 CS 431/636 Advanced Rendering Techniques Dr. David Breen University Crossings 149 Tuesday 6PM  8:50PM Presentation 2 4/7/09

2 Start Up Any questions from last time? Go over sampling image plane? Or intersection algorithms?

3 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

4 More Geometry & Intersections

5 Ray/Plane Intersection Ray is defined by R(t) = R o + R d *t where t  0 R o = Origin of ray at (x o, y o, z o ) R d = Direction of ray [x d, y d, z d ] (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) A 2 + B 2 + C 2 = 1 D = - N P 0 (P 0 - point in plane)

6 Ray/Plane (cont.) Substitute the ray equation into the plane equation: A(x o + x d t) + B(y o + y d t) + C(z o +z d t) + D = 0 Solve for t: t = -(Ax o + By o + Cz o + D) / (Ax d + By d + Cz d ) t = -(N R o - N P 0 ) / (N R d )

7 What Can Happen? N R d = 0 N R d > 0 t < 0 RoRo t > 0 RoRo

8 Ray/Plane Summary Intersection point: (x i, y i, z i ) = (x o + x d t i, y o + y d t i, z o + z d t i ) 1. Calculate N R d and compare it to zero. 2. Calculate t i and compare it to zero. 3. Compute intersection point. 4. Flip normal if N R d is positive

9 Ray-Parallelepiped Intersection Axis-aligned From (X1, Y1, Z1) to (X2, Y2, Z2) Ray P(t)=R o +R d t y=Y2 y=Y1 x=X1x=X2 RoRo RdRd

10 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=X1x=X2 RoRo RdRd

11 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 t near and t far (closest and farthest so far) y=Y2 y=Y1 x=X1x=X2 RoRo RdRd

12 Test if parallel If R d x = 0, then ray is parallel If R o x x2 return false y=Y2 y=Y1 x=X1x=X2 RoRo RdRd

13 If not parallel Calculate intersection distance t1 and t2 t1 = (X1-R o x)/R d x t2 = (X2-R o x)/R d x y=Y2 y=Y1 x=X1x=X2 RoRo RdRd t1 t2

14 Test 1 Maintain t near and t far If t1 > t2, swap if t1 > t near, t near = t1 if t2 < t far, t far = t2 If t near > t far, box is missed y=Y2 y=Y1 x=X1x=X2 RoRo RdRd t1x t2x tnear t1y t2y tfar

15 Test 2 If t far < 0, box is behind y=Y2 y=Y1 x=X1x=X2 RoRo RdRd t1x t2x tfar

16 Algorithm recap Do for all 3 axes Calculate intersection distance t1 and t2 Maintain t near and t far If t near > t far, box is missed If tfar < 0, box is behind If box survived tests, return intersection at t near If t near is negative, return t far y=Y2 y=Y1 x=X1x=X2 RoRo RdRd tnear t1y tfar

17 Ray/Ellipsoid Intersection Ray/Cylinder Intersection Ellipsoid's surface is defined by the set of points {(x s, y s, z s )} satisfying the equation: (x s / a) 2 + (y s / b) 2 + (z s / c) 2 - 1 = 0 Cylinder's surface is defined by the set of points {(x s, y s, z s )} satisfying the equation: (x s ) 2 + (y s ) 2 - r 2 = 0-z 0 ≤ z s ≤ z 0 Centers at origin

18  Substitute ray equation into surface equations  This is a quadratic equation in t:  At 2 + 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

19 Ray/Cylinder Intersection  Is intersection point P i between -Z 0 and Z 0 ?  If not, P i is not valid  Also need to do intersection test with z = -Z 0, Z 0 plane  If (P i x) 2 + (P i y) 2 ≤ r 2, you’ve intersected a “cap”  Which valid intersection is closer?

20

21 Superquadrics

22 Bezier Patch Patch of order (n, m) can be defined in terms of a set of (n + 1)(m + 1) control points P i+1,j+1 for integer indices i = 0 to n, j = 0 to m.

23 Tesselate Patches and Superquadrics

24

25 Utah Teapot Modeled by 32 Bézier Patches Control points available at http://www.holmes3d.net/graphics/teapot

26 SMF Triangle Meshes v -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 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

27 Triangle Meshes (.iv)

28 Transformations & Hierarchical Models

29 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' = xyzwxyzw aeimaeim bfjnbfjn cgkocgko dhlpdhlp p' = M p

30 Most of the time w = 1, and we can ignore it Homogeneous Coordinates x' y' z' 1 = xyz1xyz1 aei0aei0 bfj0bfj0 cgk0cgk0 dhl1dhl1

31 Translate (t x, t y, t z ) 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 = xyz1xyz1 10001000 01000100 00100010 txtytz1txtytz1 x' y' z'

32 Scale (s x, s y, s z ) Isotropic (uniform) scaling: s x = s y = s z You only have to implement uniform scaling x' y' z' 1 = xyz1xyz1 sx000sx000 0sy000sy00 00sz000sz0 00010001 Scale(s,s,s) x p p' q q' y

33 Rotation About z axis x' y' z' 1 = xyz1xyz1 cos  sin  0 -sin  cos  0 00100010 00010001 ZRotate(  ) x y z p p' θ

34 Rotation About x axis: About y axis: x' y' z' 1 = xyz1xyz1 0 cos  sin  0 -sin  cos  0 10001000 00010001 x' y' z' 1 = xyz1xyz1 cos  0 -sin  0 sin  0 cos  0 01000100 00010001

35 Rotation About (k x, k y, k z ), an arbitrary unit vector (Rodrigues Formula) x' y' z' 1 = xyz1xyz1 k x k x (1-c)+c k y k x (1-c)+k z s k z k x (1-c)-k y s 0 00010001 k y k x (1-c)-k z s k y k y (1-c)+c k z k y (1-c)+k x s 0 k x k z (1-c)+k y s k y k z (1-c)-k x s k z k z (1-c)+c 0 where c = cos  & s = sin  Rotate(k,  ) x y z θ k

36 How are transforms combined? (0,0) (1,1) (2,2) (0,0) (5,3) (3,1) Scale(2,2)Translate(3,1) TS = 2020 0202 0000 1010 0101 3131 2020 0202 3131 = Scale then Translate Use matrix multiplication: p' = T ( S p ) = ((TS) p) Caution: matrix multiplication is NOT commutative! 001001001

37 Non-commutative Composition Scale 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) Scale(2,2)

38 TS = 200200 020020 001001 100100 010010 311311 ST = 2020 0202 0000 1010 0101 3131 Non-commutative Composition Scale then Translate: p' = T ( S p ) = TS p 200200 020020 311311 2020 0202 6262 = = Translate then Scale: p' = S ( T p ) = ST p 001 001001

39 Transformations in Ray Tracing

40 Transformations in Modeling Position objects in a scene Change the shape of objects Create multiple copies of objects Projection for virtual cameras Animations

41 Scene Description Scene LightsCameraObjects Materials Background

42 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 } Group { numObjects }

43 Hierarchical Models Logical organization of scene

44 Group { numObjects 3 Group { numObjects 3 Box { } Box { } } Group { numObjects 2 Group { Box { } Box { } } Group { Box { } Sphere { } Sphere { } } } Plane { } } Simple Example with Groups

45 Group { numObjects 3 Group { numObjects 3 Box { } Box { } } Group { numObjects 2 Group { Box { } Box { } } Group { Box { } Sphere { } Sphere { } } } Plane { } } Adding Materials

46 Adding Transformations

47 Using Transformations Position the logical groupings of objects within the scene Transformation in group

48 Directed Acyclic Graph is more efficient and useful

49 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!

50 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 p WS = M p OS p OS = M -1 p WS

51 Transform Ray New origin: New direction: origin OS = M -1 origin WS direction OS = M -1 (origin WS + 1 * direction WS ) - M -1 origin WS origin OS origin WS direction OS direction WS Object Space World Space q WS = origin WS + t WS * direction WS q OS = origin OS + t OS * direction OS direction OS = M -1 direction WS

52 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)

53 Transform Normals Why? They’re used for shading object color onlyDiffuse Shading

54 Transforming Normals A surface normal is a property, not a geometric entity Correct normal transformation matrix: See http://www.cgafaq.info/wiki/Transforming_Normals

55 Given overlapping shapes A and B: Union Intersection Subtraction Constructive Solid Geometry (CSG)

56 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

57 Collect all the intersections Union Intersection Subtraction

58 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/subtraction of the intervals

59 Constructive Solid Geometry Ray Tracing CSG Models Rick Parent Ohio State U.

60 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

61 CSE 681 Union Min (t C min, t B min ) B C + B C Ray intersects union: at first intersection

62 Possible ways for 2 spans to overlap

63 Intersection ++ If ((t C min t B min ) ): t B min Else If ((t B min t C min ) ): t C min Else: none B C B C First time in B and in C

64 Difference -+ B C If ((t B min < t C min ): t B min Else if (t C max < t B max ): t C max Else: none B C First time in B not in C

65 Difference +- B C If ((t C min < t B min ): t C min Else if (t B max < t C max ): t B max Else: none B C First time in C not in B

66 Primitives Anything that can be intersected (easily) with a ray Conics: solve analytically using R(t) Convex polyhedra A 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

67 Controlling the Combinations - + + ?

68 Tree Structure circle rectangle + + + - T1 T2 T3 T4 T5 - + + T1 T2 T3

69 Tree Structure #1

70 Tree Structure circle rectangle + + - + T1 T2 T3 T4 T5 - + + T1 T2 T3

71 Tree Structure #2

72 Tree Structure Intersect ray with leaf nodes (primitive objects) Combine intersection spans according to intermediate nodes union intersection difference Might create multiple spans

73 Union of Spans

74 Intersection of Spans

75 Difference of Spans

76 Normals of CSG intersections Normal of some surface (or its negation) Union or intersection: positive normal of intersected surface

77 Difference normals Intersection is one of: t min of positive object – normal of surface t max of negative object – negated normal

78 Add transformations to tree http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/model/csg.html

79 CSE 681 Bounding Volumes circle rectangle + + + - T1 T2 T3 T4 T5 Construction Use bounding volumes at leaf nodes Union bounding volumes at interior nodes Traversal Top-down Test bounding volume at interior

80 Example

81

82 Example (Simon Chorley)

83

84 For example:

85 Wrap Up Discuss status/problems/issues with this week’s programming assignment


Download ppt "CS 431/636 Advanced Rendering Techniques Dr. David Breen University Crossings 149 Tuesday 6PM  8:50PM Presentation 2 4/7/09."

Similar presentations


Ads by Google