Terraria / Starbound Style Lighting

So I am currently developing a 2D sandbox game similar to Terraria and Starbound. I would like to set up the lighting for the game at this point similar to that of the games mentioned above. I have never done lighting before so I am curious if there are any guides or methods or anything out there that anybody might suggest.

Here is what we have right now:

alt text

Lighting used is just a simple directional light. We are looking for something more like this:

alt text

As you can see in the second screen shot (Starbound), the light does not penetrate all the way through the terrain. Almost like a fog of war type of effect going on there, except instead of showing previously explored areas it only shows illuminated areas. I am curious how this effect might be achieved, any and all help is appreciated!

P.S. - We are currently using a mesh based system for loading chunks of blocks near the player. Block data is saved to map file in the form of an array of ushorts (for blockID) that makes up the front and back blocks.

I guess if you’re building the mesh yourself then you could probably do this by changing the vertex colours. Shared vertex colours between your cells would give you the gradients around the edges.

I assume that the level tiles are structures in a 2-dimensional array, and that each array position, i.e. each tile, has information about wehter it’s filled (doesn’t emit light) or not filled (emits light).

You would then go through each tile in the array, and if it’s not filled, you then go through all the tiles around it in a certain tile radius. For each of those, you check if they are filled, and if yes, then determine the light amount of that tile by checking the distance between it and the original tile.

The “light”, of course, might just be the alpha value of a material’s color, which covers the whole scene.

For the rounded shadow shapes, you could alternatively go over each tile, and if it’s not filled, use SetPixels() to clear the pixel of the shadow texture overlaying the scene in a radius.

Simply make a new 2D material with the sprites>diffuse shader and apply that to your terrain. In the lighting panel set the ambient color to a solid black and finally add lights whereever needed in the world making sure the lights are layered above the terrain they are illuminating.