3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
3D graphics eBook - Course Materials Repository
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Z-buffering 249<br />
The invention of the z-buffer concept is most often attributed to Edwin Catmull, although Wolfgang Straßer also<br />
described this idea in his 1974 Ph.D. thesis 1 .<br />
On recent PC <strong>graphics</strong> cards (1999–2005), z-buffer management uses a significant chunk of the available memory<br />
bandwidth. Various methods have been employed to reduce the performance cost of z-buffering, such as lossless<br />
compression (computer resources to compress/decompress are cheaper than bandwidth) and ultra fast hardware<br />
z-clear that makes obsolete the "one frame positive, one frame negative" trick (skipping inter-frame clear altogether<br />
using signed numbers to cleverly check depths).<br />
Z-culling<br />
In rendering, z-culling is early pixel elimination based on depth, a method that provides an increase in performance<br />
when rendering of hidden surfaces is costly. It is a direct consequence of z-buffering, where the depth of each pixel<br />
candidate is compared to the depth of existing geometry behind which it might be hidden.<br />
When using a z-buffer, a pixel can be culled (discarded) as soon as its depth is known, which makes it possible to<br />
skip the entire process of lighting and texturing a pixel that would not be visible anyway. Also, time-consuming<br />
pixel shaders will generally not be executed for the culled pixels. This makes z-culling a good optimization<br />
candidate in situations where fillrate, lighting, texturing or pixel shaders are the main bottlenecks.<br />
While z-buffering allows the geometry to be unsorted, sorting polygons by increasing depth (thus using a reverse<br />
painter's algorithm) allows each screen pixel to be rendered fewer times. This can increase performance in<br />
fillrate-limited scenes with large amounts of overdraw, but if not combined with z-buffering it suffers from severe<br />
problems such as:<br />
• polygons might occlude one another in a cycle (e.g. : triangle A occludes B, B occludes C, C occludes A), and<br />
• there is no canonical "closest" point on a triangle (e.g.: no matter whether one sorts triangles by their centroid or<br />
closest point or furthest point, one can always find two triangles A and B such that A is "closer" but in reality B<br />
should be drawn first).<br />
As such, a reverse painter's algorithm cannot be used as an alternative to Z-culling (without strenuous<br />
re-engineering), except as an optimization to Z-culling. For example, an optimization might be to keep polygons<br />
sorted according to x/y-location and z-depth to provide bounds, in an effort to quickly determine if two polygons<br />
might possibly have an occlusion interaction.<br />
Algorithm<br />
Given: A list of polygons {P1,P2,.....Pn}<br />
Output: A COLOR array, which display the intensity of the visible polygon surfaces.<br />
Initialize:<br />
Begin:<br />
note : z-depth and z-buffer(x,y) is positive........<br />
z-buffer(x,y)=max depth; and<br />
COLOR(x,y)=background color.<br />
for(each polygon P in the polygon list) do{<br />
for(each pixel(x,y) that intersects P) do{<br />
Calculate z-depth of P at (x,y)<br />
}<br />
If (z-depth < z-buffer[x,y]) then{<br />
z-buffer[x,y]=z-depth;<br />
COLOR(x,y)=Intensity of P at(x,y);