cs488 more visible surface determination
play

CS488 More Visible-Surface Determination Luc R ENAMBOT 1 - PowerPoint PPT Presentation

CS488 More Visible-Surface Determination Luc R ENAMBOT 1 Examples The following sets of images show a wireframe version, a wireframe version with hidden line removal, and a solid polygonal representation of the same object 2 Examples


  1. CS488 More Visible-Surface Determination Luc R ENAMBOT 1

  2. Examples The following sets of images show a wireframe version, a wireframe version with hidden line removal, and a solid polygonal representation of the same object 2

  3. Examples

  4. Object Space • Object space algorithms do their work on the objects themselves before they are converted to pixels in the frame buffer. • The resolution of the display device is irrelevant here as this calculation is done at the mathematical level of the objects • For each object a in the scene • Determine which parts of object a are visible (involves comparing the polygons in object a to other polygons in a and to polygons in every other object in the scene) 4

  5. Image Space • Image space algorithms do their work as the objects are being converted to pixels in the frame buffer • The resolution of the display device is important here as this is done on a pixel by pixel basis • For each pixel in the frame buffer • Determine which polygon is closest to the viewer at that pixel location • Determine the color of the pixel with the color of that polygon at that location 5

  6. Back Face Culling Front facing • OpenGL specifies that all polygons be drawn such that the vertices are given in counterclockwise order as you look at the visible side of polygon in order to generate the 'correct' normal. Back facing • Any polygons whose normal points away from the viewer is a 'back-facing' polygon and does not need to be further investigated 6

  7. Depth Buffer • Early on we talked about the frame buffer which holds the color for each pixel to be displayed • This buffer could contain a variable number of bytes for each pixel depending on whether it was a grayscale, RGB, or color indexed frame buffer • All of the elements of the frame buffer are initially set to be the background color • As lines and polygons are drawn the color is set to be the color of the line or polygon at that point 7

  8. Warnock's Algorithm • Warnock's algorithm is a recursive area- subdivision algorithm • It looks at an area of the image • If is is easy to determine which polygons are visible in the area, they are drawn • else the area is subdivided into smaller parts and the algorithm recurses. • Eventually an area will be represented by a single non-intersecting polygon 8

  9. Depth Sort Algorithm • The idea here is to go back to front drawing all the objects into the frame buffer with nearer objects being drawn over top of objects that are further away • Simple algorithm 1. Sort all polygons based on their farthest z coordinate 2. Resolve ambiguities 3. draw the polygons in order from back to front 9

  10. Depth Sort Algorithm • This algorithm would be very simple if the z coordinates of the polygons were guaranteed never to overlap • Unfortunately that is usually not the case, which means that step 2 can be somewhat complex. • Any polygons whose z extents overlap must be tested against each other 10

  11. Depth Sort Algorithm • We start with the furthest polygon and call it P • Polygon P must be compared with every polygon Q whose z extent overlaps P's x extent • 5 comparisons are made • If any comparison is true then P can be written before Q • If at least one comparison is true for each of the Qs then P is drawn and the next polygon from the back is chosen as the new P 11

  12. Depth Sort Algorithm 1. Do P and Q's x-extents not overlap ? 2. Do P and Q's y-extents not overlap ? 3. Is P entirely on the opposite side of Q's plane from the viewport ? 4. Is Q entirely on the same side of P's plane as the viewport ? 5. Do the projections of P and Q onto the (x,y) plane not overlap ? 12

  13. Depth Sort Algorithm • If all 5 tests fail we quickly check to see if switching P and Q will work • Tests 1, 2, and 5 do not differentiate between P and Q but 3 and 4 do • So we rewrite 3 and 4: • 3 - Is Q entirely on the opposite side of P's plane from the viewport ? • 4 - Is P entirely on the same side of Q's plane as the viewport ? 13

  14. Depth Sort Algorithm • If either of these two tests succeed then Q and P are swapped and the new P (formerly Q) is tested against all the polygons whose z extent overlaps it's z extent. • If these two tests still do not work then either P or Q is split into 2 polygons using the plane of the other. These 2 smaller polygons are then put into their proper places in the sorted list and the algorithm continues. • Beware of the dreaded infinite loop ! 14

  15. BSP Trees • Binary Space Partition trees • It is a depth sort algorithm with a large amount of preprocessing to create a data structure to hold the polygons • First generate a 3D BSP tree for all of the polygons in the scene 15

  16. BSP Trees • Then display the polygons according to their order in the scene 1. Polygons behind the current node 2. The current node 3. Polygons in front of the current node 16

  17. BSP Trees • Each node in the tree is a polygon • Extending that polygon generates a plane • That plane cuts space into 2 parts • We use the front-facing normal of the polygon to define the half of the space that is 'in front' of the polygon • Each node has two children: the front children (the polygons in front of this node) and the back children (the polygons behind this node) 17

  18. Steps • We may need to split some polygons into two • Then when we are drawing the polygons we first see if the viewpoint is in front of or behind the root node • Based on this we know which child to deal with first - we first draw the subtree that is further from the viewpoint, then the root node, then the subtree that is in front of the root node, recursively, until we have drawn all the polygons 18

  19. BSP Trees • Compared to depth sort, it takes more time to setup but less time to iterate through since there are no special cases • If the position or orientation of the polygons change, then parts of the tree will need to be recomputed 19

  20. BSP Trees Example 20

  21. BSP Trees Example 21

  22. BSP Trees Example 22

  23. Scan Line Algorithm • This is an extension of the algorithm we dealt with earlier to fill polygons one scan line at a time • This time there will be multiple polygons being drawn simultaneously. 23

  24. Scan Line Algorithm • Again we create a global edge table for all non- horizontal edges sorted based on the edges smaller y coordinate. • Each entry in the table contains: • X coordinate corresponding to the smallest y coordinate • Y coordinate of the other end of the edge • deltaX = 1/m • a way to identify which polygon this edge belongs to 24

  25. Scan Line • In the scan line algorithm we had a simple 0/1 variable to deal with being in or out of the polygon • Since there are multiple polygons here we have a Polygon Table • The Polygon Table contains: • coefficients of the equation of the plane of the polygon • shading / color information on this polygon • in / out flag initialized to false 25

  26. Scan Line Algorithm • Again the edges are moved from the global edge table to the active edge table when the scan line corresponding to the bottom of the edge is reached • Moving across a scan line the flag for a polygon is flipped when an edge of that polygon is crossed • If no flags are true then nothing is drawn • If one flag is true then the color of that polygon is used • If more than one flag is true then the frontmost polygon must be determined 26

  27. Example Textbook 15.34 Two polygons ABC and DEF Scan Line AET contents Comments --------- ------------ -------- alpha AB AC one polygon beta AB AC FD FE two separate polygons gamma AB DE CB FE two overlapping polygons gamma+1 AB DE CB FE two overlapping polygons gamma+2 AB CB DE FE two separate polygons 27

  28. Simple Ray Tracing • A simple ray-tracing algorithm can be used to find visible surfaces • As opposed to a more complicated algorithm that can be used to generate those o-so-pretty images • Ray tracing is an image based algorithm • For every pixel in the image, a ray is cast from the center of projection through that pixel and into the scene • The color of the pixel is set to the color of the object that is first encountered 28

  29. Ray Tracing Algorithm Given a Center Of Projection Given a window on the view plane for (each scan line) for (each pixel on the scan line) { Compute ray from COP through pixel for (each object in scene) if (object is intersected by ray && object is closer than previous intersection) record (intersection point, object) set pixel's color to the color of object at intersection point } 29

  30. Ray Tracing • Given a ray (vector) and an object, the key idea is computing if and if so where does the ray intersect the object • The ray is represented by the vector from (Xo, Yo, Zo) at the COP , to (X1, Y1, Z1) at the center of the pixel • We can parameterize this vector by introducing t: • X = Xo + t(X1 - Xo) X = Xo + t(deltaX) • Y = Yo + t(Y1 - Yo) Y = Yo + t(deltaY) • Z = Zo + t(Z1 - Zo) Z = Zo + t(deltaZ) • Parameter • t equal to 0 represents the COP , t equal to 1 represents the pixel • t < 0 represents points behind the COP • t > 1 represents points on the other side of the view plane from the COP 30

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend