I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember...

31
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avd November 4, 2003 VSD 1/46 CIS 736 Computer Graphics Visible Surface Determination 1 of 2: Monday, 23 February 2004 Reading: Hardware Rendering (shader_lecture) Adapted with Permission W. H. Hsu http:// www.kddresearch.org

Transcript of I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember...

Page 1: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

History and modern practice

avd November 4, 2003 VSD 1/46

CIS 736 Computer Graphics

Visible Surface Determination 1 of 2:

Monday, 23 February 2004Reading: Hardware Rendering (shader_lecture)

Adapted with Permission

W. H. Hsu

http://www.kddresearch.org

Page 2: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Raytracing “Pipeline”• Raytracer produces visible samples from model, samples

convolved w/filter to form pixel image-traverse model-accumulate CTM-spatially organize objects

scene graphobject database

suitable forray-tracing

loop over objs intersect with each ray keep track of closest t

light the sample

all samples filter pixels of final image

preprocessing step

closest pt

for each desired sample: (some (u, v) on film plane)

generate ray

avd November 4, 2003 VSD 2/46

generate secondary rays

Page 3: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Rendering Polygons (1/2)Raytracing could work…

• Raytracing and implicit surface model definition go well together

• But many of our existing models and modeling apps are still based on polygon meshes. How do we render them?

– can raytrace polygons…

– better solution: traditional polygons-to-pixels pipeline

• Ray-Triangle intersection is not too hard…– do ray-intersect-plane using the plane of the polygon

– check if resulting point is inside the triangle

– fast methods using Plücker coordinates or barycentric coordinates

• Ray-Polygon intersection is similar…– can decompose into triangles

jpa,avd November 9, 2000 VSD 3/45avd November 4, 2003 VSD 3/46

Page 4: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Rendering Polygons (2/2)…but there’s a faster way

• The number of polygons is a real problem– in a typical mesh representation, there are a lot of triangles, and

each is an object that has to be considered in our intersection tests

• We can reduce the number of intersection tests with other VSD algorithms, but only to some extent…

• Traditional hardware polygon pipeline is faster– uses the very efficient Z-buffer one-polygon-at-a-time Visible

Surface Determination algorithm

– uses an approximate shading (interpolation) rule (still same lighting equation as ray-tracing) to calculate most pixels

avd November 4, 2003 VSD 4/46

Page 5: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Traditional Hardware PipelinePolygonal rendering w/ Z-buffer

• Polygons approximate actual geometry• Non-global illumination approximates lighting• Shading approximates lighting of each sample point; it’s fast, and

it looks ok• Based on calculation and comparison of z (depth) values per

pixel– much faster than solving many implicit surface equations per pixel

• N.B. Simplified from actual pipelines– (no texture maps, anti-aliasing, transparency)

• pixel processing always in hardware; rest depends

avd November 4, 2003 VSD 5/46

Page 6: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Pipeline Flow

avd November 5, 2002 VSD 5/45avd November 4, 2003 VSD 6/46

conservativeVSD

Selectivetraversal of

objectdatabase(optional;otherwise,traverse

entire scenegraph to

accumulateCTM)

TransformVertices

to canonicalview volume

Light atVertices

Use lightingmodel of choice

to calculatelight intensity

at polygonvertices

conservative VSD

Back-faceCulling

conservativeVSD

View VolumeClipping

image-precisionVSD

Comparisonof pixel depth

(Z-bufferalgorithm)

Shading

interpolatecolor values(Gouraud)or normals

(Phong)

per polygon per pixel of polygon

Viewing: Geometry ProcessingWorld Coordinates (floating point)

Rendering Pixel ProcessingScreen Coordinates (integer)

Page 7: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Raytracing vs. Poly Pipeline (1/3)Conventional wisdom

• Not competitors!– “polygon pipelines are far faster, but produce images of inferior quality”

– “polygon pipelines render in real-time, raytracing only in batch”

• Why has raytracing pipeline traditionally been much slower than polygon pipeline?

– loops over more samples per object

– computing t’s (solving implicit surface equation) harder than computing z’s

– drawing the many triangles in a tessellated sphere faster than raytracing a single sphere object that projects onto multiple pixels!

– time complexity for polygon pipeline tends not to explode with finer tessellation (unlike other algorithms)

#-of-polygons x #-of-pixels/polygon constant

• “Optimized raytracing is still too expensive for real-time applications (for now).” - avd

