Interpolating 2D tile lighting

I’m a little confused about “smooth lighting” and how to implement it. I’m using LibGDX and just doing simple tile by tile lighting right now, and I want to smooth it out to look nice. When I got to thinking, however, I first thought of Minecraft’s smooth lighting system, and that made me realize something. Minecraft doesn’t use shaders, so you cannot access individual pixels (I think), so how does the lighting work? I always imagined that you start with a light value like 12, get the light value of the block next to it, then create a gradient of pixels for the light and render it on the two block. However, you would have to modify individual pixels to make this work, so I’m confused here. Unless of course I’m wrong and you can play with pixels in old OpenGL.

But now I’m wondering how to implement my own system. I need to get the average, or interpolate, the light values of my tiles. But how do I do this? Do I need to use shaders or is this something I need to code by hand? I’m using LibGDX but that shouldn’t matter. Also, in smooth lighting systems do you do a lighting pass and render tile based lighting and then do another pass and interpolate the lighting?

Can you point to an image of what you mean? From all the screens I’ve seen, Minecraft doesn’t really have “smooth lighting” – it just has per-face lighting. But maybe I’m wrong.

In any case, you can do it fairly easily with vertex colors, and let GL do the interpolation for you. Each tile has four vertices, and if you give them different values, OpenGL will interpolate each. GL does this for any vertex attributes passed to the fragment level, e.g. texture coordinates.

You can use corner colors like so:
http://www.badlogicgames.com/forum/viewtopic.php?p=42550#p42550

You can use shaders if you want more definition, like giving a “3D” look to a brick texture.


Ok, I found an example of minecraft’s lighting system and then what I kind of want my 2d light to look like.

And the 2d lighting:

As you can see, the lighting is interpolated between tiles so that it looks smooth and you can’t see the individual tile lighting. I don’t know if your first link will provide this feel, but I’ll take a look at it. I cannot actually code right now, so sorry about the lack of code. I’m currently just researching and creating psuedo code for when I have access to a computer next.

Edit: oh sorry I just re read your post and realized you gave me an answer. So OpenGL will do that automatically for me? How do I do this exactly? When I was using straight LWJGL the interpolation would happen without me actually calling a function for it to do so, so I can’t remember how to do this. If I’m correct, I believe I just gave each vertex a color using a color function (can’t remember what it was) and since its state based, it would use that color for each vertex until I changed it. Note: I was using the fixed function pipeline so I’ve never actually dealt with shaders. Is my lighting only possible using shaders?

Firstly; are you making a 3D or 2D game? Don’t use Minecraft as a reference if you are making a 2D game, as the rendering process will be much different.

If you are making 3D cubes and want them to be very smoothly shadowed, you need to use per-fragment lighting (i.e. shader-based).
The LibGDX 3D API includes lighting, or you can do it yourself with shaders like this:
http://www.arcsynthesis.org/gltut/Illumination/Tut10%20Fragment%20Lighting.html

If you are making a 2D game, then the above is irrelevant. Instead, you should be doing research on 2D dynamic shadows:

One common solution is to use blend functions. This involves rendering your scene once, and then rendering your lights on top:

Another solution involving FBOs and shaders might look like this:

Read up on these subjects here:

If you are using LibGDX it would be better to use something like Box2DLights. It already includes a lot of optimizations
(for example, using disc meshes to reduce fill-rate on mobile) and is easy to set up. It implements all the OpenGL/shaders for you.

maybe instead of using it on each tile do an overlay of light that does it say every 4 pixels? then update that and then modify the tiles color in the locations that the light was.