LibGDX - Directional/Surface Light

1.3k views Asked by At

I'm making a 2D sidescroller game.

Using this tutorial, I made some nice flickering light.

enter image description here

Using this method, how would I make directional light that only appears on the surface? The blocks are stored in a 2D byte array.

I also tried making a 2D light[][] array and calculated the level depending on where the block was. However, making it work with other light sources (torches, for example) was very difficult. I'd really like to use shaders for this. It looks much smoother. Also, I don't need the directional light to fade off as it goes into a block, I just need the light to stop completely when it hits a solid block.

1

There are 1 answers

0
Wicpar On

If you only want to have the lighting effect on the ground, you can just apply a lightmap on the blocks (like in the tutorial) that simulates your wished light fade, if the block is connected to a transparent/ air block.

If you want some objects to cast shadows too (like trees that make the light fade in the block less bright, you can create an occlusion map of the scene, and, in the post processing, check the pixels for a possible occluder pixel on the path of the reverse of the light Vector. But that is a bit more tricky, but there is a tutorial that could help here. It is about shadow casting lights, and it gives a gorgeous result :), and should be adaptable to directional lights too :).