HOME

TheInfoList



OR:

A z-buffer, also known as a depth buffer, is a type of
data buffer In computer science, a data buffer (or just buffer) is a region of memory used to store data temporarily while it is being moved from one place to another. Typically, the data is stored in a buffer as it is retrieved from an input device (such as ...
used in
computer graphics Computer graphics deals with generating images and art with the aid of computers. Computer graphics is a core technology in digital photography, film, video games, digital art, cell phone and computer displays, and many specialized applications. ...
to store the depth information of fragments. The values stored represent the distance to the camera, with 0 being the closest. The encoding scheme may be flipped with the highest number being the value closest to camera. In a 3D-rendering pipeline, when an object is projected on the screen, the depth (z-value) of a generated fragment in the projected screen image is compared to the value already stored in the buffer (depth test), and replaces it if the new value is closer. It works in tandem with the
rasterizer In computer graphics, rasterisation (British English) or rasterization (American English) is the task of taking an Digital image, image described in a vector graphics format (shapes) and converting it into a raster image (a series of pixels, dots ...
, which computes the colored values. The fragment output by the rasterizer is saved if it is not overlapped by another fragment. Z-buffering is a technique used in almost all contemporary computers, laptops, and mobile phones for generating
3D computer graphics 3D computer graphics, sometimes called Computer-generated imagery, CGI, 3D-CGI or three-dimensional Computer-generated imagery, computer graphics, are graphics that use a three-dimensional representation of geometric data (often Cartesian coor ...
. The primary use now is for
video games A video game or computer game is an electronic game that involves interaction with a user interface or input device (such as a joystick, game controller, controller, computer keyboard, keyboard, or motion sensing device) to generate visual fe ...
, which require fast and accurate processing of 3D scenes.


Usage


Occlusion

Determining what should be displayed on the screen and what should be omitted is a multi-step process utilising various techniques. Using a z-buffer is the final step in this process. Each time an object is rendered into the
framebuffer A framebuffer (frame buffer, or sometimes framestore) is a portion of random-access memory (RAM) containing a bitmap that drives a video display. It is a memory buffer containing data representing all the pixels in a complete video frame. Mode ...
the z-buffer is used to compare the z-values of the fragments with the z-value already in the z-buffer (i.e., check what is closer), if the new z-value is closer than the old value, the fragment is written into the framebuffer and this new closer value is written into the z-buffer. If the z-value is further away than the value in the z-buffer, the fragment is discarded. This is repeated for all objects and surfaces in the scene (often in parallel). In the end, the z-buffer will allow correct reproduction of the usual
depth perception Depth perception is the ability to perceive distance to objects in the world using the visual system and visual perception. It is a major factor in perceiving the world in three dimensions. Depth sensation is the corresponding term for non-hum ...
: a close object hides one further away. This is called z-culling. The
granularity Granularity (also called graininess) is the degree to which a material or system is composed of distinguishable pieces, "granules" or "grains" (metaphorically). It can either refer to the extent to which a larger entity is subdivided, or the ...
of a z-buffer has a great influence on the scene quality: the traditional
16-bit 16-bit microcomputers are microcomputers that use 16-bit microprocessors. A 16-bit register can store 216 different values. The range of integer values that can be stored in 16 bits depends on the integer representation used. With the two ...
z-buffer can result in artifacts (called "
z-fighting Demonstration of z-fighting with multiple colors and textures over a grey background Z-fighting, also called stitching or planefighting, is a phenomenon in 3D rendering that occurs when two or more primitives have very similar distances to the ...
" or stitching) when two objects are very close to each other. A more modern
24-bit Notable 24-bit machines include the CDC 924 – a 24-bit version of the CDC 1604, CDC lower 3000 series, SDS 930 and SDS 940, the ICT 1900 series, the Elliott 4100 series, and the Datacraft minicomputers/ Harris H series. The term SWORD ...
or
32-bit In computer architecture, 32-bit computing refers to computer systems with a processor, memory, and other major system components that operate on data in a maximum of 32- bit units. Compared to smaller bit widths, 32-bit computers can perform la ...
z-buffer behaves much better, although the problem cannot be eliminated without additional algorithms. An
8-bit In computer architecture, 8-bit integers or other data units are those that are 8 bits wide (1 octet). Also, 8-bit central processing unit (CPU) and arithmetic logic unit (ALU) architectures are those that are based on registers or data bu ...
z-buffer is almost never used since it has too little precision.


Shadow mapping

Z-buffer data obtained from rendering a surface from a light's point-of-view permits the creation of shadows by the
shadow mapping Shadow mapping or shadowing projection is a process by which shadows are added to 3D computer graphics. This concept was introduced by Lance Williams in 1978, in a paper entitled "Casting curved shadows on curved surfaces." Since then, it has b ...
technique.


History

Z-buffering was first described in 1974 by Wolfgang Straßer in his PhD thesis on fast algorithms for rendering occluded objects. A similar solution to determining overlapping polygons is the
painter's algorithm The painter's algorithm (also depth-sort algorithm and priority fill) is an algorithm for Hidden-surface determination#Visible surface determination, visible surface determination in 3D computer graphics that works on a polygon, polygon-by-polyg ...
, which is capable of handling non-opaque scene elements, though at the cost of efficiency and incorrect results. Z-buffers are often implemented in hardware within consumer
graphics cards A graphics card (also called a video card, display card, graphics accelerator, graphics adapter, VGA card/VGA, video adapter, display adapter, or colloquially GPU) is a computer expansion card that generates a feed of graphics output to a displa ...
. Z-buffering is also used (implemented as software as opposed to hardware) for producing computer-generated special effects for films.


Developments

Even with small enough granularity, quality problems may arise when precision in the z-buffer's distance values are not spread evenly over distance. Nearer values are much more precise (and hence can display closer objects better) than values that are farther away. Generally, this is desirable, but sometimes it will cause artifacts to appear as objects become more distant. A variation on z-buffering which results in more evenly distributed precision is called w-buffering (see
below Below may refer to: *Earth *Ground (disambiguation) *Soil *Floor * Bottom (disambiguation) *Less than *Temperatures below freezing *Hell or underworld People with the surname * Ernst von Below (1863–1955), German World War I general * Fred Belo ...
). At the start of a new scene, the z-buffer must be cleared to a defined value, usually 1.0, because this value is the upper limit (on a scale of 0 to 1) of depth, meaning that no object is present at this point through the
viewing frustum In 3D computer graphics, a viewing frustum or view frustum is the region of space in the modeled world that may appear on the screen; it is the field of view of a perspective virtual camera system. The view frustum is typically obtained by t ...
. The invention of the z-buffer concept is most often attributed to
Edwin Catmull Edwin Earl Catmull (born March 31, 1945) is an American computer scientist and animator who served as the co-founder of Pixar and the President of Walt Disney Animation Studios. He has been honored for his contributions to 3D computer graphics, ...
, although Wolfgang Straßer described this idea in his 1974 Ph.D. thesis months before Catmull's invention. On more recent PC graphics cards (1999–2005), z-buffer management uses a significant chunk of the available memory
bandwidth Bandwidth commonly refers to: * Bandwidth (signal processing) or ''analog bandwidth'', ''frequency bandwidth'', or ''radio bandwidth'', a measure of the width of a frequency range * Bandwidth (computing), the rate of data transfer, bit rate or thr ...
. Various methods have been employed to reduce the performance cost of z-buffering, such as
lossless compression Lossless compression is a class of data compression that allows the original data to be perfectly reconstructed from the compressed data with no loss of information. Lossless compression is possible because most real-world data exhibits statisti ...
(computer resources to compress/decompress are cheaper than bandwidth) and ultra-fast hardware z-clear that makes obsolete the "one frame positive, one frame negative" trick (skipping inter-frame clear altogether using signed numbers to cleverly check depths). Some games, notably several games later in the
Nintendo 64 The (N64) is a home video game console developed and marketed by Nintendo. It was released in Japan on June 23, 1996, in North America on September 29, 1996, and in Europe and Australia on March 1, 1997. As the successor to the Super Nintendo E ...
's life cycle, decided to either minimize z-buffering (for example, rendering the background first without z-buffering and only using z-buffering for the foreground objects) or to omit it entirely, to reduce memory bandwidth requirements and memory requirements respectively. Super Smash Bros. and F-Zero X are two Nintendo 64 games that minimized z-buffering to increase framerates. Several
Factor 5 Factor 5 GmbH was a German-American Independent business, independent software and video game developer. The company was co-founded by five former Rainbow Arts employees in 1987 in Cologne, Germany, which served as the inspiration behind the st ...
games also minimized or omitted z-buffering. On the Nintendo 64 z-Buffering can consume up to 4x as much bandwidth as opposed to not using z-buffering.
Mechwarrior 2 ''MechWarrior 2: 31st Century Combat'' is a vehicle simulation game developed and published by Activision, released in 1995 as part of the '' MechWarrior'' series of video games in the ''BattleTech'' franchise. The game is set in 3057, and is pla ...
on PC supported resolutions up to 800x600 on the original 4 MB
3dfx 3dfx Interactive, Inc. was an American computer hardware company headquartered in San Jose, California, founded in 1994, that specialized in the manufacturing of 3D graphics processing units, and later, video cards. It was a pioneer in the f ...
Voodoo due to not using z-buffering.


Z-culling

In rendering, z-culling is early pixel elimination based on depth, a method that provides an increase in performance when rendering of hidden surfaces is costly. It is a direct consequence of z-buffering, where the depth of each pixel candidate is compared to the depth of the existing geometry behind which it might be hidden. When using a z-buffer, a pixel can be culled (discarded) as soon as its depth is known, which makes it possible to skip the entire process of lighting and texturing a pixel that would not be visible anyway. Also, time-consuming
pixel shader In computer graphics, a shader is a computer program that calculates the appropriate levels of light, darkness, and color during the rendering of a 3D scene—a process known as '' shading''. Shaders have evolved to perform a variety of s ...
s will generally not be executed for the culled pixels. This makes z-culling a good optimization candidate in situations where
fillrate In computer graphics, a video card's pixel fillrate refers to the number of pixels that can be Rendering (computer graphics), rendered on the screen and written to Video random access memory, video memory in one second. Pixel fillrates are give ...
, lighting, texturing, or pixel shaders are the main bottlenecks. While z-buffering allows the geometry to be unsorted, sorting
polygons In geometry, a polygon () is a plane figure made up of line segments connected to form a closed polygonal chain. The segments of a closed polygonal chain are called its '' edges'' or ''sides''. The points where two edges meet are the polygon' ...
by increasing depth (thus using a reverse
painter's algorithm The painter's algorithm (also depth-sort algorithm and priority fill) is an algorithm for Hidden-surface determination#Visible surface determination, visible surface determination in 3D computer graphics that works on a polygon, polygon-by-polyg ...
) allows each screen pixel to be rendered fewer times. This can increase performance in fillrate-limited scenes with large amounts of overdraw, but if not combined with z-buffering it suffers from severe problems such as: * polygons occluding one another in a cycle (e.g. triangle A occludes B, B occludes C, C occludes A) * the lack of any canonical "closest" point on a triangle (i.e. no matter whether one sorts triangles by their
centroid In mathematics and physics, the centroid, also known as geometric center or center of figure, of a plane figure or solid figure is the arithmetic mean position of all the points in the figure. The same definition extends to any object in n-d ...
or closest point or furthest point, one can always find two triangles A and B such that A is "closer" but in reality B should be drawn first). As such, a reverse painter's algorithm cannot be used as an alternative to z-culling (without strenuous re-engineering), except as an optimization to z-culling. For example, an optimization might be to keep polygons sorted according to x/y-location and z-depth to provide bounds, in an effort to quickly determine if two polygons might possibly have an occlusion interaction.


Mathematics

The range of depth values in camera space to be rendered is often defined between a \textit and \textit value of z. After a perspective transformation, the new value of z, or z', is defined by: : z'= \frac + \frac \left(\frac\right) After an
orthographic projection Orthographic projection (also orthogonal projection and analemma) is a means of representing Three-dimensional space, three-dimensional objects in Plane (mathematics), two dimensions. Orthographic projection is a form of parallel projection in ...
, the new value of z, or z', is defined by: :z'= 2 \cdot \frac - 1 where z is the old value of z in camera space, and is sometimes called w or w'. The resulting values of z' are normalized between the values of -1 and 1, where the \textit plane is at -1 and the \mathit plane is at 1. Values outside of this range correspond to points which are not in the viewing
frustum In geometry, a ; (: frusta or frustums) is the portion of a polyhedron, solid (normally a pyramid (geometry), pyramid or a cone (geometry), cone) that lies between two parallel planes cutting the solid. In the case of a pyramid, the base faces a ...
, and shouldn't be rendered.


Fixed-point representation

Typically, these values are stored in the z-buffer of the hardware graphics accelerator in fixed point format. First they are normalized to a more common range which is by substituting the appropriate conversion z'_2 = \frac\left(z'_1 + 1\right) into the previous formula: :z'= \frac + \frac + \frac \left(\frac\right) Simplifying: :z'= \frac + \frac \left(\frac\right) Second, the above formula is multiplied by S = 2^d - 1 where d is the depth of the z-buffer (usually 16, 24 or 32 bits) and rounding the result to an integer: :z' = f(z) = \left\lfloor \left(2^d - 1\right) \cdot \left(\frac + \frac \left(\frac\right) \right)\right\rfloor This formula can be inverted and derived in order to calculate the z-buffer resolution (the 'granularity' mentioned earlier). The inverse of the above f(z)\,: :z = \frac = \frac where S = 2^d - 1 The z-buffer resolution in terms of camera space would be the incremental value resulted from the smallest change in the integer stored in the z-buffer, which is +1 or -1. Therefore, this resolution can be calculated from the derivative of z as a function of z': :\frac = \frac \cdot \left(\textit - \textit\right) Expressing it back in camera space terms, by substituting z' by the above f(z)\,: :\begin \frac &= \frac \\ &= \frac \\ &= \frac - \frac \approx \frac \end This shows that the values of z' are grouped much more densely near the \textit plane, and much more sparsely farther away, resulting in better precision closer to the camera. The smaller near is, the less precision there is far away—having the near plane set too closely is a common cause of undesirable rendering artifacts in more distant objects. To implement a z-buffer, the values of z' are linearly interpolated across screen space between the vertices of the current
polygon In geometry, a polygon () is a plane figure made up of line segments connected to form a closed polygonal chain. The segments of a closed polygonal chain are called its '' edges'' or ''sides''. The points where two edges meet are the polygon ...
, and these intermediate values are generally stored in the z-buffer in fixed point format.


W-buffer

To implement a w-buffer, the old values of z in camera space, or w, are stored in the buffer, generally in
floating point In computing, floating-point arithmetic (FP) is arithmetic on subsets of real numbers formed by a ''significand'' (a signed sequence of a fixed number of digits in some base) multiplied by an integer power of that base. Numbers of this form ...
format. However, these values cannot be linearly interpolated across screen space from the vertices—they usually have to be inverted, interpolated, and then inverted again. The resulting values of w, as opposed to z', are spaced evenly between \textit and \textit. There are implementations of the w-buffer that avoid the inversions altogether. Whether a z-buffer or w-buffer results in a better image depends on the application.


Algorithmics

The following
pseudocode In computer science, pseudocode is a description of the steps in an algorithm using a mix of conventions of programming languages (like assignment operator, conditional operator, loop) with informal, usually self-explanatory, notation of actio ...
demonstrates the process of z-buffering:
// First of all, initialize the depth of each pixel.
d(i, j) = infinite // Max length

// Initialize the color value for each pixel to the background color
c(i, j) = background color

// For each polygon, do the following steps :
for (each pixel in polygon's projection)


See also

*
Z-fighting Demonstration of z-fighting with multiple colors and textures over a grey background Z-fighting, also called stitching or planefighting, is a phenomenon in 3D rendering that occurs when two or more primitives have very similar distances to the ...
* Irregular z-buffer * Z-order * A-buffer *
Depth map In 3D computer graphics and computer vision, a depth map is an Digital image, image or Channel (digital image), image channel that contains information relating to the distance of the Computer representation of surfaces, surfaces of scene objec ...
*
HyperZ HyperZ is the brand for a set of processing techniques developed by ATI Technologies and later Advanced Micro Devices and implemented in their Radeon-Graphics processing unit, GPUs. HyperZ was announced in November 2000 and was still available i ...
*
Stencil buffer A stencil buffer is an extra data buffer, in addition to the ''color buffer'' and '' Z-buffer'', found on modern graphics hardware. The buffer is per pixel and works on integer values, usually with a depth of one byte per pixel. The Z-buffe ...


References


External links


Learning to Love your Z-buffer



Notes

{{DEFAULTSORT:Z-Buffering 3D rendering