Transcript
Page 1: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Determining the Visible Surface

“Given a set of objects in 3-D and a Viewing specification, to determinethe portions of lines or surfaces that are visible from the view point”

� Ray Casting Algorithm

� Depth (Z) Buffer Algorithm

� Scanline Algorithm

� BSP trees

� Warnock’s Area Subdivision Algorithm.

ITCS 4120/5120 1 Visible Surface Algorithms

Page 2: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Image Space Algorithms

These typically solve the visible surface problem for image pixel, as fol-lows:

for each pixel in imagedo

determine object closest to the view that is piercedby a projector through the center of the pixel.Illuminate pixel with the appropriate color.

end

Complexity: ©(np), n: number of objects, p: number of pixels in image.

ITCS 4120/5120 2 Visible Surface Algorithms

Page 3: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Object Space Algorithms

for each object in the environmentdo

determine parts of the object unobstructed by itself orany other object.Illuminate pixel with the appropriate color.

end

Complexity: ©(n2), n: number of objects;

ITCS 4120/5120 3 Visible Surface Algorithms

Page 4: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Algorithm Classification

� Ray Casting: Image space algorithm, but visibility tests are at objectprecision.

� Z Buffer: Image space algorithm.

� BSP Tree: Object space algorithm: Object space algorithm, depthordering determined in object space, followed by scan conversion.

� Warnock’s Area Subdivision: Image space algorithm.

ITCS 4120/5120 4 Visible Surface Algorithms

Page 5: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

The Ray Casting Algorithm

� For visibility determination, only the primary ray is traced.

� Must use space subdivision structures to minimize intersection com-putations.

� Octrees, BSP trees, uniform grids are typically used.

� Refer to slides on global illumination, for details.

ITCS 4120/5120 5 Visible Surface Algorithms

Page 6: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Z (Depth) Buffer Algorithm(Catmull ’74)

� A buffer of Z or depth values is maintained, one for each pixel, inaddition to the frame buffer.

� During scan conversion, if primitive’s depth is less (closer) than theexisting value in the Z buffer, replace it and corresponding color (in-tensity) in the frame buffer.

� Each primitive is scanconverted once(visible or not), independent ofany other primitive, and in any order.

ITCS 4120/5120 6 Visible Surface Algorithms

Page 7: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Z-buffer Algorithm

For each object primitive{

For each pixel in projection{

Z = primitive’s depth value at pixel(x,y).if Z < Z BUF[x][y]{

Write ZBUF (x, y, Z)Write Pixel (x, y, pixel color)

}}

}

ITCS 4120/5120 7 Visible Surface Algorithms

Page 8: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Calculating Z: Scanline Coherence

Ax + By + Cz + D = 0

z(x, y) =−Ax−By −D

C

Let z(x, y) = zc

z(x + ∆x, y) =−A(x + ∆x, y)−By −D

C

= zc −A

C(∆x)

= zc −A

C

ITCS 4120/5120 8 Visible Surface Algorithms

Page 9: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Calculating Z: Edge Coherence

Can similarly exploit edge coherence along Y (from scanline toscanline).

� Note that from the scanline algorithm, x coordinate varies as

x′ = x− 1

m

� Thus

A(x) + By + Cz + D = 0

A(x− 1/m) + B(y + 1) + Cz′ + D = 0

� Solve for z’:

z′ = z −Am

+ B

C

ITCS 4120/5120 9 Visible Surface Algorithms

Page 10: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Z Buffer Algorithm: Notes

� Must have sufficient memory to have a Z buffer, no longer an issuetoday.

� If there is insufficient memory, may use just a scanline Z buffer, butlose coherence.

� Z values are usually from 32 bits wide or more.

� Easy to implement in hardware.

� Advantage decreases as the polygons reduce in size (or have fewerand fewer pixels in their projection)

ITCS 4120/5120 10 Visible Surface Algorithms

Page 11: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Scan-Line Algorithms

Features

� Developed by Wylie, Romney, Evans, Erdahl.

� Extension of the polygon filling algorithm, exploiting scanline, edgeand depth coherence

� Differences:

⇒ need to deal with multiple polygons,⇒ incorporate shading and depth calculations.

ITCS 4120/5120 11 Visible Surface Algorithms

Page 12: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Data Structures

1. Edge Table:

⇒ x coordinate of the edge with smaller y.⇒ Max y coordinate of the edge.⇒ ∆x (inverse slope) of the edge.⇒ Polygon identifier.

2. Active Edge Table

3. Polygon Table:

⇒ Coefficients of the plane equation.⇒ Shading information for polygon.⇒ Boolean flag, signifying if scan is in/out of polygon.

ITCS 4120/5120 12 Visible Surface Algorithms

Page 13: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Scanline Algorithm

X

Y

A

B

C

D

E

F

CE

1

2

3

4

� The scan conversion algorithm closely follows the polygon filling al-gorithm from scanline to scanline, exploiing scanline and edge co-herence.

� The edge table and active edge table permit efficient scan conver-sion.

