0% found this document useful (0 votes)
167 views45 pages

CS3500 Computer Graphics Visible Surface Determination: P. J. Narayanan

The document discusses visible surface determination and the z-buffer algorithm. It begins with an introduction to visible surface determination and the need to determine which object points are visible. It then covers view frustum culling to eliminate objects outside the view volume. Next, it describes the image-precision z-buffer algorithm, which stores depth values in a z-buffer and only writes pixels if they are closer than the previously stored value. Finally, it discusses computing interior depth values and using coherence to improve performance of the z-buffer algorithm.

Uploaded by

api-3799599
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views45 pages

CS3500 Computer Graphics Visible Surface Determination: P. J. Narayanan

The document discusses visible surface determination and the z-buffer algorithm. It begins with an introduction to visible surface determination and the need to determine which object points are visible. It then covers view frustum culling to eliminate objects outside the view volume. Next, it describes the image-precision z-buffer algorithm, which stores depth values in a z-buffer and only writes pixels if they are closer than the previously stored value. Finally, it discusses computing interior depth values and using coherence to improve performance of the z-buffer algorithm.

Uploaded by

api-3799599
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

CS3500 Computer Graphics

Visible Surface Determination


P. J. Narayanan
Spring 2005

CS3500
1

Visible Surface Determination


Multiple object points can project to the same image pixel
in 3D. Which one gives the colour to the pixel?

Visible line/surface determination or


Hidden line/surface elimination.

Consider objects to be drawn or pixels to be painted.

Two parts: Visibility to view volume and mutual occlusion


of objects.

Need to analyze the scene from the camera.


CS3500 February 14, 2005
2

View Frustum Culling


Eliminate objects that are outside the view volume.

Large parts of the scene will be eliminated this way.

Compare bounding volume of node with view volume


If intersection is null, eliminate tree from root
If volume contained in frustum, render without clipping
Else, recursively check for each child of node till leaf

Object hierarchy helps. Whole campus, each building,


each floor, each room, etc., in the hierarchy.
CS3500 February 14, 2005
3

IIIT Campus

Corporate Academic NBH OBH

I Floor II Floor III Floor

Rm 305
Rm 104
CVIT CDE Director
CS3500 February 14, 2005
4

Box-Frustum Intersection
Orthographic: Intersection of two boxes. Perform by
checking simultaneous X-Y-Z overlaps.

Perspective: Clip against 6 planes of the frustum.

Or, project. BBox becomes a frustum. Find the bounding


box (conservative) of the new one.

AABB: Axis-Aligned Bounding Box


OBB: Oriented Bounding Box.

CS3500 February 14, 2005


5

Image-Precision Algorithm
for each pixel in the image
Determine closest object in the direction of projector
Draw the pixel with appropriate colours


Works in the discrete image space.


Complexity depends on the number of pixels.
A natural choice for raster graphics.
Image resizing involves repeating the entire work.

CS3500 February 14, 2005


6

Object-Precision Algorithm
for each object in the world
Determine unobstructed parts of the object
Draw those parts with appropriate colours


Complexity depends on the number of objects.


If the image size changes, only the drawing step needs to
be redone.
Works in the original continuous object space.

CS3500 February 14, 2005


7

Simplifying VSD
Extents: If two object do not overlap in and extents,


they cannot occlude each other. Bounding volumes must
overlap for possible obstruction.
Spatial Partitions: If the whole object overlaps, divide into
sub-parts and check for each.
Hierarchy: If higher levels of the hierarchy contains the
lower ones entirely, checking can be done from top down.
Coherence or local similarity in: objects, faces, edges,
scan-line, area, depth, etc.
Results in incremental computation algorithms.
CS3500 February 14, 2005
8

Viewing a Solid Object

Which polygons are visible?


Which are hidden?

CS3500 February 14, 2005


9

Back-Face Culling
Only the front side can be seen of solid, opaque objects.
If surface normals point out of the object, polygons with
normals pointing away from the viewer cannot be seen.
If , draw. Else discard. v is a vector from CoP to






any point on the polygon and n the surface normal.


After normalizing, DoP is -1 T. Eliminate polygons



with negative component in the normal vector.

Half the polygons eliminated on the average.


If there is only one object, no other VSD necessary.
CS3500 February 14, 2005
10

End of Class 19

CS3500 February 14, 2005


11

Z-buffer or Depth-buffer Algorithm


An image-precision algorithm that needs a z-buffer
parallel to the frame buffer.

values after the normalizing transformation is stored into


the z-buffer along with colour info to the frame buffer. We


have .






Since depth ordering is maintained, a larger implies a


closer 3D point in any direction.

Write to frame buffer and z-buffer only when the value


is larger than previously stored value.
CS3500 February 17, 2005
12

10 6 8
3
+
5
3 2

CS3500 February 17, 2005


13

Pseudocode
for Ymax


for Xmax


