A better point light attenuation function
added on 2022/08/04 @ 14:17:29 | 120 views| category: gamedev

Alternative point light attenuation with GLSL implementation:

float sqr(float x)
{ return x * x; }

float attenuate_no_cusp(float distance, float radius, float max_intensity, float falloff)
{
float s = distance / radius;
if (s >= 1.0) return 0.0;
float s2 = sqr(s);
return max_intensity * sqr(1 - s2) / (1 + falloff * s2);
}

float attenuate_cusp(float distance, float radius, float max_intensity, float falloff)
{
float s = distance / radius;
if (s >= 1.0) return 0.0;
float s2 = sqr(s);
return max_intensity * sqr(1 - s2) / (1 + falloff * s);
}

tags: #gamedev #programming #opengl #vulkan