You may remember me from my post on brightening a texture. My friend and I have come a long way with our engine since then and are working on dynamic lights and shadows.
We started out with the example given here:
which goes into dynamic soft shadows via creating an alpha texture, rendering a black “ambient darkness” sheet with alpha 1.0f over the scene, and then using the alpha map of your lights to “reveal” through the darkness. Downsides to this system were the lack of our ability to do any kind of bloom effect without shader language, which led us to…
Finally implementing GLSL and GL2.0 compatibility, we explored the possibility of using shader programs for our lights. Currently we have the following simple fragment shader that draws a basic circular light:
varying vec2 pos;
uniform vec4 color;
void main()
{
float t = 1.0 - sqrt(pos.x*pos.x + pos.y*pos.y);
//Enable this line if you want sigmoid function on the light interpolation
//t = 1.0 / (1.0 + exp(-(t*12.0 - 6.0)));
gl_FragColor = vec4(color.r, color.g, color.b, color.a) * t;
}
Which is an example from the youtube video. Using this, we draw the lights to the screen as before, create the alpha map, and then blend this alpha map into our finished scene at the very end.
Again we run into the problem of being unable to add any sort of bloom effect (we assume that this is another type of fragment shader that we would have to pass our lights through), and the idea of how to achieve even “hard” shadows is somewhat of a mystery (save for finding the dot product of the light vector and the normal of the shadow casting surface).
The context of our project: We are developing a 2D indie title that we hope will be as backwards-compatible as possible (I think GL2 is pretty safe). However, having good looking shadows gives a game a great “pop” factor. We are complete strangers to VBOs and FBOs, having used the fixed function pipeline until now. However, we understand the basic purposes of these objects; we’re just lost on implementation and how they might help us arrive at a lighting solution without breaking the rest of our working code.
A picture of our current light… uses a shader program, but uses GL_QUADS to actually draw it… kind of a bastardization of GL2, but we’re working on it:
Hopefully you guys see that we have put a decent amount of effort into figuring this out, and aren’t just begging for help. That said, you’re the experts, so any advice would be most appreciated. In return, we can offer a gift… these two droids. Uh, I mean, the two shaders, once we get them working, so that hopefully others can benefit from our combined efforts. If you need any more code from our project in order to help, just ask and I’ll try to dig up something resembling a program.
Thanks in advance!