1 / 46

Introduction to 3D Graphics Lecture 5: From Realism to Real-Time

Introduction to 3D Graphics Lecture 5: From Realism to Real-Time. Anthony Steed University College London. Overview. Projecting As an optimisation of ray-casting New issues and problems Clipping Polygons 2D 3D Visibility Culling. Reflection on Ray Casting.

soniawhite
Télécharger la présentation

Introduction to 3D Graphics Lecture 5: From Realism to Real-Time

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. Introduction to 3D GraphicsLecture 5: From Realism to Real-Time Anthony Steed University College London

  2. Overview • Projecting • As an optimisation of ray-casting • New issues and problems • Clipping Polygons • 2D • 3D • Visibility Culling

  3. Reflection on Ray Casting • The process of casting rays is very slow • E.G. for a cow we have 10,000 triangles, but to render a 1000x1000 pixel image we have 10000000 primary rays to cast (and then reflections, shadow rays, etc…) • Exploit point coherency • If ray through pixel (x,y) hits triangle T, then rays through adjacent pixels will likely hit the same triangle

  4. Think Optimisation • But although point coherency is useful, we can easily enumerate ALL the rays that hit the triangle • Find which rays would hit the vertices of the triangle • These rays are defined by a 2D triangle on the image plane • Scan this 2D triangle out

  5. COP

  6. Why Triangles? • In general for an object representation (bezier, CSG) is it far from easy to find the 2D projection of the shape

  7. Projection Problems (1) • Projecting the vertices • Needs to be done efficiently • Clipping to the view volume • Triangle might lie partially or totally off the screen • Visible surface determination • We now have to iterate through all the objects to see if they are visible.

  8. Projection Problems (2) • Lighting • Now we have to re-construct the lighting across the screen • Depth test determination • Have to cope with overlapping and potential “difficult” coverage relations • Shadows and Inter-Reflections • Much more complicated

  9. Full camera specification • We have already seen: • VRP, VPN, VUV, COP, view plane window • Some more parameters: • Viewplane Distance • Type of projection • Perspective – all rays converge to the COP • Parallel – parallel rays from points in the scene (DOP) • Front and back clip planes

  10. Full Camera V truncated View Volume COP view window N VRP=O back clipping plane front clipping plane VP

  11. Perspective Projection • In order to get a natural looking image we need the perspective • For a simple arrangement it is easy to find the projection Y P Q COP Z C A O viewplane

  12. We use these as intermediate stages from which we know how to proceed Canonical Perspective: Cop at (0,0,-1) Viewplane coincident with U-V plane Viewplane window bounded by –1 to +1 p’ = (x/z+1, y/z+1, 0) Canonical Frames View volume

  13. Canonical Parallel • Orthographic parallel projection • Direction of projection (DOP) is (0,0,-1) • View volume bounded by –1 and +1 on U and V • And by 0 and 1 on the N axis • p’ = (x, y, 0) View volume V + DOP

  14. From General Perspective to Canonical Parallel (Projection Space) +

  15. Perspective to Canonical Perspective • We will apply a set of transformation matrices (4 in total) • Each one ‘corrects’ a particular aspect of the projection • Then we put them all together to get one matrix

  16. V N View plane Step 1: Move the View Plane to the UV Plane (n = 0) V cop cop d N View plane

  17. V N View plane Step 2: Translate the COP so that it Lies on the N axis V cop N cop View plane

  18. V V D N N cop cop D View plane Step 3: Change the View Volume into a Regular Pyramid Where D = d – cz dx = x2 – x1 dy = y2 – y1 px = x2 + x1 py = y2 + y1

  19. Step 4: Scale by 1/D V V 1 D N N cop cop 1 D

  20. Multiplying Steps 1-4

  21. Canonical Perspective To Canonical Parallel • Projection space • Divide through by Z • Incorporation of front and back clipping planes (canonical parallel) + + Dmax 1 Dmin 0

  22. Projection Space • A use for the right hand column! • x maps to x/z+1

  23. Incorporate Front and Back Clipping Planes • (Actually this step occurs before the previous one)

  24. The composite matrix T = MQ

  25. Overview • Projecting • As an optimisation of ray-casting • New issues and problems • Clipping Polygons • 2D • 3D • Visibility Culling

  26. Clipping Problem • Once we start projecting polygons we have to cope with cases where only some of the vertices project to the view window

  27. Sutherland-Hodgman Algorithm(2D) Clip to top • Clip the polygon against each boundary of the clip region successively • Result is possibly NUL if polygon is outside • Can be generalised to work for any polygonal clip region, not just rectangular Clip to right etc

  28. P2 P1 P0 P3 Clipping to a Region Boundary right clip boundary • To find the new polygon • iterate through each of the polygon edges and construct a new sequence of points • starting with an empty sequence • for each edge there are 4 possible cases to consider clip region

  29. p 1 p 0 p 1 p 0 p 1 p 0 p p 1 0 Clipping the Polygon Edge • Given an edge P0,P1 we have 4 case. It can be: • entering the clip region, add P and P1 • leaving the region, add only P • entirely outside, do nothing • entirely inside, add only P1 • Where P is the point of intersection V i s i b l e s i d e o f b o u n d a r y p p OUT IN

  30. P1 P2 P0 P3 Wrapping Up • We can determine which of the 4 cases and also the point of intersection with just if statements • To sum it up, an example: Pa Pb P0 P3

  31. Weiler-Atherton Algorithm • When we have non-convex polygons then the algorithm above might produce polygons with coincident edges • This is fine for rendering but maybe not for other applications (eg shadows) • The Weiler-Atherton algorithm produces separate polygons for each visible fragment

  32. polygon 1 2 B 8 7 i j a b 0 9 6 k 5 A 4 l 3 c d clip region Weiler-Atherton Algorithm 0 1 a 2 3 b 4 5 c 6 7 d 8 loop of region vertices 9 loop of polygon vertices

  33. polygon 1 2 B 8 7 i j a b 0 9 6 k 5 A 4 l 3 c d clip region After Inserting the first Intersection Vertex i 0 1 i a 2 3 l b 4 5 k c 6 7 j d 8 9

  34. polygon 1 2 B 8 7 i j a b 0 9 6 k 5 A 4 l 3 c d clip region After Insertion of all Intersection Vertices 0 1 i a 2 3 l b 4 5 k c 6 7 j d 8 9

  35. Collect Your Polygons • Traverse the vertex list from the top • When the intersection point is an exit switch to traversing the clip boundary • When the intersection point is an entry switch to traversing the polygon vertices

  36. Clipping polygons in 3D • The Sutherland-Hodgman can easily be extended to 3D • the clipping boundaries are 6 planes instead of 4 lines • intersection calculation is done by comparing an edge to a plane instead of edge to edge • It can either be done in Projection Space or in Canonical Perspective

  37. Clipping in Projection Space • The view volume is defined by:

  38. Clipping in Canonical Perspective • When we have an edge that extends from the front to behind the COP, then if we perform the clipping after the projection of the points (which in effect is what the PS does) we might get wrong results top View plane V + 1 p 2 p 1 q 1 projected external lines N O C O P q 2 - 1 bottom

  39. Clipping in Homogeneous Co-Ordinates • The Sutherland-Hodgman can also be used for clipping in 4D before dividing the points by the w • This can have the advantage that is even more general, it even allows for the front clip plane to be behind the COP

  40. Overview • Projecting • As an optimisation of ray-casting • New issues and problems • Clipping Polygons • 2D • 3D • Visibility Culling

  41. Visibility Problem • Not all objects are visible • In ray-tracing only rays inside the view frustum could be created • Not all polygons are visible • Visibility “solved” by default by ray-tracing because of object intersection test • Visibility ordering is a problem • Ray-tracing “solved” this problem implicitly because closest ray intersection point was chosen

  42. Object Culling • Any object outside the view frustum can be discarded • Bounding sphere/plane test is common • Remaining objects must be sent to clipping process

  43. Back Face Culling • Polygons facing away from the COP can be discarded • Often over-ridden to model thin walled objects COP

  44. List Priority Algorithms • Must sort the objects (or polygons or pixels) • Commonest approach is to sort the objects on their distance from the COP (z-sort)

  45. Order of Polygons • For a single closed polyhedron ANY order of polygon drawing is correct • With multiple overlapping objects z-sort the individual polygons • Special cases galore! • In general these techniques are not sufficient, and we will buffer individual pixels with a z-buffer

  46. Conclusion • We have moved a considerable way from realism to real-time • Reduced a 3D problems to a 2D problem (via a 4D problem!) • Remaining issues • Filling polygons to cope with local illumination and visibility

More Related