Hidden surface removal v Clipping algorithms will discard

  • Slides: 31
Download presentation
Hidden surface removal v Clipping algorithms will discard objects or parts of objects that

Hidden surface removal v Clipping algorithms will discard objects or parts of objects that are outside of the viewing volume v But, that does not solve the problem of one objects blocking the view of another object v Hidden surface algorithms deal with this problem v Some algorithms are more correctly called visible surface algorithms but the two names are used interchangeably. 21/10/2005 Lecture 9

Visibility of primitives v We don’t want to waste time rendering primitives which don’t

Visibility of primitives v We don’t want to waste time rendering primitives which don’t contribute to the final image. v A scene primitive can be invisible for 3 reasons: v. Primitive lies outside field of view v. Primitive is back-facing (under certain conditions) v. Primitive is occluded by one or more objects nearer the viewer v How do we remove these efficiently? v How do we identify these efficiently? 21/10/2005 Lecture 9

The visibility problem. Removal of faces facing away from the viewer. Removal of faces

The visibility problem. Removal of faces facing away from the viewer. Removal of faces obscured by closer objects. 21/10/2005 Lecture 9 3

Visible surface algorithms. Hidden/Visible Surface/Line Elimination/Determination v Requirements v Handle diverse set of geometric

Visible surface algorithms. Hidden/Visible Surface/Line Elimination/Determination v Requirements v Handle diverse set of geometric primitives v Handle large number of geometric primitives Classification: Sutherland, Sproull, Schumacher (1974): v Object Space v Geometric calculations involving polygons v Floating point precision: Exact v Often process scene in object order v Image Space v Visibility at pixel samples v Integer precision v Often process scene in image order 21/10/2005 Lecture 9

Visible surface algorithms. Object based methods v Consider objects pairwise at a time, do

Visible surface algorithms. Object based methods v Consider objects pairwise at a time, do it iteratively, comparing each polygon with the rest of polygons: v A and B both completely visible – display both v A completely obscure B – display only A (vice versa) v A and B partially obscure each other – calculate visible parts of each polygon v Complexity is O(k 2) – regard the determination of which case it is and any required calculation of visible parts of each polygon as a single operation Image based methods v per pixel, consider a ray that leaves the center of projection and passes through a pixel and decide which object should appear at the pixel and what colour/light/texture it should be drawn in 21/10/2005 Lecture 9

Back face culling. v We saw in modelling, that the vertices of polyhedra are

Back face culling. v We saw in modelling, that the vertices of polyhedra are oriented in an anticlockwise manner when viewed from outside – surface normal N points out. v Project a polygon. v Test z component of surface normal. If negative – cull, since normal points away from viewer. v Or if N. V > 0 we are viewing the back face so polygon is obscured (A polygon faces away from the viewer if the angle between the surface normal (N) and the viewing direction (V) is less than 90 degrees V. N > 0) v Only works for convex objects without holes, ie. closed orientable manifolds. 21/10/2005 Lecture 9

Back face culling v Back face culling can be applied anywhere in the pipeline:

Back face culling v Back face culling can be applied anywhere in the pipeline: world or camera coords, NDC (normalised device coordinate), image space. v Where is the best point? What portion of the scene is eliminated, on average? v Depends on application v If we clip our scene to the view frustrum, then remove all back-facing polygons – are we done? v NO! Most views involve overlapping polygons. 21/10/2005 Lecture 9

How de we handle overlapping? How about drawing the polygons in the “right order”

How de we handle overlapping? How about drawing the polygons in the “right order” so that we get the correct result ( eg. blue, then green, then peach)? Is it just a sorting problem ? Yes it is for 2 D, but in 3 D we can encounter intersecting polygons or groups of non-intersecting polygons which form a cycle where order is impossible (later). 21/10/2005 Lecture 9 8

Z-buffer Algorithm v Some polygons will be obscured by others - we only want

Z-buffer Algorithm v Some polygons will be obscured by others - we only want to draw the visible polygons v Suppose polygons have been passed through the projection transformation, with the z coordinate retained (ie the depth information) - suppose z normalized to range 0 to 1 v For each pixel (x, y), we want to draw the polygon nearest to the camera, ie largest z y x z camera 21/10/2005 Lecture 9

Z-buffer Algorithm v We require two buffers: v frame buffer to hold colour of

Z-buffer Algorithm v We require two buffers: v frame buffer to hold colour of each pixel v z-buffer to hold depth information for each pixel A B v Initialize all depth(x, y) to 0 and refresh(x, y) to background colour v For each pixel compare depth value z to current depth(x, y) v if z > depth(x, y) then v depth(x, y)=z v Frame buffer (x, y) = Isurface(x, y) (gouraud/phong shading) 21/10/2005 Lecture 9 y z 2 z 1 x z

