Light blocks up

Hi,

How would you light blocks up around a player - like fog of war - would you need a shader to do this and how would you cycle night and day, so game goes darker (I guess this is just a simple global shader)? Or is there another way to do this such as getting player position and changing the tint on the blocks around them? Screen shot of my game so far - big sandbox game, procedurally generated, would just like to add lights to it :slight_smile:

This maybe in the wrong section…I’m using libgdx for this.

Many thanks

Your image isn’t working.

You can do: right-click -> open in new tab -> download attachment

aaand OP needs to learn how to post pictures ;D

@topic: If you want a smoothly changing gradient, use shaders OR an overlay rendered over the screen, the latter is as simple as rendering a transparent-in-the-middle image over the whole screen.

You could also write a simple shader that does create your desired effect in the fragment pass for max accuracy.
It’ll be a bit confusing if you do this for the first time though:

Depending on how you draw your sprites, you could also change the tint of the individual sprites to achieve different effects.

Thanks,

Is it possible to pass to the shader if the tile/sprite needs to be lit up?


uniform int renderMode; 

void main() {
    if(renderMode == 0) {
        //render normally
    } else if(renderMode == 1) {
        //lighten tiles color up...
    }
}

Thanks

That is possible, but extremely inefficient. You’ll want to draw all tiles with a single draw call, so at least make renderMode a vertex attribute, not a uniform variable.

Thanks,

Think I need go do some reading on shaders, never really used them before.

If I wanted to do block lighting, can this not be done by just setting the tint on the blocks around the player?

Thanks