aboutsummaryrefslogtreecommitdiff
path: root/res/shaders/line.fs
blob: 04cba8694d3ad6f6148e5407b509f9f6abc08a5f (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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#version 420 core

uniform vec4 _u_colour;

layout(std140, binding = 0) uniform _u_globals {
    mat4 proj;
    mat4 view;
    vec4 frustum[6];
    float znear;
    float zfar;
    float xfov;
    float yfov;
    int time;
    float xwindow;
    float ywindow;
};
layout(binding = 2) uniform sampler2D main_colour;
layout(binding = 3) uniform sampler2D main_depth;

out vec4 _o_colour;

vec4 texture_sample(const sampler2D sampler, const vec2 coord) {
    return texture(sampler, coord);
}

float depth_sample(const sampler2D sampler, const vec2 coord) {
    return texture(sampler, coord).r;
}

void main() {
    const vec2 coords = vec2(gl_FragCoord.x / xwindow, gl_FragCoord.y / ywindow);

    const float cur_depth = depth_sample(main_depth, coords);
    gl_FragDepth = gl_FragCoord.z * 0.9999f;
    if (gl_FragDepth > cur_depth) {
        discard;
    }

    _o_colour = vec4(0.0f, 0.0f, 0.0f, 1.0f);

    // This is for dynamically choosing a higher contrast colour, but it's not
    // that nice of an effect so it's commented out.
    /*
    const vec2 coords = vec2(gl_FragCoord.x / xwindow, gl_FragCoord.y / ywindow);
    const float cur_depth = depth_sample(main_depth, coords);
    gl_FragDepth = gl_FragCoord.z * 0.9999f;
    if (gl_FragDepth > cur_depth) {
        discard;
    }

    const vec4 cur_tex = texture_sample(main_colour, coords);
    const float clr = (1.0f - (cur_tex.r + cur_tex.g + cur_tex.b) / 3.0f) > 0.5f ? 1.0f : 0.0f;
    _o_colour = vec4(clr, clr, clr, 1.0f);
    */
}