Z-buffer Algorithm Fill each pixel with background and set each z colour to infinity

Z-buffer Algorithm Fill each pixel with background and set each z colour to infinity For each polygon P in the scene Do For each pixel (x, y) in P's projection Do calculate z-coordinate, zp of p at (x, y) IF zp < value in Z-buffer at ( x, y ) THEN replace value in Z-buffer at (x, y) by Zp colour pixel (x, y) in colour of p End IF End For 21/10/2005 Lecture 9

Determining depth. -Only one subtraction needed -Depth coherence. 21/10/2005 Lecture 9

Determining depth. -Only one subtraction needed -Depth coherence. 21/10/2005 Lecture 9

Z Buffer - Strengths and Weaknesses Advantage v Simple to implement in hardware. v

Z Buffer - Strengths and Weaknesses Advantage v Simple to implement in hardware. v Add additional z interpolator for each primitive. v Memory for z-buffer is now not expensive v Diversity of primitives – not just polygons. v Unlimited scene complexity v Don’t need to calculate object-object intersections. Disadvantage v Extra memory and bandwidth v Waste time drawing hidden objects v Limited precision for depth calculations in complex scenes can be a problem 21/10/2005 Lecture 9

Z-compositing Colour photograph. Can use depth other than from polygons. Laser range return. Reflected

Z-compositing Colour photograph. Can use depth other than from polygons. Laser range return. Reflected laser power Data courtesy of UNC. 21/10/2005 Lecture 9 14

Ray casting. v Sometimes referred to as Ray-tracing. v Involves projecting an imaginary ray

Ray casting. v Sometimes referred to as Ray-tracing. v Involves projecting an imaginary ray from the centre of projection (the viewers eye) through the centre of each pixel into the scene. Scene Eyepoint Window 21/10/2005 Lecture 9

