Presentation is loading. Please wait.

Presentation is loading. Please wait.

Modeling of worlds A complicated object be decomposed into simple objects and represented by hierarchical model A world scene usually contain many objects.

Similar presentations


Presentation on theme: "Modeling of worlds A complicated object be decomposed into simple objects and represented by hierarchical model A world scene usually contain many objects."— Presentation transcript:

1 Modeling of worlds A complicated object be decomposed into simple objects and represented by hierarchical model A world scene usually contain many objects If position each objects are relatively fixed, then the world can be rendered by drawing each object. Eg. the buildings in a city CP411 Hidden face removing1

2 Dynamic world with many objects What if the objects are moving and their relative positions are changing? E.g. solar system, animations How do we remember and get the current position of each object? CP411 Hidden face removing2

3 Method one Remember the current position of all vertices of the object. E.g. when cube is moving remember the current coordinates of each object Pro: Con: Works when an object has a few vertices Bad when an object contains many object CP411 Hidden face removing3

4 Method two Use the model coordinate system, ie. the (Ux, Uy, Uz, O) or MC, the MC->WC transformation matrix to remember the position. When the an object is moving to a new position, apply the same transformation matrix to MC to get the new MC. Then new MC represents the new MC->WC transformation matrix and the object can be rendered with CTM * MC Pro : Con: CP411 Hidden face removing4

5 MC normalization The vectors in MC are unit vectors and orthogonal with each other. After a large number of transformations, the MC begins to deform due to error accumulation How to fix? CP411 Hidden face removing5

6 6 The drawing does not look right! What happens? A face drawn earlier is overwritten by other faces drawn later, even though it is closer to the viewer than the others How can we solve the problem?

7 CP411 Hidden face removing7 Visibility and Hidden surface removing 1.Visibility and visibility issues 2.Back-face method (to be implemented) 3.Depth sort method (to be implemented) 4.Depth-buffer method (implemented in OpenGL, to be used) 5.A-buffer method 6.Scan line method 7.Area-division method 8.BSP-tree method

8 CP411 Hidden face removing8 1. Visibility Given a set of polygons, determine which is visible at each pixel? –Also called hidden surface removal Many approaches were invented. Two major classes: –Object-space method: computations that operate on primitives –Image-space method: computations at the pixel level

9 CP411 Hidden face removing9 Space and Depth All the spaces in the viewing pipeline maintain depth, so we can work in any space –World, View and Canonical Screen spaces might be used –Depth can be updated on a per-pixel basis as we scan convert polygons or lines

10 CP411 Hidden face removing10 Issues with visibility Efficiency –it is slow to overwrite pixels, or scan convert things that cannot be seen Accuracy –answer should be right, and behave well when the viewpoint moves Complexity –object precision visibility may generate many small pieces of polygon –Must have technology that handles large, complex rendering databases In many complex worlds, few things are visible How much of the real world can you see at any moment?

11 CP411 Hidden face removing11 2. Back Face method Back faces are the surfaces facing at opposite directions from the viewpoint. A surface is a back face if the viewpoint is on the inside of the surface, ie, Ae x + Be y + Ce z + D < 0. The test will even be simpler after the viewing transformation Ax + By + Cz + D = 0 (e x, e y, e z )

12 CP411 Hidden face removing 12 Eye position Reference point How to detect if a face is a back face A face is a back face if Using this condition for back face detection in A3 will give a better performance. Credits to Alasdair and Derek

13 CP411 Hidden face removing13

14 CP411 Hidden face removing14 Back face detection algorithm with OpenGL If an object is opaque, back faces are obstructed by the object itself and thus are not visible from the viewer. In default mode, OpenGL draws both front face and back face as filled polygons. This is the reason why the preceding drawing of the cube did not look right. OpenGL can be set to display front faces as filled polygons and back faces as wire frames. glPolygonMode( GL_FRONT, GL_FILL); glPolygonMode( GL_BACK, GL_LINE); A more thorough solution is not to display the back faces at all. glCullFace(GL_BACK); glEnable(GL_CULL_FACE);

15 CP411 Hidden face removing15 2. Depth Sorting ( Painters) Method Algorithm: –Choose an order for the polygons based on some choice (e.g. depth to a point on the polygon) –Render the polygons in that order, deepest one first An example of a list-priority algorithm –Sort polygons on depth of some point –Render from back to front (modifying order on the fly) –Rendering: For surface S with greatest depth If no overlap in depth with other polygons, scan convert Else, for overlaps in depth, test for overlaps in the image plane –If none, scan convert and go to next polygon If S, S’ overlap in depth and in image plane, swap order and try again If S, S’ have been swapped already, split and reinsert

