Z-buffering

The Z -buffering (also Depth Buffering, z-buffer or depth buffer method) is a method of computer graphics to conceal calculation to determine that is to say, the visible from the viewer's three-dimensional surfaces in computer graphics. By depth information in a so-called Z- Buffer ( "Z- buffer"), the method provides pixel-wise identify the elements of a scene to be drawn and which are hidden. Virtually all of today's graphics cards implement Z -buffering in hardware. As the developer of the Z- buffer method applies Edwin Catmull; However, Wolfgang Strasser described the principle about the same time in a different context. The main alternative to the z -buffering is the ray tracing algorithm.

Operation

The principle of the Z -buffering is very simple. In addition to the visible part of the picture memory, which contains the actual color values ​​, there is a further memory, the Z-buffer which contains the depth of the visible object at each pixel. Alternatively, the pixel values ​​can be expanded to a value in the frame buffer. At the beginning of the entries are set in the Z-buffer to a value that represents an infinite distance (Backplane Distance). The frame buffer is initialized with the background color. Each polygon will be rasterized. Only when the current point of the halftoned polygon is not further away from the viewer than the point whose distance is recorded in the Z-buffer, the values ​​in the z-buffer and the frame buffer by the distance, or the color of the current polygon to be replaced.

The order in which the polygons to be rasterized, is arbitrary in principle. Not only polygons, but any other graphical primitives can be rendered using the Z- buffer.

The memory size of the values ​​in the Z-buffer has a major impact on the quality of the rendered image. If two objects are very close together, can easily arise artifacts in a Z-buffer with 8 bits per pixel. 16, 24 or 32-bit Z-buffer depth produce fewer artifacts.

On current graphics cards the Z- Buffer absorbs a significant portion of the available memory and the data transfer rate. With different methods it is attempted to reduce the influence of the Z- buffer on the performance of the graphics card. This is, for example, lossless compression of the data is possible because the compression and decompression of the data is more cost effective than to increase the data transmission rate of a map. Another method saves deletions in the Z-buffer: the depth information is written with alternating sign in the z-buffer. An image is saved with a positive sign, the next image with negative, only then must be deleted. A further possibility for optimization is the sorting of the primitives: first Will the nearer primitives rendered, can later be decided directly from the more distant, whether or which pixels need to be rendered and which are obscured by foreground objects, which texturing and pixel shaders operations can be saved.

Algorithm

Pseudocode initialization:

ZBuffer by ∞            Framebuffer using background color start:

For each pixel (x, y)                Determine color c and z - coordinate z                IF z < ZBuffer (x, y)                     ZBuffer (x, y) = z                     Frame Buffer (x, y ) = c                FI Coding of the depth information

The range of the depth information in the camera space rendering is often defined by the near value and far value of. According to a perspective transformation, the new value of is, as referred to herein is calculated as follows:

It is the new value of the camera space. Sometimes the abbreviations and used.

The resulting values ​​are normalized to a value of between -1 and 1, wherein the area close to the value -1 and the area obtained when the far value of 1 at. Values ​​outside this range are from points that are not in the viewing area, and should not be rendered.

When implementing a Z- buffer, the values ​​of the vertices of a polygon are linearly interpolated and the values ​​including the intermediate values ​​in the Z-buffer stored. The values ​​of are much more closely distributed to the near- surface and scattered much more remote area out, resulting in a higher accuracy of the representation close to the camera position. The closer the near- surface is set to the camera, the less the precision in the distance zone. A common cause of unwanted artifacts in distant objects is that the near - surface was too narrow at the camera. This as Z-fighting (Z- fighting) designated artifacts occur especially when two coplanar faces are very close to each other, for example a wall mounted thereon and a poster. Which is of two polygons in the foreground then, is essentially random and can also be changed by small changes in the camera location. To remedy must be taken explicitly measures by the programmer, for example by the Z values ​​of the poster be changed artificially or by the use of a so-called Stencilbuffers.

Since the distance values ​​are not uniformly deposited in the Z-buffer, close objects are better represented as distant, because their values ​​are stored in more detail. Generally, this effect is desirable, but it can also lead to obvious artifacts when objects move apart. A variation of the Z- Bufferings with balanced distance values ​​is the so-called W -buffering. To implement a W buffer, the unchanged values ​​of the buffer or be stored as floating point numbers, in general. These values ​​can not be linearly interpolated, but must be inverted, interpolated and inverted again. The resulting values ​​are, as opposed to evenly distributed between near and far. Whether a Z-buffer or a W- buffer leads to better images depends on the particular application.

Pros and Cons

  • Benefits ease of implementation ( both in software and in hardware )
  • No presorting necessary input
  • Very fast
  • Simple parallelization possible (eg subdivision into smaller quadrants)
  • No random access to the scene needed
  • Each polygon of the input is rendered
  • The running time increases linearly with the input size
  • There are no relationships between the objects used
229098
de