Computing ray-object intersections. v The heart of ray tracing. v e. g. sphere (

Computing ray-object intersections. v The heart of ray tracing. v e. g. sphere ( the easiest ! ). Expand, substitute for x, y & z. Gather terms in t. Quadratic equation in t. Solve for t. -No roots – ray doesn’t intersect. - 1 root – ray grazes surface. - 2 roots – ray intersects sphere, (entry and exit) 21/10/2005 Lecture 9

Ray-polygon intersection. v Not so easy ! 1. 2. v Determine whether ray intersects

Ray-polygon intersection. v Not so easy ! 1. 2. v Determine whether ray intersects polygon’s plane. Determine whether intersection lies within polygon. Easiest to determine (2) with an orthographic projection onto the nearest axis and the 2 D point-in-polygon test. z Ray x y 21/10/2005 Lecture 9

Ray casting. v Easy to implement for a variety of primitives – only need

Ray casting. v Easy to implement for a variety of primitives – only need a ray-object intersection function. v Pixel adopts colour of nearest intersection. v Can draw curves and surfaces exactly – not just triangles ! v Can generate new rays inside the scene to correctly handle visibility with reflections, refraction etc – recursive ray-tracing. v Can be extended to handle global illumination. v Can perform area-sampling using ray super-sampling. v But… too expensive for real-time applications. 21/10/2005 Lecture 9

Examples of Ray-traced images. 21/10/2005 Lecture 9 19

Examples of Ray-traced images. 21/10/2005 Lecture 9 19

Depth Sort Methods v The Depth Sort Algorithm initially sorts the faces in the

Depth Sort Methods v The Depth Sort Algorithm initially sorts the faces in the object into back to front order. v The faces are then scan converted in this order onto the screen. v Thus a face near the front will obscure a face at the back by overwriting it at any points where their projections overlap. v This accomplishes hidden-surface removal without any complex intersection calculations between the two projected faces. This latter technique of painting the object in back to front order is often called The Painter's Algorithm v The Depth Sort algorithm is a hybrid algorithm in that it sorts in object space and does the final rendering in image space. 21/10/2005 Lecture 9 20

Depth Sort Methods A B z v The basic algorithm : 1. 2. 3.

Depth Sort Methods A B z v The basic algorithm : 1. 2. 3. x Sort all polygons in descending order of maximum z-values. Resolve any ambiguities in this ordering. Scan convert each polygon in the order generated by steps (1) and (2). v The necessity for step (2) can be seen in the simple case: A precedes B in order of maximum z but B should precede A in writing order. v At step (2) the ordering produced by (1) must be confirmed. This is done by making more precise comparisons between polygons whose z-extents overlap 21/10/2005 Lecture 9 21

BSP (Binary Space Partitioning) Tree. v. One of class of “list-priority” algorithms – returns

BSP (Binary Space Partitioning) Tree. v. One of class of “list-priority” algorithms – returns ordered list of polygon fragments for specified view point (static pre-processing stage). v. Choose polygon arbitrarily 5 2 v. Divide scene into front (relative to normal) and back half-spaces. v. Split any polygon lying on both sides. 1 3 4 v. Choose a polygon from each side – split scene again. v. Recursively divide each side until each node contains only 1 polygon. 21/10/2005 Lecture 9 View of scene from above 22

BSP Tree. 5 5 a 5 b 2 v. Choose polygon arbitrarily v. Divide

BSP Tree. 5 5 a 5 b 2 v. Choose polygon arbitrarily v. Divide scene into front (relative to normal) and back half-spaces. 3 1 4 v. Split any polygon lying on both sides. v. Choose a polygon from each side – split scene again. front v. Recursively divide each side until each node contains only 1 polygon. 21/10/2005 Lecture 9 1 2 5 a 3 back 4 5 b 23

BSP Tree. 5 5 a 5 b 2 v. Choose polygon arbitrarily v. Divide

BSP Tree. 5 5 a 5 b 2 v. Choose polygon arbitrarily v. Divide scene into front (relative to normal) and back half-spaces. 3 1 4 v. Split any polygon lying on both sides. v. Choose a polygon from each side – split scene again. v. Recursively divide each side until each node contains only 1 polygon. front 5 a 21/10/2005 3 front Lecture 9 2 back 4 5 b 1 24

BSP Tree. 5 5 a 5 b 2 v. Choose polygon arbitrarily v. Divide

BSP Tree. 5 5 a 5 b 2 v. Choose polygon arbitrarily v. Divide scene into front (relative to normal) and back half-spaces. 3 1 4 v. Split any polygon lying on both sides. v. Choose a polygon from each side – split scene again. v. Recursively divide each side until each node contains only 1 polygon. front 5 a 21/10/2005 3 front Lecture 9 2 back 4 1 5 b 25

BSP Tree. 5 2 v. Choose polygon arbitrarily 3 1 v. Divide scene into

BSP Tree. 5 2 v. Choose polygon arbitrarily 3 1 v. Divide scene into front (relative to normal) and back half-spaces. 4 v. Split any polygon lying on both sides. v. Choose a polygon from each side – split scene again. 5 back 4 v. Recursively divide each side until each node contains only 1 polygon. front 3 back 1 Alternate formulation starting at 5 2 21/10/2005 Lecture 9 26

Displaying a BSP tree. v Once we have the regions – need priority list

Displaying a BSP tree. v Once we have the regions – need priority list v BSP tree can be traversed to yield a correct priority list for an arbitrary viewpoint. v Start at root polygon. v If viewer is in front half-space, draw polygons behind root first, then the root polygon, then polygons in front. v If polygon is on edge – either can be used. v Recursively descend the tree. v If eye is in rear half-space for a polygon – then can back face cull. 21/10/2005 Lecture 9

BSP Tree. v A lot of computation required at start. v Try to split

BSP Tree. v A lot of computation required at start. v Try to split polygons along good dividing plane v Intersecting polygon splitting may be costly v Cheap to check visibility once tree is set up. v Can be used to generate correct visibility for arbitrary views. Efficient when objects don’t change very often in the scene. 21/10/2005 Lecture 9

Warnock’s Algorithm v Elegant hybrid of object-space and image-space. v Uses standard graphics solution:

Warnock’s Algorithm v Elegant hybrid of object-space and image-space. v Uses standard graphics solution: - if situation too complex then subdivide problem. v Start with root window: v If zero or one intersecting, contained or surrounding polygon then scan convert window v Else subdivide window as quadtree v Recurse until zero or one polygon, or some set depth v Depth may be pixel resolution, display nearest polygon 21/10/2005 Lecture 9

Warnock’s example 21/10/2005 Lecture 9 30

Warnock’s example 21/10/2005 Lecture 9 30

Warnock performance measure v Warnock’s algorithm: v. Screen-space subdivision (screen resolution, r = w*h)

Warnock performance measure v Warnock’s algorithm: v. Screen-space subdivision (screen resolution, r = w*h) hybrid object-space & image-space algorithm good for relatively few static primitives, precise. v. Working set size (memory requirement): O(n) v. Storage overhead (over & above model): O(n lg r) v. Time to resolve visibility to screen precision: O(n*r) v. Overdraw (depth complexity – how often a typical pixel is written by rasterization process): none 21/10/2005 Lecture 9