<p>I've very less knowledge when it comes to rasterization and typical rendering in games and other applications. So I was reading up on the rendering pipeline and found that the hardware could do early depth testing if you don't write to depth in fragment shader and this struck as odd to me. I'm having a hard time imagining cases where you'd wanna write to depth inside a fragment shader. In a normal rendering environment, the depth value gets calculated properly through all the transformations so why would you wanna mess with that? If anybody can explain briefly 2 or 3 examples it'd be great. Thanks.</p>

CC BY-SA 4.0
2021-09-06T15:05:21.653Z
The most common use of writing to a depth buffer in the fragment shader is for shadow map generation some algorithms require the use of the fragment shader. Others can get away with just a vertex shader for shadow maps.
pmw1234
CC BY-SA 4.0
2021-09-08T07:06:38.550Z
ok. waiting for further examples.
gallickgunner
CC BY-SA 4.0
2021-09-10T10:09:39.663Z
Proxy geometry may want to write the zbuffer. Other more exotic objects like raymarched or raytraced objects that are mixed into your pipeline could also need their own zbuffer writes.
PaulHK
<rendering><fragment-shader><z-buffer>
Examples of cases where you write depth value in Fragment Shader?
gallickgunner
# Examples of cases where you write depth value in Fragment Shader?

(Asked by: username_0 on 2021-09-06)

I've very less knowledge when it comes to rasterization and typical rendering in games and other applications. So I was reading up on the rendering pipeline and found that the hardware could do early depth testing if you don't write to depth in fragment shader and this struck as odd to me. I'm having a hard time imagining cases where you'd wanna write to depth inside a fragment shader. In a normal rendering environment, the depth value gets calculated properly through all the transformations so why would you wanna mess with that? If anybody can explain briefly 2 or 3 examples it'd be great. Thanks.

**Tags:** rendering, fragment-shader, z-buffer

> **Comments:**
> **username_1**: The most common use of writing to a depth buffer in the fragment shader is for shadow map generation some algorithms require the use of the fragment shader. Others can get away with just a vertex shader for shadow maps.  
> **username_0**: ok. waiting for further examples.  
> **username_2**: Proxy geometry may want to write the zbuffer. Other more exotic objects like raymarched or raytraced objects that are mixed into your pipeline could also need their own zbuffer writes.  

---

## 0 answers

