Hello, i am creating a 2D Terraria tile based game and i am wondering the best way to creating the lighting similar to what is used in Terraria. Each of my blocks are stored in a 16x512 array per chunk and a mesh is created to form edges to the blocks. I have tried to colour each vertex in the area to be lit to create a mock lighting system however to find the correct vertices in the mesh takes a long time and impacts performance when working with dynamic lights.
I would like to know whether this is possible by creating a shader and if there are any good places to look on how to achieve this or an easier way to use vertex colours.
It might be best to take a very simple approach that will be very performance friendly. Here is my initial idea.
Every lightsource has a “radius” and depending on this radius a certain number of rays will be generated (the larger the radius the more rays will be needed. These rays will fire out of the center of the light source forming a circle. You can then calculate all of the collisions these rays have with your blocks (possibly up to a maximum). You can then change those blocks’ brightness based upon their distance from the lightsource. Anything not touched by a light would just have an ambient brightness of whatever you choose. Thoughts?