avd November 4, 2003 VSD 7/46

Page 8: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Raytracing vs. Poly Pipeline (2/3)Unconventional wisdom

• Pat Hanrahan and Seth Teller: “raytracing WILL be competitive”

• Polygon pipelines have to consider every object in the view frustum, occluded or not

• Rays in raytracing pipelines can examine the scene front-to-back and stop at the first cell where there is an intersection

• When # polygons in view frustum gets big enough, raytracing becomes the faster of the two

• How big is “big enough?”– recent paper at Eurographics—Wald & Slusallek, “Interactive

Rendering with Coherent Ray Tracing,” in Eurographics 2001—demonstrates interactive frame rates at 2.5 M polygons from a raytracer which outperforms most polygon hardware

avd November 4, 2003 VSD 8/46

Page 9: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Raytracing vs. Poly Pipeline (3/3)A final assessment

• What are we comparing, anyway? One sample/pixel? How much tessellation?– the pipelines always produce different images!

• Another factor: “acceptable” speed!

• Polygon graphics processors are doubling speed every 6 mos.

• General-purpose processors (which raytracers and the front end of polygon pipelines depend on) are doubling in speed every 18 mos.

• Models never as complex as we’d like…– but once models get huge, other issues surface; i.e., not enough RAM

– SIGGRAPH ’96: Pharr & Hanrahan – paper dedicated to handling models far bigger than memory

– SIGGRAPH ’98: P & H & others – 2 billion triangles

– special software (Large Model Viewing) becoming a standard API on top of a rendering pipeline

• On balance: both will be useful…

avd November 4, 2003 VSD 9/46

Page 10: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

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

– you’ve already seen a VSD step…computing the smallest non-negative t value along a ray

– why might objects not be visible? occlusion vs. clipping

– clipping is one object at a time while occlusion is global

• Also called Hidden Surface Removal (HSR)

avd November 4, 2003 VSD 10/46

Page 11: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Visible Surface Determination (2/5)Historical note

• Problem first posed for wireframe rendering

• 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

canonical house

avd November 4, 2003 VSD 11/46

Page 12: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Visible Surface Determination (3/5)Three classes of algorithms

• “Conservative” visibility testing: only trivial 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 with

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

• Object precision – resolve for all possible view directions from a given eye point

– irrespective of view direction or sampling density

– resolve visibility exactly, then sample the results

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

avd November 4, 2003 VSD 12/46

Page 13: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Visible Surface Determination (4/5)Criteria to watch for

• Various differences among algorithms:– what sort of geometry? triangles vs. implicit surfaces

– does it support transparent objects? anti-aliasing?

– 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?

– 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 # pixels

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

avd November 4, 2003 VSD 13/46

Page 14: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Visible Surface Determination (5/5)Exploit coherence

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

– 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– spatial subdivision will take advantage of this

avd November 4, 2003 VSD 14/46

Page 15: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Object Database Culling Techniques“Conservative” visibility tests

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

• 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-throughs: “cell-

portal visibility”

– use big “blocker” polygons: occlusion culling

avd November 4, 2003 VSD 15/46

Page 16: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Bounding Volumes• Extents and Bounding Volumes:

– bound each complex object with a simpler one• 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

• 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 visible, don’t have to draw all its triangles!

single rayeye

arbitrarilycomplexobject bounding frustum of a

bundle of rays

boundingbox of object

avd November 4, 2003 VSD 16/46

Page 17: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Bounding Volume Hierarchy (1/2)A technique for organizing entire model

• Two methods of construction

• Repeatedly group bounding volumes of nearby objects together until entire scene is bounded

– requires some form of spatial sorting

• Could use original scene graph: bounding volumes at nodes = union of child bounding volumes

– easy to make…

– only useful if scene graph is already spatially coherent (otherwise boxes will not be tight)

A

B

Croot volume

bbox A bbox B bbox C

A B C

avd November 4, 2003 VSD 17/46

Page 18: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Bounding Volume Hierarchy (2/2)Applications in both pipelines

• Raytracing: if ray intersects parent, check the children

• Scan-conversion: if root not completely clipped, check the children recursively– if we’re at a leaf, pass its polygons to the pipeline

A

B

Croot volume

bbox A bbox B bbox C

A B C

1. check root bbox; hit, so check children2. check bbox A; miss3. check bbox B; miss4. check bbox C; hit, so check children

