2018-02-15 09:59:38 +01:00
|
|
|
#version 330 core
|
|
|
|
|
2018-02-16 11:35:09 +01:00
|
|
|
in vec2 ioUV;
|
2018-02-15 09:59:38 +01:00
|
|
|
|
2018-02-16 11:35:09 +01:00
|
|
|
out vec3 outColor;
|
2018-02-15 09:59:38 +01:00
|
|
|
|
2018-03-11 22:05:42 +01:00
|
|
|
uniform sampler2D uDepthTexture;
|
|
|
|
uniform float uIsOrthographic;
|
2018-02-16 11:35:09 +01:00
|
|
|
uniform float uNear;
|
|
|
|
uniform float uFar;
|
2018-02-15 09:59:38 +01:00
|
|
|
|
|
|
|
void main() {
|
2018-03-11 22:05:42 +01:00
|
|
|
float z = texture(uDepthTexture, ioUV).r;
|
|
|
|
float c;
|
|
|
|
if (uIsOrthographic == 1.0) {
|
|
|
|
c = (z - uNear) / (uFar - uNear);
|
|
|
|
} else {
|
|
|
|
c = (2.0 * uNear) / (uFar + uNear - z * (uFar - uNear));
|
|
|
|
}
|
2018-02-16 11:35:09 +01:00
|
|
|
|
|
|
|
outColor = vec3(c);
|
2018-02-15 09:59:38 +01:00
|
|
|
}
|