A year ago I implemented 2d lighting in XNA using sprites. The sprites I used were created by placing a soft white photoshop brush on a transparant background.
The result was this: (lights only)
And this seemed right to me.
I returned to the subject this week to try replacing the sprites with a texture created with code and a formula:
As you can see, there is a black ring around every light.
This is the code I used for creating the textures:
int diameter = 250;
int radius = diameter / 2;
Color[] colors = new Color[diameter * diameter];
for (int y = 0; y < diameter; y++)
{
for (int x = 0; x < diameter; x++)
{
Vector2 l = new Vector2(radius, radius) - new Vector2(x, y);
float attenuation = MathHelper.Clamp(1 - Vector2.Dot(l / radius, l / radius), 0, 1);
colors[x + y * diameter] = Color.White;
colors[x + y * diameter].A = (byte)(attenuation * 255);
}
}
Texture2D texture = new Texture2D(device, diameter, diameter);
texture.SetData(colors);
I got the attenuation formula from here.
Aside from that I now create the textures using code, the rest of the code has remained the same.
Where do the black rings come from, and how do I prevent them from appearing?