Starbound / Terraria 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:

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

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 a multi-dimensional array of ushorts (for blockID) that makes up the walls and fronts.

Currently I have had some degree of success with

  1. Using a flood fill algorithm similar to the one in the last post here:

http://www.java-gaming.org/index.php?topic=26363.0

  1. Using draw SetpPixels32 to create a trilinear texture map and layering it over.

However, I have had significantly difficulty in finding a way to only layer this shadow over the foreground elements and not the sky/background elements with any efficiency. You can check out my currently slow pixel shader discard method here:

Iā€™m still going to work on another method when I get the time, but if someone knows a more efficient method, Iā€™d appreciate this, myself.