Original Post
Hi,
I was wondering how to make "light" in a 2D game ?
It doesn't need to be dynamic and cast shadows, which I know is a different topic. Static light would be enough.
Something like this:
[media]
Or static lights here (the ones on the celing):
[media]
Here is my method that is pretty basic and it doesn't quite work, I get some bugs when there are more "lights".
I made this up myself so I don't know is this even a good start.
I am using DirectX 9 (D3DXSprite for drawing textures) and pixel shaders (v.2).
1. I render the scene on the texture.
2. To make "light" I take a part of the texture where I want to apply light and I use my light shader on it, and then I draw it on the same place from where I took it.
3. I render the scene/texture to backbuffer.
These are the results. You can see multiple "lights".
As you can see I just increase the brightness of the pixels on some area:
- you can see that bug above the character where multiple lights overlap,
- the parts that are already bright are just brighter, and dark areas are not bright enough.
I was wondering how to make "light" in a 2D game ?
It doesn't need to be dynamic and cast shadows, which I know is a different topic. Static light would be enough.
Something like this:
[media]
[/media]
Or static lights here (the ones on the celing):
[media]
[/media]
Here is my method that is pretty basic and it doesn't quite work, I get some bugs when there are more "lights".
I made this up myself so I don't know is this even a good start.
I am using DirectX 9 (D3DXSprite for drawing textures) and pixel shaders (v.2).
1. I render the scene on the texture.
2. To make "light" I take a part of the texture where I want to apply light and I use my light shader on it, and then I draw it on the same place from where I took it.
3. I render the scene/texture to backbuffer.
float4 ps_light( float2 Tex : TEXCOORD0 ) : COLOR0
{
float4 Color;
//circular light
float d = sqrt((Tex.x*SCREENW-pos_x*SCREENW)*(Tex.x*SCREENW-pos_x*SCREENW)+(Tex.y*SCREENH-pos_y*SCREENH)*(Tex.y*SCREENH-pos_y*SCREENH));
if (d<size) Color = tex2D( g_samSrcColor, Tex.xy)*(1+(size-d)/size);
else
{
Color = tex2D( g_samSrcColor, Tex.xy);
}
return Color;
}
These are the results. You can see multiple "lights".
As you can see I just increase the brightness of the pixels on some area:
- you can see that bug above the character where multiple lights overlap,
- the parts that are already bright are just brighter, and dark areas are not bright enough.