I'm trying to do terraria-like lighting, except not on a per-tile basis. e.g. http://cloud.steampowered.com/ugc/648743187051563480/80FE8DD1840E25A4FD5BF1EA529EC30CD7E0C329/
I'm using OpenGL, but nothing specific to it, the concept is generic.
Basically I want my entire scene to be black/dark unless there are light sources, like a torch. In which case there would be a radius where the light bleeds off. Currently I render my game scene (tile map, then entities). Then I render the light points (torches) into an FBO (offscreen texture), and then I render that to the backbuffer using multiplicative blending.
Here's an example of what I'm doing..and trying to get to work http://i.imgur.com/CJvTkej.png
Light sources can be changed at runtime by the player, and there has to be support for a lot of them, which is why I am using this deferred approach to rendering them.
The lights are each rendered as a quad using the frag shader below, then the entire FBO is rendered as a fullscreen quad to the backbuffer using a simple passthrough shader.
Fragment shader code, to calculate lights. But the code itself is pretty screwed up because from the screenshot above, you can see that the ball of light is all concentrated in one area, more like a Sun than a Torch. So my lighting shader needs to be fixed, then I need someway to make non lit areas dark.
void main() {
float distance = 8 * distance(frag_texcoord.xy, vec2(0.5, 0.5));
fragColor = vec4(frag_color.rgb * (1/distance), frag_color.a * (2/ distance));
}
Anyways, not only do I need the areas that aren't in range of a light source to be darkened, but I also need to think of a way to handle the sky. I mean, some approach might be fine while i'm underground, but if I'm above ground where half the screen is sky and the bottom half is ground (and it's not symmetrical either, but can be jagged, however the user places blocks)...I wouldn't know how to make the sky *not* black.
Any thoughts, suggestions or somewhere to point me to? Because I'm super new to this lighting stuff (well, graphics programming altogether), and I've been trying to solve my lighting for a long time now, trying different approaches.
Thanks.