WritePixel (x, y, bgnd colour)


WriteZ (x, y, -1) // Farthest value
for each polygon
for each pixel in polygon’s projection
pz = polygon’s -value at pixel





if (pz ReadZ(x, y))


WriteZ()
WritePixel()

CS3500 February 17, 2005


14

Computing for Interior Points


Exploit coherence in depth
values over the plane to
Z1
compute interior values Y1

given the vertex values. Z3
Y3
Za Zp Zb




 













 

 







Y2
Z2
When or increments by 1


along a side or a scan line,


changes by a constant .


CS3500 February 17, 2005


15

Z-buffering: Discussion
Any shape with per pixel can be handled correctly.


Time is independent of number of primitives.
Easy to implement; can do with a single scan-line Z-
buffer.
Z-buffer can be read back and saved.
Needs extra memory, but memory is cheap.
Can cause aliasing or z-fighting (shimmering).

CS3500 February 17, 2005


16

VSD: Recap
Need to know which surface is in front and which is at the
back.

Back-Face Culling: Eliminate roughly half the polygons


based on a test involving the normals.

Z-buffering: A buffer parallel to the frame buffer holds the


-coordinates of the 3D point closest to the camera.

Retain the closest (i.e., change the depth and colour in


the Z/frame-buffers) only when a new point maps to a
pixel.
CS3500 February 17, 2005
17

List Priority Algorithms


Reorder objects such that the correct picture results if you
draw them in that order.
Example: If objects do not overlap in , draw them from


back to front.
Objects may need splitting if no unique ordering exists.
Ordering and splitting polygons: Object-precision
operation.
Overwriting farther points while scan conversion: Image-
precision operation.
CS3500 February 17, 2005
18

Depth-Sort or Painter’s Algorithm


1. Sort polygons on the farthest coordinate of each.


2. Resolve ambiguities due to overlap in .


Split polygons if necessary.
3. Scan convert from back to front.

Draw in the order of minimum if no depth ambiguity.



Painter’s Algorithm: Paint close objects over farther
ones.

Each object can be thought of as belonging to a plane of


constant .

CS3500 February 17, 2005


19

Q
P Q

P
P
Q Q
CS3500 February 17, 2005
20

Ordering a Pair of Polygons


Let P be the farthest polygon in the sorted list. If it doesn’t
overlap in with any other polygon, it can be drawn

immediately. Else let Q overlap with it in .


Test the following:
1. Are P and Q non-overlapping in ?
2. Are P and Q non-overlapping in ?

3. Is P entirely on the opposite side of Q’s plane from
viewpoint?
4. Is Q entirely on the same side of P as the viewpoint?
5. Are XY projections of P and Q non-overlapping?
CS3500 February 17, 2005
21

If the answer to any question is a yes, P can be drawn


(i.e., scan converted) before Q.
Otherwise, reverse the roles of P and Q and check
modified conditions 3’ and 4’. If any is satisfied, move
Q to the end of the list and make it P and go to the
beginning. (Need to check Q against polygons P was
farther to earlier!)
Check conditions 3’ and 4’ only of P has not been moved
to the end of the list earlier. (To avoid looping.)
Otherwise, split P with the plane of Q (or vice versa).
Delete P from the list. Insert the 2 new polygons in correct
order and proceed.

CS3500 February 17, 2005


22

3 2

No ordering can solve the ambiguities.

Split polygon 1 to 1a (left) and 1b.

Draw in the order: 1b, 2, 3, 1a.


CS3500 February 17, 2005
23

Depth-Sort Algorithms: Discussion


Ensures back-to-front ordering for proper rendering.

No aliasing effects introduced as objects are reordered/split.

Reordering and splitting of polygons have to be done at


run time.

Redo the whole calculations if the view-point changes.

Computationally expensive.

CS3500 February 17, 2005


24

Binary Space Partitioning Trees


Can we have simple linear display algorithm, perhaps
using expensive preprocessing?

Consider a plane in space that divides scene into two


halfs.

Objects on the same side of the plane as the eye cannot


be blocked by objects on the other side.

Each side of the plane can further be divided using other


planes till we reach a single object.
CS3500 February 17, 2005
25

If enviroments consist of clusters of objects, separate


them using an appropriate plane.

We end up with the BSP Tree representation of the


scene.

Internal nodes contain partitioning planes; leaf nodes are


polygons.

Some preprocessing to construct the tree, but simple


algorithm to render using it from any viewpoint.

CS3500 February 17, 2005


26

BSP Trees
Use planes of polygons in the scene as partitioning
planes.

Normal direction indicates the “front” side of the plane.

Each plane divides space into two sides.

If a polygon lies on both sides of the plane, divide it into


two parts.

Continue this recursively till each side contains exactly


one polygon.
CS3500 February 17, 2005
27

Example: BSP Tree


4

3
CS3500 February 17, 2005
28

Psuedocode: BSP Tree Construction


