Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to 3D Graphics Lecture 5: From Realism to Real-Time Anthony Steed University College London.

Similar presentations


Presentation on theme: "Introduction to 3D Graphics Lecture 5: From Realism to Real-Time Anthony Steed University College London."— Presentation transcript:

1 Introduction to 3D Graphics Lecture 5: From Realism to Real-Time Anthony Steed University College London

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

3 Reflection on Ray Casting n 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…) n 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 n 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? n 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) n Projecting the vertices –Needs to be done efficiently n Clipping to the view volume –Triangle might lie partially or totally off the screen n Visible surface determination –We now have to iterate through all the objects to see if they are visible.

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

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

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

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

12 Canonical Frames n We use these as intermediate stages from which we know how to proceed n 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) View volume

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

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

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

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

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

18 Step 3: Change the View Volume into a Regular Pyramid N View plane V N cop V D D Where D = d – c z dx = x 2 – x 1 dy = y 2 – y 1 px = x 2 + x 1 py = y 2 + y 1

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

20 Multiplying Steps 1-4

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

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

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

24 The composite matrix T = MQ

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

26 Clipping Problem n 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) n Clip the polygon against each boundary of the clip region successively n Result is possibly NUL if polygon is outside n Can be generalised to work for any polygonal clip region, not just rectangular Clip to top Clip to right etc

28 Clipping to a Region Boundary n 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 right clip boundary P0P0 P1P1 P2P2 P3P3

29 Clipping the Polygon Edge n Given an edge P 0,P 1 we have 4 case. It can be: –entering the clip region, add P and P 1 –leaving the region, add only P –entirely outside, do nothing –entirely inside, add only P1 n Where P is the point of intersection Visible side of boundary p 0 p 1 p 0 p 0 p 0 p 1 p 1 p 1 p p OUT IN

30 Wrapping Up n We can determine which of the 4 cases and also the point of intersection with just if statements n To sum it up, an example: P0P0 P1P1 P2P2 P3P3 P0P0 PaPa PbPb P3P3

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

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

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

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

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

36 Clipping polygons in 3D n 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 n It can either be done in Projection Space or in Canonical Perspective

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

38 Clipping in Canonical Perspective n 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 V N +1 -1 COP O p1 p2 q1 q2 top bottom View plane projected external lines

39 Clipping in Homogeneous Co-Ordinates n The Sutherland-Hodgman can also be used for clipping in 4D before dividing the points by the w n 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 n Projecting –As an optimisation of ray-casting –New issues and problems n Clipping Polygons –2D –3D n Visibility Culling

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

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

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

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

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

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


Download ppt "Introduction to 3D Graphics Lecture 5: From Realism to Real-Time Anthony Steed University College London."

Similar presentations


Ads by Google