visible surface determination - gunadarma...

26
Komputer Grafik 2 (AK045206) Visible Surface Visible Surface Determination (Penentuan Permukaan Tampak) Visible Surface Determination 1/26

Upload: vancong

Post on 21-Jun-2019

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Visible Surface Visible Surface Determination

(Penentuan Permukaan Tampak)

Visible Surface Determination 1/26

Page 2: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Outline

• Definisi VSD• Tiga Kelas Algoritma VSD• Kelas : Conservative

Spatial Subdivison– Spatial Subdivison– Bounding Volume– Back Face Culling

• Kelas : Image-Precision– Z-Buffer– Algoritma Painterg

• Kelas : Object-Precision– Algoritma 3-D Sort

Binary Space Partitioning (BSP)

Visible Surface Determination 2/26

– Binary Space Partitioning (BSP)

Page 3: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Visible Surface Determination (1/5)

• Definition– Given a set of 3-D objects and a view

specification (camera), determine which lines or surfaces of the object are visible

– A surface might be occluded by other objects or by the same object (self occlusion)

Visible Surface Determination 3/26

Page 4: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Visible Surface Determination (2/5)

• Historical note– Problem first posed for wireframe

rendering

canonical house

– Solution called “hidden-line removal”• note: lines themselves don’t hide lines.

Lines must be edges of opaque surfaces that hide other lines

• some techniques show hidden line segments as dotted or dashed lines

Visible Surface Determination 4/26

Page 5: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Visible Surface Determination (3/5)

• Three classes of algorithms– “Conservative” visibility testing: only trivial y g y

reject – does not give final answer!• e.g., back-face culling, canonical view volume

clipping, spatial subdivision• have to feed results to algorithms mentioned

below

– Image precision – resolve visibility at discrete points in image

• sample model, then resolve visibility – i.e., figure out which objects it makes sense to compare withcompare with

• e.g., raytracing, or Z-buffer and scan-line depth buffers (both in hardware!)

– Object precision – resolve for all possible view di ti f i i tdirections from a given eye point

• irrespective of view direction or sampling density

• resolve visibility exactly, then sample the resultse g poly’s clipping poly’s 3 D depth sort BSP

Visible Surface Determination 5/26

• e.g., poly’s clipping poly’s, 3-D depth sort, BSP trees

Page 6: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Visible Surface Determination (4/5)

• Criteria to watch forV i diff l ith– Various differences among algorithms:

• what sort of geometry? triangles vs. implicit surfaces

• does it support transparent objects? anti-aliasing?g

• how much of scene has to be considered?– e.g., ray-tracing usually able to consider less

than Z-buffering

• must preprocess the model?• does it easily handle moving objects?• does it easily handle moving objects?• performance: space-time complexity. With large

models, even O(n) too slow– what is n? # total objects, # visible objects, #

pixels…?really some combination i e # total objects x #– really some combination, i.e., # total objects x # pixels

– Pipelines first use some conservative algorithms, then one of the image-precision or object-precision algorithms

Visible Surface Determination 6/26

Page 7: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Visible Surface Determination

• Exploit coherenceTh d t hi h t f i t

(5/5)

– The degree to which parts of an environment exhibit logical similarities. Make good guesses! Reuse previous calculations!

– Image: except at object boundaries, adjacent pixels tend to be from the same objectpixels tend to be from the same object

• scan-line conversion takes advantage of this

– Object: objects aren’t point clouds – they tend to be continuous

• scan-line conversion takes advantage of this

– Visible set: set of visible objects doesn’t change much as viewpoint moves incrementally (largely unexploited)

• most objects don’t move that much frame-to-frameframe

• background objects tend to stay constant while relatively fewer foreground objects move (games take advantage of this!)

– Objects tend to be clustered together in space

Visible Surface Determination 7/26

• spatial subdivision will take advantage of this

Page 8: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Conservative : Object Database jCulling Techniques

• “Conservative” visibility testsHugely important to minimize the load on the pipeline by– Hugely important to minimize the load on the pipeline by culling detail that can’t be seen

• view volume visibility is the most literal application of this principle

• we only see a small portion of the model from any particular viewpoint, particularly for big modelsp p p y g

– Spatially organize model: spatial subdivision, bounding volume hierarchies

– Objects occlude parts of themselves: back-face culling

– Additional techniques (not covered here):• take advantage of walls in games and architectural walk-• take advantage of walls in games and architectural walk-

throughs: “cell-portal visibility”

• use big “blocker” polygons: occlusion culling

Visible Surface Determination 8/26

Page 9: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Bounding VolumesBounding Volumes

– Extents and Bounding Volumes:• bound each complex object with a simpler onep j p

– examples of simpler volumes: sphere, cuboid– Kay & Kajiya SIGGRAPH ’86 uses polyhedra

