I am utilizing this to render utilizing a reversed Z buffer:
This appears to be like superb and fully fixes all my z-fighting, nevertheless it breaks what I take advantage of in shader to derive the world place from the depth for numerous functions equivalent to deferred lighting and fog (it has labored for an everyday projection matrix):
vec4 screenSpacePosition = vec4(texcoord * 2.0 - 1.0, depth * 2.0 - 1.0, 1); vec4 worldSpacePosition = invProjView * screenSpacePosition; vec3 finalPosition = worldSpacePosition.xyz / worldSpacePosition.w; return finalPosition;
I’ve thought that this was resulting from this utilizing a single view projection matrix, so I’ve additionally tried this:
vec4 clipSpacePosition = vec4(texcoord * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); vec4 viewSpacePosition = invProj * clipSpacePosition; viewSpacePosition /= viewSpacePosition.w; vec4 worldSpacePosition = invView * viewSpacePosition; return worldSpacePosition.xyz;
That have to be suboptimal efficiency smart, nevertheless it does not work both anyway. Any concept what I am lacking?