16 CP411 Hidden face removing16 The depth of a point The depth of a point is the z value of in view coordinate system The z value d of P (the depth of P) is equal to the length of project of P eye P on P eye P ref Peye Pref vz vx vy P d

17 CP411 Hidden face removing17 How to calculate the Z-value The z-value of P is equal to

18 CP411 Hidden face removing18

19 CP411 Hidden face removing19 The depth of a polygon can be defined to be the depth of its center Overlap of polygons is a problem with painter’s algorithm Testing for overlaps: Start drawing when first condition is met: –x-extents or y-extents do not overlap –S is behind the plane of S’ –S’ is in front of the plane of S –S and S’ do not intersect in the image plane S S’ S or z x S S’ z x S S

20 CP411 Hidden face removing20 Advantages: –Filter anti-aliasing works fine Composite in back to front order with a sequence of over operations –No depth quantization error Depth comparisons carried out in high-precision view space Disadvantages: –Over-rendering –Potentially very large number of splits -  (n 2 ) fragments from n polygons

21 CP411 Hidden face removing21 This renders nearer polygons over further Difficulty: –works for some important geometries (2.5D - e.g. VLSI) –doesn’t work in this form for most geometries - need at least better ways of determining ordering zszs xsxs Fails Which point for choosing ordering?

22 CP411 Hidden face removing22 3. The depth-buffer (Z buffer) algorithm When a new surface is drawn, a pixel value will be updated only if the part of the surface corresponding to the pixel is closer to the viewer than the surface currently displayed by the pixel. Suppose that the cyan face in the middle is drawn first. The pixel corresponding to the line of sight shown is set to cyan. Next, when the green face is drawn, the pixel will not be updated. Finally when the red triangle is drawn, the pixel is set to red. One pixel of the screen

23 CP411 Hidden face removing23 For each pixel on screen, have at least two buffers –Color buffer stores the current color of each pixel The thing to ultimately display –Z-Buffer stores at each pixel the depth (distance) of the nearest thing seen so far 0 2 0 12 1......... Frame Buffer Video Controller Monitor Display Processor Depth Buffer Depth Buffer Frame Buffer

24 CP411 Hidden face removing24 Initialize this buffer to a value corresponding to the furthest point As a polygon is filled in, compute the depth value of each pixel that is to be filled –if depth < z-buffer depth, fill in pixel color and new depth –else disregard

25 CP411 Hidden face removing25 The depth-buffer algorithm For each pixel at (x, y) of the screen //Initialization color( x, y) = background_color; depth( x, y) =  ; Draw each surface one by one For each pixel that covered by the projection of the surface (suppose the pixel is at (x, y) ) z = the depth of the surface corresponding to the pixel; if (z < depth( x, y) ) { color( x, y) = the color of the surface; depth( x, y) = z; }

26 CP411 Hidden face removing26 OpenGL Depth Buffer Functions OpenGL defines a depth buffer as its visibility algorithm –To set up the depth buffer testing (in main() ) glutInitDisplayMode(GLUT_DEPTH); –The enable depth testing: glEnable(GL_DEPTH_TEST); –To clear the depth buffer glClear(GL_DEPTH_BUFFER_BIT); –To clear color and depth: –glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); –The comparison function can be specified: glDepthFunc(…); For efficiency, we shall enable back-face culling as well.

27 CP411 Hidden face removing27 glutSolidSphere( 1.0, 20, 20);

28 CP411 Hidden face removing28 glutSolidTeapot( 1.5);

29 CP411 Hidden face removing29 Advantages: –Simple and now ubiquitous in hardware A z-buffer is part of what makes a graphics card “3D” –Computing the required depth values is simple Disadvantages: –Over-renders - worthless for very large collections of polygons –Depth quantization errors can be annoying –Can’t easily do transparency or filtering for anti-aliasing (Requires keeping information about partially covered polygons)

30 CP411 Hidden face removing30 4. A-buffer Handles transparent surfaces and filter anti-aliasing At each pixel, maintain a pointer to a list of polygons sorted by depth, and a sub-pixel coverage mask for each polygon –Matrix of bits saying which parts of the pixel are covered Algorithm: When drawing a pixel: –if polygon is opaque and covers pixel, insert into list, removing all polygons farther away –if polygon is transparent or only partially covers pixel, insert into list, but don’t remove farther polygons

31 CP411 Hidden face removing31 Algorithm: Rendering pass –At each pixel, traverse buffer using polygon colors and coverage masks to composite: Advantage: –Can do more than Z-buffer –Coverage mask idea can be used in other visibility algorithms Disadvantages: –Not in hardware, and slow in software –Still at heart a z-buffer: Over-rendering and depth quantization problems But, used in high quality rendering tools over =

