This repository has been archived on 2019-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
dungeon-gunner/res/shaders/light_attenuation_shader.frag

26 lines
624 B
GLSL
Raw Normal View History

2013-09-12 16:13:03 +00:00
uniform vec2 lightPos;
uniform vec3 lightColor;
uniform float radius;
uniform float bleed;
uniform float linearizeFactor;
void main()
{
float dist = length(lightPos - gl_FragCoord.xy);
float distFromFalloff = radius - dist;
// Still has absolute falloff point
float attenuation = distFromFalloff * (bleed / pow(dist, 2.0) + linearizeFactor / radius);
// Optional, clamp it to prevent overcoloring
attenuation = clamp(attenuation, 0.0, 1.0);
vec4 color = vec4(attenuation, attenuation, attenuation, 1.0) * vec4(lightColor.r, lightColor.g, lightColor.b, 1.0);
gl_FragColor = color;
}