![[../../00 Asset Bank/Pasted image 20250314093055.png]]
The depth buffer is a [[Buffer (GPU)]] in which every [[Pixel]] corresponds to the depth ([[../Math/Distance|Distance]] from the [[Camera Modeling Transform|Camera]]) of the [[Fragment Shader|Fragment]] rendered.
The [[Depth Buffer]] is a way of implementing obscured surface removal on the pixel level.
The [[Depth Buffer]] for a given [[Frame Buffer Model|Frame Buffer]] has the same width and height, the [[Frame Buffer Model|Framebuffer]] stores the [[Color]] of each pixel and the [[Depth Buffer]] stores the depth of each pixel.
When rendering a fragment with depth $d_{1}$ over a pixel with a depth value $d_1$, the fragment will only write to that pixel if $d_{1} < d_{0}$.
>[!note] [[OpenGL]] Convention
>$z < z_0$ is following the [[OpenGL]] convention that the [[Near Clipping Plane]] is at $z=0$ and the [[../Math/Far Clipping Plane|Far Clipping Plane]] is at $z=1$
- Candidate [[Pixel]] $(i,j)$ with depth value of $z$
- Look up $z$ value in $z$ buffer at $(i,j), z_0$
- If $z < z_0$, write pixel at $z-buffer$, else dicard [[Fragment]].
>[!note] If the [[Fragment]]'s depth is farther than the [[../Math/Far Clipping Plane|Far Clipping Plane]] or closer than the [[Near Clipping Plane]] ($z$ must be $0\le z\leq1$), the [[Fragment]] is discarded.