#version 330
in vec2 outTexCoord;
uniform sampler2DArray depthTexture;
uniform mat4 prevFrameInvertedProjViewMatrix;
uniform mat4 currFrameProjViewMatrix;
void main() {
float depth = texture(depthTexture, vec3(outTexCoord, 0)).r;
vec2 cspos = vec2(outTexCoord.x * 2 - 1, (1-outTexCoord.y) * 2 - 1);
vec4 depthCoord = vec4(cspos, depth, 1.0);
depthCoord = prevFrameInvertedProjViewMatrix * depthCoord;
vec4 position = vec4(depthCoord.xyz / depthCoord.w, 1.0);
vec4 projPosition = currFrameProjViewMatrix * position;
gl_FragDepth = projPosition.z / projPosition.w;
}