• if bounding volume isn’t visible, neither is object inside it!

• can put multiple objects into one volume: more efficient

– Great for ray-tracing pipeline!• quick reject: check ray against bounding volume first• quicker reject: check group of rays (frustum) against

bounding volume of object

eyesingle ray

y

arbitrarilycomplexobject

bounding frustum of aboundingb f bj t

– Great for traditional hardware pipeline!• quick reject large numbers of triangles at a time

during clipping• e.g., if bounding box of tessellated sphere is not

i ibl d ’t h t d ll it t i l !

bounding frustum of abundle of rays

box of object

Visible Surface Determination 9/26

visible, don’t have to draw all its triangles!

Page 10: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Spatial Subdivision (1/2)Spatial Subdivision (1/2)

• Another way to organize whole model– Top-down construction: divide and conquer!

– Divide space into cells, place objects in them• scan-converter places polygons in the cells

• raytracer places bounding volumes in the cellsy p g

2-D example of spatial subdivision

Visible Surface Determination 10/26

Page 11: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Spatial Subdivision (2/2)Spatial Subdivision (2/2)

• Applications for both pipelinesR t i “ lk” th h th ll l– Raytracing: rays “walk” through the cells, only checking objects in those cells

ray R only needs to be intersectedray R only needs to be intersected with objects A, B, and C

• start in cell of eye point; skip empty cells; stop walking when we find an intersection

• speedup: walk bundle of rays through the cells

– Scan-conversion: clip groups of polygons at a– Scan-conversion: clip groups of polygons at a time. Only cells impinging on the view volume have their contents processed

Visible Surface Determination 11/26

Page 12: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

B k F C lliBack-Face Culling

• Line of Sight InterpretationApproach assumes objs defined as closed– Approach assumes objs defined as closed polyhedra, w/eye pt always outside of them

– Use outward normal (ON) of polygon to test for rejection

– LOS = Line of Sight, the projector from the t f j ti (COP) t i t Pcenter of projection (COP) to any point P on

the polygon. (For parallel projections LOS = DOP = direction of projection)

– If normal is facing in same direction as LOS, it’s a back face:

if LOS ON 0 th l i i i ibl• if LOS • ON > 0, then polygon is invisible –discard

• if LOS • ON < 0, then polygon may be visible

– To render one lone polyhedron, you need back-face culling as VSD!

Visible Surface Determination 12/26

back-face culling as VSD!

Page 13: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Image Precision :

– Light in the phosphor display of the CRT monitor decays very quickly Screen must be

gReview of Buffers

monitor decays very quickly. Screen must be frequently refreshed (at least 60 times/second) to maintain a constant image without flickering

– Screen is refreshed one scan line at a time from pixel information held in a refresh orfrom pixel information held in a refresh or frame buffer

– Additional buffers can be used to store other pixel information. For example, we will use a z-buffer in which z-values (depth of points on az-buffer in which z-values (depth of points on a polygon) are stored to do VSD

z-buffer with depth values for gray subset

of frame buffer

frame buffer with pixmap

Visible Surface Determination 13/26

of frame buffer

Page 14: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Depth-Buffer Method

• In addition to the frame buffer (that keeps

Depth-Buffer Method (Z-Buffer) (1/4)

the pixel values), keep a Z-buffer containing the depth value of each pixel

• Surfaces are scan-converted in anSurfaces are scan converted in an arbitrary order. For each pixel (x, y), the Z-value is computed as well. The pixel (x, y) is overwritten only if it is closer to the viewing plane than the pixel alreadyviewing plane than the pixel already written at the same location

Visible Surface Determination 14/26

Page 15: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Depth-Buffer Method

Algorithm:

Depth-Buffer Method (Z-Buffer) (2/4)

g• Initialize the z-buffer depth and the frame-buffer I:

depth(x,y) = MAX_Z ; I(x, y) = Ibackground

• Calculate the depth z for each (x, y) position on any surface:any surface:• If z < depth(x, y), then depth(x, y) = z and I(x, y) =

Isurf(x,y)

• Very simple implementation in the case of• Very simple implementation in the case of polygon surfaces. Uses polygon scan line conversion, and exploits face coherence and scan-line coherence :

• z = −(Ax+By+D)/C• z = (Ax+By+D)/C

• Along scan lines

z'= −(A(x+1)+By+D)/C = z−A/C

• Between successive scan lines:

Visible Surface Determination 15/26

z'= −(Ax+B(y+1)+D)/C = z−B/C

Page 16: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Depth-Buffer Method

• Example :

Depth-Buffer Method (Z-Buffer) (3/4)p

Visible Surface Determination 16/26

Page 17: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Depth-Buffer Method

• Implemented in the image space

Depth-Buffer Method (Z-Buffer) (4/4)

• Very common in hardware due its simplicity (SGI)

• 32 bits per pixel for Z is common

• Advantages:– Simple and easy to implement– Buffer may be saved with image for re-

processingprocessing

• Disadvantages:– Requires a lot of memory– Finite depth precision can cause problems– Spends time while rendering polygons that are

not visible– Requires re-calculations when changing the

scale

Visible Surface Determination 17/26

Page 18: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

P i t ’ Al ith

• Simple approach: render the polygons from back to front “painting over”

Painter’s Algorithm

from back to front, “painting over” previous polygons; find a way to sort polygons by depth (z), then draw them in that order

f– do a rough sort of the polygons by the smallest (farthest) z-coordinate in each polygon

– scan-convert the most distant polygon first, then work forward towards the viewpointthen work forward towards the viewpoint (“painters’ algorithm”)

• Intersecting polygons present a problem

Visible Surface Determination 18/26

g p yg p p

Page 19: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

Object-PrecisionObject-Precision

• Historically first approaches– Roberts ’63 - hidden line removal

• compare each edge with every object -eliminate invisible edges or parts of edges.

– A similar approach for hidden surfaces:• each polygon is clipped by the projections of all

other polygons in front of it invisible surfaces are eliminated and visible sub-polygons are created SLOW, ugly special cases, polygons onlyonly

Visible Surface Determination 19/26

Page 20: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

3 D D th S t Al ith (1/2)3-D Depth-Sort Algorithm (1/2)

(Newell, Newell, and Sancha, based on work by Schumacher)S )

