I know this has been asked a lot of time before but none of those answers fixed my problem. I try to implement deferred shading and to do so I need to reconstruct the world space position from the depth. (Having a position texture in the gbuffer would be a waste of data)
The calculation works fine for rotationing the camera (-> moving the mouse) but as soon as I move the camera (-> pressing wasd) they get weird.
vec4 screenSpacePosition = vec4(pass_Texture * 2.0 - 1.0, texture(gbuffer_texture, pass_Texture).r, 1); vec4 worldSpacePosition = invertedViewProjection * screenSpacePosition; vec3 finalPosition = worldSpacePosition.xyz / worldSpacePosition.w;
gbuffer_texture is the depth attachment of OpenGL. invertedViewProjection is the matrix I used to render the scene inverted on the CPU.