Been working on this game for around two weeks on and off when I have time, doing the procedural landscape generation which is using
a mix of perlin noise and cellular automata.
Tile lighting? I’ve covered this practically the same amount of times I have with basic cave systems, so I will dump an older post here and go over it more in depth.
Each block has a byte of data (I only use half a byte b/c I don’t use the negative part). That byte corresponds to the “brightness” of each block. There is also a float for each block but that’s for colour, which I won’t go over.
Lighting is calculated with light sources and a recursion method at each source. The recursiveness of the lighting gives it that diamond shape.
My code is here.
This does use one shader, and it’s to mask the lighting buffer onto the world without covering up the background. The smoothness is merely a gradient quad.
This is what the lighting looks like without gradients:
This is what the lighting looks like without masking:
As you can see the moon and the stars have the “shadow” effect as a result.
This just sets my whole screen lighter or darker dependant on the ambient colour that is passed in.
How could I apply the lighting to just parts of the screen? Would I need to use a fbo?
I drew gradients over the blocks with their corresponding light levels. The corners of the gradients were the surrounding 3 adjacent blocks (counting diagonal) averaged with the block itself.
If you want simple blocky lighting, all you have to do is draw a 1x1 texture (either generated at runtime or read from file) and stretch it over your blocks. I myself haven’t worked too much with shaders, but if you need a good resource, mattdesl has an awesome starting guide here.