• Handles errors/ambiguities of Z-sort:

• Summary of algorithm1. Initially, sort by smallest Zy, y2. Resolve ambiguities:

(a) Compare X extents(b) Compare Y extents(c) Is P entirely on one side of Q?(d) Is Q entirely on one side of P?(e) Compare X-Y projections (Polygon

Intersection)(f) Swap or split polygons

3 Scan convert back to front

Visible Surface Determination 20/26

3. Scan convert back to front

Page 21: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

3 D D th S t Al ith (1/2)

Advantages

3-D Depth-Sort Algorithm (1/2)

– Fast enough for simple scenes

– Fairly intuitive

Disadvantagessad a ages– Slow for even moderately complex

scenes

– Hard to implement and debugp g

– Lots of special cases

Visible Surface Determination 21/26

Page 22: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

S ( / )Binary Space Partitioning (1/4)

•(Fuchs, Kedem, and Naylor, based on work by Schumacher)Schumacher)

– Provides spatial subdivision and draw order

Di id d– Divide and conquer:• to display any polygon correctly, display all polygons

on “far” (relative to viewpoint) side of polygon, then that polygon, then all polygons on polygon’s “near” side.

• but how to display polygons on one side correctly? Choose one polygon and process it recursively!

– Trades off view-independent preprocessing step (extra time and space) for low run-time overhead each time view changes

Visible Surface Determination 22/26

g

Page 23: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

S ( / )Binary Space Partitioning (2/4)

– Perform view-independent step once each time scene changes:time scene changes:

• recursively subdivide environment into a hierarchy of half-spaces by dividing polygons in a half-space by the plane of a selected polygon

• build a BSP tree representing this hierarchybuild a BSP tree representing this hierarchy

• each selected polygon is the root of a sub-tree

– An example:

Visible Surface Determination 23/26

Page 24: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

S ( / )Binary Space Partitioning (3/4)

BSP-1: Choose any polygon (e.g., polygon 3) and subdivide Others by its plane, splitting polygons when necessary

BSP-2: Process front sub-tree recursively

Visible Surface Determination 24/26

BSP-2: Process front sub-tree recursively

Page 25: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

S ( / )Binary Space Partitioning (4/4)

BSP-3: Process back sub-tree recursively

BSP-4: An alternative BSP tree with polygon 5 at the root

Visible Surface Determination 25/26

BSP-4: An alternative BSP tree with polygon 5 at the root

Page 26: Visible Surface Determination - Gunadarma Universitykarmila.staff.gunadarma.ac.id/Downloads/files/38473/VSD.pdf · Komputer Grafik 2 (AK045206) Outline • Definisi VSD • Tiga Kelas

Komputer Grafik 2 (AK045206)

R f iReferensi

• F.S.Hill, Jr., COMPUTER GRAPHICS –Using Open GL Second EditionUsing Open GL, Second Edition, Prentice Hall, 2001

• Andries van Dam, Introduction to Computer Graphics, Slide-Presentation, Brown University, 2003, (folder : brownUni)

• __________, Interactive Computer Graphic, Slide-Presentation, (folder : p , , (Lect_IC_AC_UK)

• _________, CS 445/645 : Introduction to Computer Graphics, Slide-Presentation Virginia University (folderPresentation, Virginia University (folder :COMP_GRAFIK)

Visible Surface Determination 26/26