<p>Broadly speaking, the way to deal with this is to check the depth value for that position on the screen. If the value is the value you cleared the depth buffer to, then you didn't write anything to that fragment.</p>

CC BY-SA 4.0
2021-07-13T16:13:49.753Z
2021-07-13T16:13:49.753Z
Nicol Bolas
<p>In deferred rendering, I first write world position to G-Buffer, and then in shading part, I want to use that information to reproject in the previous frame and then write the final color.</p>
<p>However, the world position buffer wont have any values for fragments that are not touching geometry. How can I recognize these fragments without valid world position info in deferred lighting shader? E.g. I should be displaying environment instead of black parts in world pos buffer.</p>

CC BY-SA 4.0
2021-07-13T16:13:07.800Z
You don't have to write position values. You can [reconstruct camera-space positions from the depth alone (along with the projection matrix)](https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space#Optimized_method_from_XYZ_of_gl_FragCoord).
Nicol Bolas
<shader><fragment-shader><buffers><deferred-rendering>
Is fragment shader run on fragments that are outside of rasterized geometry?
Toothery
# Is fragment shader run on fragments that are outside of rasterized geometry?

(Asked by: username_0 on 2021-07-13)

In deferred rendering, I first write world position to G-Buffer, and then in shading part, I want to use that information to reproject in the previous frame and then write the final color.

However, the world position buffer wont have any values for fragments that are not touching geometry. How can I recognize these fragments without valid world position info in deferred lighting shader? E.g. I should be displaying environment instead of black parts in world pos buffer.

**Tags:** shader, fragment-shader, buffers, deferred-rendering

> **Comments:**
> **username_1**: You don't have to write position values. You can [reconstruct camera-space positions from the depth alone (along with the projection matrix)](https://www.khronos.org/opengl/wiki/Compute_eye_space_from_window_space#Optimized_method_from_XYZ_of_gl_FragCoord).  

---

## 1 answers

### Answer by username_1 on 2021-07-13. Score: 1

Broadly speaking, the way to deal with this is to check the depth value for that position on the screen. If the value is the value you cleared the depth buffer to, then you didn't write anything to that fragment.


---

