summaryrefslogtreecommitdiffhomepage
path: root/shaders/lightmap.frag
blob: 61bf10ff8fc3e357311539e64944bbd3bb099a17 (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
precision mediump float;

layout (location = 0) uniform vec4 color_intensity;
layout (location = 1) uniform vec2 center;
layout (location = 2) uniform uint falloff;
layout (location = 3) uniform vec2 size;

out vec4 color;

void main() {
    vec2 pos = gl_FragCoord.xy;
    float L = color_intensity.w;
    float dist = distance(pos, center);
    //float dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
    float A = 1;
    //attenuation = ((light_dist - dist)**exponent) / (light_dist**exponent)
    if (falloff == 0) // linear
        A = max(0, (L - dist) / L);
    else if (falloff == 2) // quadratic
    {
        float tmp = max(0, L - dist);
        A = max(0, tmp*tmp / (L*L));
    }
    //I = sqrt(color_intensity.w*1.5)*16;
    //dist = sqrt(tmp.x*tmp.x + tmp.y*tmp.y);
    //float alpha = 1 - min(1, dist / I);
    color = vec4(color_intensity.xyz, A);
}