# cs 431/636 advanced rendering techniques

Post on 31-Dec-2015

45 views

Category:

## Documents

Embed Size (px)

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

• CS 431/636 Advanced Rendering TechniquesDr. David BreenUniversity Crossings 149Tuesday 6PM 8:50PMPresentation 24/7/09

• Start UpAny questions from last time?Go over sampling image plane?Or intersection algorithms?

• Slide CreditsLeonard McMillan, Seth Teller, Fredo Durand, Barb Cutler - MITG. Drew Kessler, Larry Hodges - Georgia Institute of TechnologyJohn Hart - University of IllinoisRick Parent - Ohio State University

• More Geometry & Intersections

• Ray/Plane IntersectionRay is defined by R(t) = Ro + Rd*t where t 0Ro = 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 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?

• Ray/Plane SummaryIntersection point:(xi, yi, zi) = (xo + xdti, yo + ydti, zo + zdti)

Calculate N Rd and compare it to zero.Calculate ti and compare it to zero.Compute intersection point.Flip normal if N Rd is positive

• Ray-Parallelepiped IntersectionAxis-alignedFrom (X1, Y1, Z1) to (X2, Y2, Z2)Ray P(t)=Ro+Rdty=Y2y=Y1x=X1x=X2RoRd

• Nave ray-box IntersectionUse 6 plane equationsCompute all 6 intersectionCheck that points are inside box Ax+By+Cz+D 0

• Factoring out computationPairs of planes have the same normalNormals have only one non-0 componentDo computations one dimension at a timeMaintain tnear and tfar (closest and farthest so far)

• Test if parallelIf Rdx = 0, then ray is parallelIf Rox < X1 or Rox > x2 return falsey=Y2y=Y1x=X1x=X2RoRd

• If not parallelCalculate intersection distance t1 and t2t1 = (X1-Rox)/Rdxt2 = (X2-Rox)/Rdx

• Test 1Maintain tnear and tfarIf t1 > t2, swapif t1 > tnear, tnear = t1 if t2 < tfar, tfar = t2If tnear > tfar, box is missed

• Test 2If tfar < 0, box is behindy=Y2y=Y1x=X1x=X2RoRdt1xt2xtfar

• Algorithm recapDo for all 3 axesCalculate intersection distance t1 and t2Maintain tnear and tfarIf tnear > tfar, box is missedIf tfar < 0, box is behindIf box survived tests, return intersection at tnearIf tnear is negative, return 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 equationsThis is a quadratic equation in t: At2 + Bt + C = 0Analyze as beforeSolve for t with quadratic formulaPlug t back into ray equation - DoneWell, not exactlyRay/Ellipsoid Intersection Ray/Cylinder Intersection

• Ray/Cylinder Intersection Is intersection point Pi between -Z0 and Z0?If not, Pi is not validAlso need to do intersection test with z = -Z0 , Z0 planeIf (Pix)2 + (Piy)2 r2, youve intersected a capWhich valid intersection is closer?

• Bezier PatchPatch 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.

• Utah TeapotModeled by 32 Bzier PatchesControl 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 6verticestrianglesDraw data structure

• Triangle Meshes (.iv)

• Transformations & Hierarchical Models

• Add an extra dimensionin 2D, we use 3 x 3 matricesIn 3D, we use 4 x 4 matricesEach point has an extra value, wHomogeneous Coordinates

• Most of the time w = 1, and we can ignore it

Homogeneous Coordinates

• Translate (tx, ty, tz)Why bother with the extra dimension? Because now translations can be encoded in the matrix!Translate(c,0,0)xypp'c

• Scale (sx, sy, sz)Isotropic (uniform) scaling: sx = sy = sz

You only have to implement uniform scalingScale(s,s,s)xpp'qq'y

• RotationAbout z axisx'y'z'1=xyz1cos sin 00-sin cos 0000100001ZRotate()xyzpp'

• Rotation

• RotationAbout (kx, ky, kz), an arbitrary unit vector (Rodrigues Formula)

where c = cos & s = sin Rotate(k, )xyzk

• How are transforms combined?(0,0)(1,1)(2,2)(0,0)(5,3)(3,1)Scale(2,2)Translate(3,1)TS =20

02

00

10

01

31

20

02

31

=Scale then TranslateUse matrix multiplication: p' = T ( S p ) = ((TS) p)Caution: matrix multiplication is NOT commutative!

• Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS pTranslate 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 =200020001100010311ST =20

02

00

10

01

31

Non-commutative CompositionScale then Translate: p' = T ( S p ) = TS p20002031120

02

62

==Translate then Scale: p' = S ( T p ) = ST p

• Transformations in Ray Tracing

• Transformations in ModelingPosition objects in a sceneChange the shape of objectsCreate multiple copies of objectsProjection for virtual camerasAnimations

• Scene DescriptionSceneLightsCamera

ObjectsMaterialsBackground

• Simple Scene Description FileCamera { 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 }

• Hierarchical Models

Logical organization of scene

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

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

• Using TransformationsPosition the logical groupings of objects within the scene

Transformation in group

• Directed Acyclic Graph is more efficient and useful

• Processing Model TransformattionsGoalGet everything into world coordinatesTraverse graph/tree in depth-first orderConcatenate transformationsCan store intermediate transformationsApply/associate final transformation to primitive at leaf nodeWhat about cylinders, superquadrics, etc.?Transform ray!

• Transform the RayMap the ray from World Space to Object SpacepWS = M pOSpOS = M-1 pWS

• Transform RayNew origin:

New direction:originOS = M-1 originWSdirectionOS = M-1 (originWS + 1 * directionWS) - M-1 originWSoriginOSoriginWSdirectionOSdirectionWSObject SpaceWorld Space qWS = originWS + tWS * directionWS qOS = originOS + tOS * directionOSdirectionOS = M-1 directionWS

• Transforming Points & DirectionsTransform point

Transform direction

Map intersection point and normal back to world coordinatesHomogeneous Coordinates: (x,y,z,w)W = 0 is a point at infinity (direction)

• Transform NormalsWhy? Theyre used for shading

• Transforming NormalsA 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 SubtractionConstructive Solid Geometry (CSG)

• How can we implement CSG?Points on A, Outside of BPoints on B, Outside of APoints on B, Inside of APoints on A, Inside of B

Union Intersection Subtraction

• Collect all the intersections

Union Intersection Subtraction

• Implementing CSGTest "inside" intersections:Find intersections with A, test if they are inside/outside BFind intersections with B, test if they are inside/outside A

Overlapping intervals:Find the intervals of "inside" along the ray for A and BCompute union/intersection/subtraction of the intervals

• Constructive Solid Geometry

Ray Tracing CSG Models

Rick ParentOhio State U.

• CSGForm object as booleans of primitive objectsPrimitives: sphere, cube, cylinder, coneBoolean operators: union, intersection, differenceTree structure used to manage operationsLeaf nodes are primitive objectsIntermediate nodes specify combination operator

• CSE 681UnionMin (tCmin, tBmin )BCRay intersects un

Recommended