5. check C; hit!6. all done; C was closest

root

avd November 4, 2003 VSD 18/46

Page 19: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Spatial Subdivision (1/3)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 cells

2-D example of spatial subdivision

avd November 4, 2003 VSD 19/46

Page 20: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Spatial Subdivision (2/3)Applications for both pipelines

• Raytracing: rays “walk” through the cells, only checking objects in those cells

– 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 time. Only cells impinging on the view volume have their contents processed

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

avd November 4, 2003 VSD 20/46

Page 21: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Spatial Subdivision (3/3)Methods of Spatial Subdivision

• Regular Grids– in one approach, the environment is partitioned into a regular grid of equal-sized

rectangular volumes

– easy to traverse– non adaptive: doesn’t account for varying object density

• Octrees– world is divided into 8 cubes, and objects are sorted by which cube they belong to.

Recurse by subdividing each cube until # objs/cube is low– 2-D equivalent: quadtrees– hierarchical– sensitive to scene density – more work for a ray to traverse

• BSP trees (Binary Space Partitioning)– world is recursively divided by arbitrary split planes; objects sorted by which side of

the plane they’re on– even more sensitive to scene, even harder for a ray to traverse!

avd November 4, 2003 VSD 21/46

Page 22: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Global Scene OrganizationSummary

• Hybrid techniques best: combine spatial subdivision and bounding volume scenegraph hierarchies

• Trade-off upfront investment in constructing object database for savings during every subsequent rendering pass

– construct only once

– speeds up every frame:• raytracer gets speedup for every ray

• hardware pipeline draws fewer triangles

– “lazy” or on-the-fly subdivision – only when cell touched – could be better than a-priori subdivision!

– really good for (largely) static scenes, really bad for scenes with lots of moving objects

• The Ray-Tracing News: lots of algorithms, deep thoughts from hard-core “raytracin’ dudes,” published at random intervals

– http://www.acm.org/tog/resources/RTNews/html/

avd November 4, 2003 VSD 22/46

Page 23: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Clipping Against View Volume• Polyhedra transformed to the normalized world are clipped against the bounds of

the canonical view volume, a polygon at a time

• Polygons are clipped an edge at a time

• Intersection calculations are trivial because of the normalized planes of the canonical view volume

• New vertices are created where objects are clipped

• Use bounding volumes to trivially reject groups of objects at a time

• Raytracing doesn’t strictly need to clip polygons against the view volume: why?

avd November 4, 2003 VSD 23/46

Page 24: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Back-Face Culling (1/2)Line of Sight Interpretation

• 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 center 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, 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!

avd November 4, 2003 VSD 24/46

Page 25: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Back-Face Culling (2/2)Plane Half-Spaces Interpretation

• A plane can be defined by a normal N and any point, P0, on the plane:– plane satisfied by NxPx + NyPy + NzPz+ D= 0– rewrite as (N • P) + D = 0– pick another point, P1; then we can say N •(P1 – P0) = 0– notice that –N •P0 is constant; let’s call it D– solve for D using any point on the plane.

• Plane divides all points into two half-spaces– (N • P) + D = 0, P is on plane– (N • P) + D > 0, P is in positive half-space– (N • P) + D < 0, P is in negative half-space

• Can define polyhedron as intersection of planes: face = plane

• Polygon faces away for eye points in the negative half-space– this slide: if (N • Eye) + D< 0, discard

– previous slide: if (N • LOS) >=0, discard

– LOS = P – Eye; D = -(N • P): they’re equivalent!

• Faster than recalculating LOS per-polygon (3 subs, 3 mults, 3 adds vs. 3 mults and 4 adds)

avd November 4, 2003 VSD 25/46

Page 26: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Back-Face Culling (3/3)How we do it using immediate-mode APIs

• Only have a triangle, no sense of “inside-outside”

• But the triangle is derived from tessellating the surface of a solid object. Therefore, as you tessellate, specify the vertices with a particular winding with respect to an outward normal (specifically, you used a counter-clock-wise winding for your Shapes assignment)

• Open GL automatically computes an outward normal from the cross product of two consecutive screen-space edges and culls back-facing polygons

– just checks the sign of the resulting z component

avd November 4, 2003 VSD 26/46

Page 27: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Recall the Perspective Transformation (PT) (1/2)

• The PT preserves “in front of” relationships, straight lines and planes, and performs perspective foreshortening

