I'm working on implementing some semi-basic lighting in a fragment shader for a 2D renderer.
At the moment, the light attenuation is calculated using: I / (d/r + 1)2
where I = intensity, d = distance between light source and gl_FragCoord, r = radius of light
The final attenuation for any given fragment is the sum of attenuation values from all other sources.
Here is an example scene - two quads and a background (no textures)
No lighting:
With lighting:
This is with very minimal ambient lighting.
Right now the color of the fragment is computed with: rgb * light_color * attenuation
How do I mix the frag color with light color AND ambient color so that ambient color is applied consistently throughout the frame while the light color only has an effect within the lights' attenuation range?
What other factors should I be putting in for a solid 2D light system (i.e. material/diffuse/etc.)?