Hi, so I’ve been stalking these forums for the last couple of months now, and it seems like a real great community, I’ve tried asking the question on gamedev.stackexchange (here : http://gamedev.stackexchange.com/questions/104785/2d-smooth-lighting-with-shadows-for-a-tile-based-game) but to no avail.
So, here we go -
I’ve been trying to implement efficient lighting in my starbound/terraria-like game. I’m creating it in LibGDX, and I am aware of Box2D, but I am more doing this for the learning experience, so reinventing the wheel here is useful. I’ve been doing tons of research and experimenting, I’ve seen many posts on here and other places, and I just cannot figure it out. What I’m going for isn’t Terraria’s tiled-based lighting, but like Starbound (http://playstarbound.com/wp-content/uploads/2012/04/Dungeon.jpg).
I do have something that works for the most part :
This is done by shooting a ray to each tile in the area around the light, and if it doesn’t hit any other block, it puts a vertex there. Afterwards, I sort all the vertices and assign them color values of black and create a middle pixel that has a color value of black but with 0 alpha. I learned that shaders automatically create the gradient between the vertices, so this works pretty well. The problem I’ve now encountered is actually darkening everything else. As you can see in the picture, it doesn’t black out the tiles near the edges of the light since they are squares.
My idea right now is to render a black mesh over the screen with an alpha value of one, and I’m wondering if it’s possible, using blendFuncs and blendEquations, to subtract the alpha of the black mesh from the mesh of the light (if that makes any sense) - So the darkness is rendered, then the light afterwards, and I don’t know if there’s a way to just remove some of the alpha from some of the pixels that are overlapping using blend funcs.
P.S. Please excuse my complete lack of knowledge about OpenGL and LibGDX in general, I’m trying to learn it and most of the stuff I’m saying could make absolutely no sense to experts and I may come back in a couple of years and laugh at how naive I was.