[[File:Z-buffer.jpg|thumb|L'immagine complessiva e la sua rappresentazione nello z-buffer, in cui sono memorizzate solo le distanze]]
{{WIP|Moongateclimber}}
[[Image:Z-buffer.jpg|thumb|Z-buffer data]]
Nella [[computergrafica graphics|computer graficacomputerizzata]] tridimensionale, lo '''z-buffering''' è una tecnica di gestione della coordinata corrispondente alla profondità di un oggetto a livello di singolo pixel, ovvero della massima risoluzione possibile. Solitamente viene realizzata dall'[[hardware]], ovvero dalla [[scheda grafica]], che deve essere dotata di un'apposita area di [[memoria (informatica)|memoria]] detta '''z-buffer'''; tuttavia, può avere all'occorrenza anche un'implementazione totalmente [[software]].
Lo z-buffering è una delle strategie possibili per risolvere il [[problema della visibilità]] nel [[rendering]] [[rendering tridimensionale|tridimensionale]], ovvero per stabilire quali parti degli oggetti sulla scena siano visibili e quali siano invece nascoste da altri elementi in primo piano. StabilireNonostante per tempo quali oggetti siano da visualizzare consente di otteneresia una maggioretecnica efficienzapiuttosto evitando operazioni di rendering inutili. Alcune tecnichesemplice (comee il [[tile based rendering]]lenta), cercano di anticipareè lotuttavia z-bufferingsfruttata nella [[pipelinemaggior 3D]]parte indei modomotori dagrafici ottenere3D una efficienza ancora maggiorecommerciali.
Stabilire per tempo quali oggetti siano da visualizzare (temporal coherence) può incrementare notevolmente le prestazioni in quanto ciò consente di ottenere una maggiore efficienza evitando operazioni di rendering inutili. Alcune tecniche (come il [[tile based rendering]]) cercano di anticipare lo z-buffering nella [[Pipeline grafica|pipeline 3D]] in modo da ottenere una maggiore efficienza. Altre tecniche riguardano l'occlusion culling. Sono stati proposti algoritmi che sfruttano uno z-buffer gerarchico per velocizzare le operazioni di occlusion culling.
Un'altra tecnica molto usata, per quanto meno efficiente, è l'[[algoritmo del pittore]].
== Descrizione ==
Quando un oggetto viene visualizzatorenderizzato da una [[scheda grafica 3D]], la profondità dei [[pixel]] che lo rappresentano (la "coordinata z") viene memorizzata nello z-buffer. Questo [[buffer]] è solitamente strutturato come una [[matrice]] bidimensionale, con un elemento per ogni pixel dello schermo. Se un altro oggetto deve essere visualizzato nello stesso punto, la scheda grafica confronta le profondità dei due oggetti sovrapposti; se il nuovo oggetto è più vicino all'osservatore, i valori corrispondenti per il pixel sostituiscono quelli precedenti, e la cella corrispondente dello z-buffer viene anch'essa aggiornata con la nuova profondità.
La granularità dello z-buffer influisce fortemente sulla qualità dell'immagine; uno z-buffer a [[8 bit|8]] o [[16 bit]] può creare sgradevoli [[artefatto (segnale)|artefatti]] (detti informalmente "lotta per lo z-buffer") nel caso di due oggetti molto vicini. Questi artefatti diminuiscono se si portano i bit dello z-buffer a [[24 bit|24]] o [[32 bit|but]].
Inoltre, la precisione nella memorizzazione delle distanze in uno z-buffer non è costante rispetto al valore assoluto di tali distanze. In altre parole, lo z-buffer distingue molto meglio oggetti vicini che oggetti lontani. Sebbene questa sia una scelta voluta nella progettazione delle schede grafiche (essendo in generale preferibile), in alcuni contesti può portare alla comparsa di artefatti visibili nel rendering di oggetti molto lontani (come in certi programmi di [[simulatore di volo|simulazione di volo]]). Una variante dello z-buffering che mantiene una precisione più costante rispetto alla distanza viene chiamata [[w-buffering]].
All'inizio di una nuova scena, lo z-buffer viene azzerato, generalmente assegnando il valore 1,0 a ogni cella. Poiché la profondità viene memorizzata come un valore in [[virgola mobile]] compreso fra 0 e 1, 1,0 rappresenta la profondità degli oggetti assolutamente più lontani.
L'invenzione dello z-buffer viene generalmente attribuita a [[Edwin Catmull]], sebbene [[Wolfgang Straßer]] avesse descritto un'idea simile nella sua [[tesi di dottorato]], nel [[1974]].
== Z-buffering nelle schede video moderne ==
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]].
Nelle schede grafiche più moderne, lo z-buffer usa una porzione significativa della [[larghezza di banda]] disponibile per l'accesso alla memoria. Molte tecniche sono state proposte per ridurre l'impatto dello z-buffering sull'uso delle risorse della scheda; per esempio il [[tile based rendering]] e tecniche di [[Compressione dati lossless|compressione senza perdita di informazione]].
The invention of the z-buffer concept is most often attributed to [[Edwin Catmull]], although Wolfgang Straßer also described this idea in his 1974 Ph.D. thesis<sup id="fn_1_back">[[#fn_1|1]]</sup>.
* [[Edwin Catmull]], inventore dello z-buffering
* [[Computer grafica 3D]]
* [[Scheda grafica 3D]]
* [[ fr:Z-buffer irregolare]] ▼
* [[ Irregular ZW-buffer]] ▼
== Altri progetti ==
On recent PC graphics cards (1999-2005), z-buffer management uses a significant chunk of the available [[computer storage|memory]] [[bandwidth]]. Various methods have been employed to reduce the impact of z-buffer, such as [[lossless compression]] (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).
{{interprogetto}}
== Collegamenti esterni == ▼
==Mathematics==
* [{{cita web|http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html |Impara Learningad toamare Loveil yourtuo Zz-buffer ]|lingua=en}}▼
* [{{cita web|http://www.sjbaker.org/steve/omniv/alpha_sorting.html Alpha|L'alpha-blending ande thelo Z-buffer ]|lingua=en}}▼
{{Portale|informatica}}
The range of depth values in camera [[space]] (See [[3D projection]]) to be rendered is often defined between a <math>\mathit{near}</math> and <math>\mathit{far}</math> value of <math>z</math>. After a [[perspective transform]]ation, the new value of <math>z</math>, or <math>z'</math>, is defined by:
[[Categoria: InformaticaGrafica 3D]] ▼
<math>z'=
[[Categoria:Computer grafica]]
\frac{\mathit{far}+\mathit{near}}{\mathit{far}-\mathit{near}} +
\frac{1}{z} \left(\frac{-2 \cdot \mathit{far} \cdot \mathit{near}}{\mathit{far}-\mathit{near}}\right)
</math>
Where <math>z</math> is the old value of <math>z</math> in camera space, and is sometimes called <math>w</math> or <math>w'</math>.
The resulting values of <math>z'</math> are [[normalize]]d between the values of -1 and 1, where the <math>near</math> [[plane (mathematics)|plane]] is at -1 and the <math>far</math> plane is at 1. Values outside of this range correspond to points which are not in the viewing [[frustum]], and shoudn't be rendered.
To implement a z-buffer, the values of <math>z'</math> are [[Linear interpolation|linearly interpolated]] across screen space between the [[vertex|vertices]] of the current [[polygon]], and these intermediate values are generally stored in the z-buffer in [[Fixed-point arithmetic|fixed point]] format. The values of <math>z'</math> are grouped much more densely near the <math>near</math> plane, and much more sparsely farther away, resulting in better precision closer to the camera. The closer the <math>near</math> plane is set to the camera, the less precision there is far away -- having the <math>near</math> plane set too closely is a common cause of undesirable rendering artifacts in more distant objects.
To implement a w-buffer, the old values of <math>z</math> in camera space, or <math>w</math>, are stored in the buffer, generally in [[floating point]] format. However, these values cannot be linearly interpolated across screen space from the vertices -- they usually have to be [[Inversion|inverted]], interpolated, and then inverted again. The resulting values of <math>w</math>, as opposed to <math>z'</math>, are spaced evenly between <math>near</math> and <math>far</math>.
Whether a z-buffer or w-buffer results in a better image depends on the application.
When using the <code><canvas></code> tag with [[JavaScript]], you can use the following as a Z-Buffer formula.
<pre>//F=far, N=near, Z=final return
f=0;
n=0;
z=0;
z=((f+n)/(f-n))+((1/z)*((-2*f*n)/(f-n)));
// Optimized: z=(f+n-2*f*n/z)/(f-n)</pre>
*[[Edwin Catmull]] -- inventor of the z-buffer concept.
*[[3D computer graphics]]
▲==Collegamenti esterni==
▲*[http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html Learning to Love your Z-buffer]
▲*[http://www.sjbaker.org/steve/omniv/alpha_sorting.html Alpha-blending and the Z-buffer]
==Notes==
<cite id="1">[[#fn_1_back|Note 1:]]</cite> see W.K. Giloi, J.L. Encarnação, W. Straßer. "The Giloi’s School of Computer Graphics". Computer Graphics 35 4:12–16.
▲[[Categoria:Informatica]]
[[de:Z-Buffer]]
[[en:Z-Buffer]]
[[es:Z-Buffer]]
[[nl:Dieptebuffer]]
[[ja:Zバッファ]]
[[pl:Bufor Z]]
[[fi:Z-puskurointi]]
[[sv:Z-Buffer]]
|