� If the scanline intersects only 1 polygon, then there is no changefrom the filling algorithm (scanline 1).

ITCS 4120/5120 13 Visible Surface Algorithms

Page 14: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Scanline Algorithm(contd)

X

Y

A

B

C

D

E

F

CE

1

2

3

4

� If a second polygon is encountered (indicated by the boolean flagset to 1 and an edge from a second polygon is encountered), thendepth calculations are performed and the closer polygon’s span isscan converted. New shading calculations are also triggered.

� When the scan ‘leaves’ a polygon, control goes back to the polygonwhich still has its boolean flag set to ‘in’ (scanline 3 in figure).

� Assumes non-penetrating polygons. If polygons penetrate, thenthey will need to be fragmented.

ITCS 4120/5120 14 Visible Surface Algorithms

Page 15: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Scan-line Z buffer

� Allocate a Z-buffer and frame buffer for 1 scanline.

� Depth calculations are performed between all points on the spaneach polygon on the scanline.

� Permits inter-penetrating polygons.

ITCS 4120/5120 15 Visible Surface Algorithms

Page 16: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Binary Space Partitioning Trees

Features:

� Continuous Space Representation.

� Represents geometry with hyperplanes.

� Convex decomposition of space by recursive subdivision.

� Internal nodes contain discontinuities, leaf nodes represent convexregions.

a

outb

out

in

in

c

d

out

a

d

b

c

in

in

Viewer

ITCS 4120/5120 16 Visible Surface Algorithms

Page 17: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Representing Polyhedra: An example

a

d

b

c

in

in

ITCS 4120/5120 17 Visible Surface Algorithms

Page 18: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

a

d

b

c

in

in

a

out

ITCS 4120/5120 18 Visible Surface Algorithms

Page 19: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

a

d

b

c

in

in

a

outb

out

ITCS 4120/5120 19 Visible Surface Algorithms

Page 20: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

a

d

b

c

in

in

a

outb

out

in

c

ITCS 4120/5120 20 Visible Surface Algorithms

Page 21: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

a

d

b

c

in

in

a

outb

out

in

in

c

d

out

ITCS 4120/5120 21 Visible Surface Algorithms

Page 22: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Determining Visible Surface using the BSPTree

a

outb

out

in

in

c

d

out

a

d

b

c

in

in

Viewer

� Paint faces back to front, as faces in front cannot obscure those thatare behind.

� Classification is performed recursively, resulting in generating a pri-ority order of faces, for a given viewer position.

� The BSP tree is independent of viewer location, so long as the ob-jects do not move.

ITCS 4120/5120 22 Visible Surface Algorithms

Page 23: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Traversal Order for Viewer:a

outb

out

in

in

c

d

out

a

d

b

c

in

in

Viewer

a+, a, a-a+, a, (b-, b, b+)a+, a, (c+, c, c-) b, b+a+, a, (d+, d, d-), c, c-, b, b+a+, a, d+, d, d-, c, c-, b, b+

ITCS 4120/5120 23 Visible Surface Algorithms

Page 24: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Area Subdivision Algorithms

Idea

� Divide and conquer strategy of spatial partitioning the projectionplane.

� If it is “easy” to display the polygons in the area, display them, elsesubdivide and apply the same logic to the sub-areas.

ITCS 4120/5120 24 Visible Surface Algorithms

Page 25: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Warnock’s Algorithm

Subdivision of the original area into 4 equal areas. Analyze the polygonrelationship to the area.

� Surrounding polygons completely contain the area

� Intersecting polygons intersect the area

� Contained polygons are completely inside the area

� Disjoint polygons are completely outside the area.

ITCS 4120/5120 25 Visible Surface Algorithms

Page 26: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Warnock’s Algorithm

Consider the polygons that project onto this area (intersecting, surround-ing, contained, or disjoint)

� All polygons are disjoint - paint background color over the area.

� Only 1 intersecting or 1 contained polygon - fill area with backgroundcolor, then the part of polygon inside area is scanconverted.

� Single surrounding polygon, no intersecting of contained polygon -Area is filled with color of surrounding polygon.

� More than 1 polygon is intersecting, contained in, or surroundingthe area - determine if a single surrounding polygon is in front of allothers. If yes, fill area with color of surrounding polygon. The depth(z coordinates) of the planes of the polygons are examined at the 4corners of the area.ITCS 4120/5120 26 Visible Surface Algorithms

Page 27: Determining the Visible Surface - Personal Web Pages · Determining the Visible Surface “Given a set of objects in 3-D and a Viewing specification, to determine the portions of

Warnock’s Algorithm:Subdivision

� If none of the 4 cases resolves the problem, the area is subdividedinto 4 equal areas and each area’s polygons are examined to resolvethe closest visible surface.

� Once the resolution of the display is reached, subdivision stops; theclosest polygon visible at the center of the pixel is taken as the colorof the pixel (for anti-aliasing, multiple subpixel areas are examinedand averaged (with or without weighting).

ITCS 4120/5120 27 Visible Surface Algorithms


Top Related