makeBSPTree(pList)
if (pList is empty) return NULL
root selAndRemove(pList); bList, fList NULL
for each polygon p in pList
if (p is in front of root) addToList(p, fList)
elsif (p is in back of root) addToList(p, bList)
else
splitPoly(p, fp, bp)
addToList(fp, fList); addToList(bp, bList)
return combineTree(makeBSPTree(fList),
root, makeBSPTree(bList))
CS3500 February 17, 2005
29

Example: Smallest First

4b
1

1 4a
3 2
2
5b 5a 4b 4a
5a
5b
3

CS3500 February 17, 2005


30

Example: Largest First

4
5
1
4 3
2

5 1 2

CS3500 February 17, 2005


31

Psudeocode: Displaying a BSP Tree


displayBSPTree(bTree)
if (empty(bTree)) return
if (eye in front of root)
displayBSPTree(bTree bChild)
displayPoly(root)
displayBSPTree(bTree fChild)
else
display(BSPTree(bTree fChild)
if (no back-face culling) displayPoly(root)
display(BSPTree(bTree bChild)

CS3500 February 17, 2005


32

Performance Considerations
Construction of the BSP tree is expensive.

No splitting while rendering; everything is done during


preprocessing.

Straightforward display algorithm. Back-face culling


woven into it.

Strategy of selecting the root has a great impact.

Select the polygon that splits least number of polygons.


CS3500 February 17, 2005
33

End of Class 20

CS3500 February 17, 2005


34

Scan-Line Algorithms
Perform visibility computations along with scan conversion.
Modify scan conversion algorithm to handle multiple
polygons for each scan line. Use a Polygon Table (PT)
in addition to the ET.
Spans are further divided into portions depending on the
polygon they belong to.
Compute which polygon is in front for each such span.
An image pixel is computed only once (except, perhaps,
background pixels).
CS3500 March 18, 2004
35

Area-Subdivision Algorithms
If the image to be formed belongs to only one polygon, no
visibility computation.

Else, subdivide the image area into portions and


recursively check for the same!

Several such algorithms can be devised.

An image pixel is computed only once, unlike back-to-


front or z-buffer algorithms.

CS3500 March 18, 2004


36

Octree Visibility Algorithms


Strict ordering of octants for Y
visibility exists for octrees for
orthographic projection, 2 3
6 2 3
given the VPN 6 7 3 3
6 7 7
(View Plane Normal). 6 1
4 5 5

1 X
5
4 5

Only 3 of the faces can be visible from any viewpoint.


CS3500 March 18, 2004
37

If VPN is (+, +, +):

 

 












If VPN is (-, +, +):

 

 











If VPN is (+, +, -):

 











Visit the octree in the back-to-front order, given the
orientation of the camera with respect to the scene.

Holds good for perspective projections also if scene is


only on one side of the plane.

CS3500 March 18, 2004


38

Ray Tracing for Visibility


Perform exactly what our image-precision algorithm
described.
for each pixel in the image
Determine closest object in the direction of projector
Draw the pixel with appropriate colours
Send rays from CoP through each image pixel to the
world.
Called ray tracing or ray casting.
Equation of the ray is known. Need to intersect it with
objects in the world.
CS3500 March 18, 2004
39

Ray Equation
If the CoP is and pixel point is , the











ray is given by



















Negative values of line behind CoP. is at the





projection or pixel plane.

If the scene is in front of the plane, the region of interest


is .



Compute intersections with other objects. Closest object


is the one with the smallest value.


CS3500 March 18, 2004


40

Intersection with Polygons


Plane of the polygon is given by













Intersection point:
 











Does it lie within the polygon?

Project to a coordinate plane and check for 2D polygon


containment.

Use the plane with largest area. This is determined by


the largest absolute value of .





CS3500 March 18, 2004


41

Intersection with a Sphere


Sphere is given by .

 

 

 












Substituting, we get:

 

 

 

























 

 

 









A quadratic equation. Solve for . Real solution with



smaller positive is the one of interest.


Can normalize such that the coefficient of is 1, since



we are interested only in the relative values of .


CS3500 March 18, 2004


42

Ray Tracing: Discussion


Ray tracing is an image precision operation.

Intersection calculations need to be performed for each


ray with each object. Very expensive.

Hierarchical organization and spatial partitioning of data


can help reduce the number of intersections computed.

Coherence in image space enables us to trace a bunch


of rays (beams) to be traced together.

CS3500 March 18, 2004


43

VSD: Summary
Sorting in the right order is key to all of them.
If expensive lighting/shading is used, do not shade an
image pixel more than once.
For quick rendering, z-buffer algorithms are better.
BSP Trees can be fast if environment is static.
Ease of implementation and scope of hardware
acceleration are also important.
Z-buffering is popular due to memory being cheap.

CS3500 March 18, 2004


44

End of Class 21

CS3500 March 18, 2004

You might also like