summaryrefslogtreecommitdiff
path: root/advanced_opengl/1.depth/shaders/depth.fs
blob: 2f3d9ca4a50a593a1e04d788f34ee6a5b99b5438 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#version 330 core

out vec4 frag_color;

in vec2 tex_coords;

uniform sampler2D our_texture;

float near = 0.1f;
float far = 100.0f;

float
linearize_depth(float depth)
{
    float ndc_z = 2.0f*depth-1.0f;
    return((2.0f*near*far)/(far+near-ndc_z*(far-near)));
}

void
main(void)
{
    /* 
    frag_color = texture(our_texture, tex_coords);
    */
    float depth = linearize_depth(gl_FragCoord.z)/far;
    frag_color = vec4(vec3(depth), 1.0f);
}