So I have a pretty simple GLSL shader for point lights. I simply iterate through my lights and draw them to the scene with the following fragment shader:
#version 330
in vec4 v_color;
in vec2 v_texCoord;
uniform sampler2D u_texture;
uniform sampler2D u_normal;
uniform float lightRadius; // Radius of light (screen coords)
uniform vec2 lightCoord; // Position of point light (screen coords)
uniform vec4 lightColor; // Color of light, a is intensity
uniform float lightZ; // Z-index of light (0-1)
layout(location = 0) out vec4 lightBuffer;
void main()
{
// RGBA of diffuse color.
vec4 diffuseRGBA = texture2D(u_texture, v_texCoord);
// RGB of normal map, invert g in normal map for accuracy.
vec3 normalRGB = texture2D(u_normal, v_texCoord).rgb;
normalRGB.g = 1.0 - normalRGB.g;
// The delta position of the light.
vec2 lightDir = vec2(lightCoord - gl_FragCoord.xy);
// Distance to light.
float distance = length(lightDir);
// Attenuation.
float attenuation = clamp(1.0 - ((distance * distance) / (lightRadius * lightRadius)), 0.0, 1.0);
// Normalize vectors.
vec3 N = normalize(normalRGB * 2.0 - 1.0);
vec3 L = vec3(normalize(lightDir), lightZ);
// Pre-multiply light color with intensity then perform "N dot L" to determine diffuse term.
vec3 diffuse = (lightColor.rgb * lightColor.a) * max(dot(N, L), 0.0);
// The calculation which brings it all together.
vec3 intensity = diffuse * attenuation;
vec3 finalColor = diffuseRGBA.rgb * intensity;
// Done.
lightBuffer = v_color * vec4(finalColor, diffuseRGBA.a);
}
Here's the output:
(I upped the intensity a bunch to make it clearer.)
Can someone smarter than me help me out and tell me what could be the reason for the "dead area" in the top-right area of each light? I've been scratching my head about it for a while now.
Thanks.