32 CP411 Hidden face removing32 5. Scan Line Algorithm (Image Precision) Assume polygons do not intersect one another –Except maybe at edges or vertices Observation: across any given scan line, the visible polygon can change only at an edge Algorithm: –fill all polygons simultaneously –at each scan line, have all edges that cross scan line in AEL (Active Edge List) –keep record of current depth at current pixel - use to decide which is in front in filling span

33 CP411 Hidden face removing33 zszs xsxs zszs xsxs zszs xsxs Spans Where polygons overlap, draw front polygon

34 CP411 Hidden face removing34 Advantages: –Simple –Potentially fewer quantization errors (more bits available for depth) –Don’t over-render (each pixel only drawn once) –Filter anti-aliasing can be made to work (have information about all polygons at each pixel) Disadvantages: –Invisible polygons clog AEL, ET (edge table) –Non-intersection criteria may be hard to meet

35 Final exam questions What is the back-face method for hidden surface removal? What is the painter’s method for hidden surface removal? What is the difference between depth-sort method and depth-buffer method? CP411 Hidden face removing35

36 CP411 Hidden face removing36

37 CP411 Hidden face removing37 6. Area Subdivision Exploits area coherence: Small areas of an image are likely to be covered by only one polygon Three easy cases for determining what’s in front in a given region: 1.a polygon is completely in front of everything else in that region 2.no surfaces project to the region 3.only one surface is completely inside the region, overlaps the region, or surrounds the region

38 CP411 Hidden face removing38 Warnock’s Area Subdivision Start with whole image If one of the easy cases is satisfied (previous slide), draw what’s in front Otherwise, subdivide the region and recurse If region is single pixel, choose surface with smallest depth

39 CP411 Hidden face removing39 Warnock’s Algorithm Regions labeled with case used to classify them: 1)One polygon in front 2)Empty 3)One polygon inside, surrounding or intersecting Small regions not labeled Note it’s a rendering algorithm and a HSR algorithm at the same time –Assuming you can draw squares 222 2222 2 2 3 3 3 333 3 3 3 3 3 333 3 3 1 11 1 1

40 CP411 Hidden face removing40 Warnock’s Area Subdivision Method Advantages: –No over-rendering –Anti-aliases well - just recurs deeper to get sub-pixel information Disadvantage: –Tests are quite complex and slow

41 CP411 Hidden face removing41 7. BSP-Trees (Object Precision) Construct a binary space partition tree –Tree gives a rendering order –A list-priority algorithm Tree splits 3D world with planes –The world is broken into convex cells –Each cell is the intersection of all the half-spaces of splitting planes on tree path to the cell Also used to model the shape of objects, and in other visibility algorithms

42 BSP Trees Having a pre-built BSP tree will allow us to get a correct depth order of polygons in our scene for any point in space. We will build a data structure based on the polygons in the scene, that can be queried with any point input to return an ordering of those polygons.

43 Structure of a BSP Tree Each internal node has a +half space, a -half space, and a list of objects contained entirely within that plane (if any exist). Each leaf has a list of zero or one objects inside it, and no sub-trees The size of a BSP tree is the total number of objects stored in the leaves & nodes of the tree. This can be larger than the number of objects in our scene because of splitting.

44 The Big Picture Assume that no objects in our space overlap Use planes to recursively split our object space, keeping a tree structure of these recursive splits.

45 Choose a Splitting Line Choose a splitting plane, dividing our objects into three sets – those on each side of the plane, and those fully contained on the plane.

46 Choose More Splitting Lines What do we do when an object (like object 1) is divided by a splitting plane? It is divided into two objects, one on each side of the plane.

47 Split Recursively Until Done When we reach a convex space containing exactly zero or one objects, that is a leaf node.

48 Continue

49

50 Finished Once the tree is constructed, every root-to- leaf path describes a single convex subspace.

51 Querying the Tree If an eye point is in the positive/negative half-space of a plane, then everything in the negative/positive half-space is farther away -- so draw it first, using this algorithm recursively Then draw objects on the splitting plane, and recurse into the positive/negative half-space.

52 What Order Is Generated From This Eye Point? Q5, Q4, Q4’, Q3, Q1’, Q2, Q1

53 Summary 1.Back-face method 2.Depth sort method 3.Depth-buffer method 4.A-buffer method 5.Scan line method 6.Area-division method 7.BSP-tree method CP411 Hidden face removing53


Download ppt "Modeling of worlds A complicated object be decomposed into simple objects and represented by hierarchical model A world scene usually contain many objects."

Similar presentations


Ads by Google