Canonical perspective-projection view volume with cube

After Perspective Transformation to normalized parallel-projection view volume. Note that cube is distorted (perspective foreshortening).(Remember PT transforms z from [-1,0] to [0,1])

avd November 4, 2003 VSD 27/46

(1,1,1)

(-1,-1,0)

(-1,1,-1)

(k,-k,-k)

-

Page 28: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Perspective Transformation (2/2)• Clipping after PT is simply along planes defined by

(-1 < x < 1), (-1 < y < 1), (0 < z < 1)• Depth comparison before PT

– compare every two points, e.g., and :perform calculation to determine if they are on same projector (a lot of work)

– if (x, y) pairs are on same projector, then z-values are compared• Depth comparison after the PT

– compare every two points, e.g., and : must , and must for one of those points to obscure the other, i.e., to be on the same projector (not much work to perform necessary comparisons)

– if the (x’, y’) pairs are equal then the z-values are compared• Projection after PT is just discarding z-values!

avd November 4, 2003 VSD 28/46

1'P 2'P

1P 2P

1'x 2'x 1'y 2'y

Page 29: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Review of Buffers• Light in the phosphor display of the CRT 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 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 a polygon) are stored to do VSD

avd November 4, 2003 VSD 29/46

(shown as floats, though typically 24bit or 32bit ints)

z-buffer with depth values for gray subset of

frame buffer

frame buffer with pixmap

Page 30: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Depth Comparison using a Z-Buffer – Image Precision

The Z-buffer algorithm• The Z-buffer is initialized to the background value (furthest plane of

view volume = 1.0)

• As each object is traversed, the z-values of all its sample points are compared to the z-value in the same (x, y) location in the Z-buffer

– z could be determined by plugging x and y into the plane equation for the polygon (ax + by + cz + d = 0)

– in reality, we calculate the z at vertices and interpolate the rest

• If the new point has z value less than the previous one (i.e., closer to the eye), its z-value is placed in the z-buffer and its color placed in the frame buffer at the same (x, y); otherwise the previous z-value and frame buffer color are unchanged

• Can store depth as integers or floats or fixed points– i.e.for 8-bit (1 byte) integer z-buffer, set 0.0 ->0 and 1.0 ->255

– each representation has its advantages in terms of precision

avd November 4, 2003 VSD 30/46

Page 31: I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S History and modern practice avdNovember 4, 2003VSD 1/46 CIS 736 Computer Graphics Visible Surface.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S

Z-Buffer Algorithm (1/3)• Requires two “buffers”

Intensity Buffer —our familiar RGB pixel buffer

—initialized to background color

Depth (“Z”) Buffer —depth of scene at each pixel

—initialized to far depth = 255

• Polygons are scan-converted in arbitrary order. When pixels overlap, use Z-buffer to decide which polygon “gets” that pixel

Above: example using integer Z-buffer with near = 0, far = 255

avd November 4, 2003 VSD 31/46

255 255 255 255 255 255 255 255

255 255 255 255 255 255 255 255255 255 255 255 255 255 255 255255 255 255 255 255 255 255 255255 255 255 255 255 255 255 255255 255 255 255 255 255 255 255255 255 255 255 255 255 255 255255 255 255 255 255 255 255 255

127 127 127 127 127 127 127 255

127 127 127 127 127 127 255 255127 127 127 127 127 255 255 255127 127 127 127 255 255 255 255127 127 127 255 255 255 255 255127 127 255 255 255 255 255 255127 255 255 255 255 255 255 255255 255 255 255 255 255 255 255

127 127 127 127 127 127 127

127 127 127 127 127 127127 127 127 127 127127 127 127 127127 127 127127 127127

127 127 127 127 127 127 127 255

127 127 127 127 127 127 255 255127 127 127 127 127 255 255 255127 127 127 127 255 255 255 255127 127 127 255 255 255 255 255127 127 255 255 255 255 255 255127 255 255 255 255 255 255 255255 255 255 255 255 255 255 255

+ =

127 127 127 127 127 127 127 255

127 127 127 127 127 127 255 255127 127 127 127 127 255 255 25563 127 127 127 255 255 255 25563 63 127 255 255 255 255 25563 63 63 255 255 255 255 25563 63 63 63 255 255 255 25563 63 63 63 63 255 255 255

6363 6363 63 6363 63 63 6363 63 63 63 63

+ =