2016-05-18 13:04:27 +03:00
|
|
|
#version 330
|
|
|
|
|
|
|
|
// Input vertex attributes (from vertex shader)
|
|
|
|
in vec2 fragTexCoord;
|
|
|
|
in vec4 fragColor;
|
|
|
|
|
|
|
|
// Input uniform values
|
|
|
|
uniform sampler2D texture0; // Depth texture
|
2016-07-19 11:57:35 +03:00
|
|
|
uniform vec4 colDiffuse;
|
2016-05-18 13:04:27 +03:00
|
|
|
|
|
|
|
// Output fragment color
|
|
|
|
out vec4 finalColor;
|
|
|
|
|
|
|
|
// NOTE: Add here your custom variables
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
float zNear = 0.01; // camera z near
|
|
|
|
float zFar = 10.0; // camera z far
|
|
|
|
float z = texture(texture0, fragTexCoord).x;
|
|
|
|
|
|
|
|
// Linearize depth value
|
|
|
|
float depth = (2.0*zNear)/(zFar + zNear - z*(zFar - zNear));
|
|
|
|
|
|
|
|
// Calculate final fragment color
|
|
|
|
finalColor = vec4(depth, depth, depth, 1.0f);
|
|
|
|
}
|