1 / 39

David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory

CS 430/585 Computer Graphics I 3D Clipping Backface Culling, Z-buffering, Ray Casting, Ray Tracing Week 7, Lecture 14. David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University http://gicl.cs.drexel.edu.

lkahn
Download Presentation

David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 430/585Computer Graphics I3D ClippingBackface Culling,Z-buffering,Ray Casting, Ray TracingWeek 7, Lecture 14 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University http://gicl.cs.drexel.edu

  2. Overview • 3D Clipping • Advanced topics • Z-buffering • Back-Face Culling • Ray Tracing (Ray Casting) 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  3. Simple Mesh Format (SMF) • Michael Garland http://graphics.cs.uiuc.edu/~garland/ • Triangle data • Vertex indices begin at 1

  4. 3D Clipping • Cohen-Sutherland and Cyrus-Beck can be trivially extended to 3D • We will cover: • Cohen-Sutherland for 3D, (parallel projection) • Cohen-Sutherland for 3D, (perspective projection)

  5. Line is completely visible iff both code values of endpoints are 0, i.e. If line segments are completely outside the window, then Recall: Cohen-Sutherland Pics/Math courtesy of Dave Mount @ UMD-CP

  6. Cohen-Sutherland for 3D,Parallel Projection • Use 6 bits • Trivially accept if both end-codes are 0 • Trivially reject if bit-by-bit AND of end-codes is not 0 • Up to 6 intersections may have to be computed

  7. Cohen-Sutherland for 3D computing intersection points. • Use parametric representation of the line to compute intersections • So for y=1 replace y with 1 and solve for t • If 1  t  0use it to find x and z • Test if x and z are in valid range • Repeat for planes y=-1, x=1, x=-1, z=-1, z=0

  8. Cohen-Sutherland for 3D, Perspective Projection • Use 6 bits identical to parallel view volume clipping • Conditions on the codes are different • Trivially accept/reject lines using same roles • Intersection points computed differently

  9. Cohen-Sutherland for 3D computing intersection points. • Intersections with planes z=-1, z=zminis the same. • Calculating intersections with a sloping plane … • For plane y=z these two equations are equal • Repeat for planes y=-z, x=z, x=-z

  10. More Efficient Alternative? • Use Cohen-Sutherland to do trivial accept/reject • Project remaining edges onto view plane • Clip lines in 2D

  11. end clipping

  12. Mesh/Faceted Model

  13. Back-Face Culling • Assumptions: • Object approximated as closed polyhedron • Polyhedron interior is not exposed by the front cutting plane • Eye-point not inside object • Polygons not facing the viewer called Back-Facing • Right-hand vertex ordering defines outward normal • Back-Face Culling is a technique for eliminating these polygons • On average eliminates half of the polygons

  14. Back-Face Culling • After projection, examine normal Nk(xk , yk, zk)to the face. • If zk < 0, face is a Back-Face - don’t draw it • More general test looks at Nk•V • V - View vector • The only test necessary for a single convex polyhedron 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  15. Back-Face Culled Wire-Frame

  16. Z-buffering • Z-buffering (depth-buffering) is a visible surface detection algorithm • Implementable in hardware and software • Requires data structure (z-buffer) in addition to frame buffer. • Z-buffer stores values [0 .. ZMAX] corresponding to depth of each point. • If the point is closer than one in the buffers, it will replace the buffered values

  17. Z-buffering + = + = 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  18. Z-buffering for (y = 0; y < YMAX; y++) for (x = 0; x < XMAX; x++) { F[x][y] = BACKGROUND_VALUE; Z[x][y] = ZMIN; } for (each polygon) for (each pixel in polygon’s projection) { pz = polygon’s z-value at pixel coordinates (x,y) if (pz > Z[x][y]) {/* New point is closer */ Z[x][y] = pz; F[x][y] = polygon’s color at pixel coordinates (x,y) } } 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  19. Z-buffering • We can simplify the calculation of z by exploiting the fact that triangle is planar. • Interpolate z values along the edges • Interpolate z values along scan line • Special cases: vertices & horizontal edge 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  20. Back-Face Culled & Z-Buffered Wire-Frame

  21. See the Difference From HW of Andrew Mroczkowski

  22. Depth Cueing • Objects that are closer are brighter • Objects farther away are darker • Color = BaseColor(z - far)/(near - far) www.siggraph.org www.dm.unibo.it/~casciola

  23. Important Reminder • Recall: near and far planes are transformed by Nparand Nper • Parallel projection • Near: z = 0 • Far: z = -1 • Perspective projection • Near: z = • Far: z = -1

  24. Ray Casting (Ray Tracing ) • Determines visible surfaces by tracing rays of light from the viewers eye to the objects in the world.

  25. Ray Casting • Determines visible surfaces by tracing rays of light from the viewers eye to the objects • View plane is divided on the pixel grid • The eye ray is fired from the center of projection through each pixel 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  26. Ray Casting Select the center of projection and viewplane window for (each scan line) { for (each pixel on the scan line) { Find ray from the center of projections through the pixel for (each object in the scene) { if (object is intersected and intersection is closest considered so far) { Record the intersection and the object name } } Set pixel color to that of the closest intersected object } } 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  27. Computing Intersections • Using parametric equation of the line: • Simplifying for speed: • Resulting ray: (x1,y1,z1) (x0,y0,z0) 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  28. Computing Intersections with Sphere • Sphere with radius r and center (a,b,c) is: • Intersection is found by substituting values for (x,y,z) • With some straightforward algebraic transformations: • Equation is quadratic in terms of t • No real roots, No intersection • One real root, Ray grazes the sphere • Two roots, There are two points of intersection 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  29. Computing Intersections with Polygon • First intersect ray with plane • The substitution results in: • If denominator is 0, ray is parallel to the plane • Project polygon and point orthographically on the coordinate plane • Polygon containment test can be performed in 2D 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  30. Polygon Containment Test • Jordan Curve Theorem: • Point is inside if, for any ray, there is an odd number of crossings • Otherwise it is outside • Be careful with all the special cases • Wide variety of other techniques exist

  31. Why Trace Rays? • More elegant • Testbed for techniques: • modeling (reflectance, transport) • rendering (e.g. Monte Carlo) • texturing (e.g. hypertexture) • Easiest photorealistic renderer to implement Boat reflected in wavy water rendered in openGLusing an environment map Compiled from: Lecture notes of Dr. John C. Hart @ University of Illinois

  32. Ray Tracing • Extension of ray casting • Idea: Continue to bounce the ray in the scene • Shoot rays to light sources • Simple and powerful • Reflections, shadows, transparency and multiple light sources • Can be used to produce highly realistic images

  33. Ray Traced Image Blessed State, by Ken Musgrave

  34. cos in - i i i m t t = ? -n To Ray Trace, We Need Refraction • Snell’s Law: i sin i = t sin t • Let  =i/t = sin t / sin i • Let m = (cos in - i) / sin i • Then… t = sintm - cos tn = (sint / sini) (cos in -i) - cos tn = ( cos i- cos t )n -i Can be negative for grazing angles when  >1, say when going from glass to air, resulting in total internal reflection (no refraction). Compiled from: Lecture notes of Dr. John C. Hart @ University of Illinois

  35. Refraction in Action

  36. More Refractions Photon Mapping! Justin Hansen University of Utah Henrik Wann Jensen UC, San Diego

  37. Efficiency Considerations • Partition the bounding box on a regular grid with equal sized extents • Associate each partition with the list of objects contained in it 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  38. Efficiency Considerations • Ray only intersected with the objects contained in the partitions it passes through • If partitions are examined in the order ray travels, we can stop after first intersection is found • Need to check if intersection itself is in the partition 1994 Foley/VanDam/Finer/Huges/Phillips ICG

  39. Computer Graphics II Image produced by Horace Ip

More Related