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

cs488 more visible surface determination
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

CS488 More Visible-Surface Determination

Luc RENAMBOT

1

slide-2
SLIDE 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

slide-3
SLIDE 3

Examples

slide-4
SLIDE 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

slide-5
SLIDE 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

slide-6
SLIDE 6

Back Face Culling

  • 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.

  • Any polygons whose normal

points away from the viewer is a 'back-facing' polygon and does not need to be further investigated

6

Front facing Back facing

slide-7
SLIDE 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

slide-8
SLIDE 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

slide-9
SLIDE 9

Depth Sort Algorithm

  • The idea here is to go back to front drawing all the
  • bjects 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

slide-10
SLIDE 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

slide-11
SLIDE 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

slide-12
SLIDE 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

slide-13
SLIDE 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

slide-14
SLIDE 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

  • ther. 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

slide-15
SLIDE 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

slide-16
SLIDE 16

BSP Trees

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

16

slide-17
SLIDE 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

slide-18
SLIDE 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

slide-19
SLIDE 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

slide-20
SLIDE 20

BSP Trees Example

20

slide-21
SLIDE 21

BSP Trees Example

21

slide-22
SLIDE 22

BSP Trees Example

22

slide-23
SLIDE 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

slide-24
SLIDE 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

slide-25
SLIDE 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

slide-26
SLIDE 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

slide-27
SLIDE 27

Example

27

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

slide-28
SLIDE 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

slide-29
SLIDE 29

Ray Tracing Algorithm

29

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 }

slide-30
SLIDE 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

slide-31
SLIDE 31

Ray Tracing Algorithm

  • We want to find out what the value of t is

where the ray intersects the object

  • This way we can take the smallest value of t that

is in front of the COP as defining the location of the nearest object along that vector

  • The problem is that this can take a lot of time,

especially if there are lots of pixels and lots of

  • bjects

31

slide-32
SLIDE 32

Performance

  • Raytraced images in 'T
  • y Story' for example took at minimum 45 minutes

and at most 20 hours for a single frame

  • So minimizing the number of comparisons is critical:
  • Bounding boxes can be used to perform initial checks on complicated
  • bjects
  • Hierarchies of bounding boxes can be used where a successful

intersection with a bounding box then leads to tests with several smaller bounding boxes within the larger bounding box

  • The space of the scene can be partitioned: partitions are then treated

like buckets in a hash table, and objects within each partition are assigned to that partition. Checks can then be made against this constant number of partitions first before going on to checking the

  • bjects themselves. These partitions could be equal sized volumes, or

contain equal numbers of polygons

32

slide-33
SLIDE 33

Algorithm Comparison

  • The relative performance of the various

algorithms where smaller is better and the depth sort of a hundred polygons is set to be 1

  • Caution with z-buffer value

33

# of polygonal faces in the scene Algorithm 100 250 60000

  • Depth Sort 1 10 507

z-buffer 54 54 54 scan line 5 21 100 Warnock 11 64 307

15.3 in the textbook

slide-34
SLIDE 34

Models

34

250 polygons 550 polygons 6,000 polygons 8,000 polygons 10,000 polygons