Hello everyone.
I am making a game that's set in the 5 boroughs of New York and it's set at night.
Although my game's art is already having a darker colour palette, I would love to have a lighting effect that made so that the street lamps and cards headlights lightened the scene (or their absence darkens it).
Something to the lines of this.
How would I go about doing something like this?
2d Lighting with shaders
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: 2d Lighting with shaders
That's a fun challenge.
While I can think of two ways of doing that, one is better than the other.
The first way is: you draw the entire scene at night (like using nighttime editions of all background and foreground graphics, or using a dark tint color set by love.graphics.setColor so it multiplies with their original colors), then after that you re-paint parts of the scene using the "lit up" version of those graphics (like drawing the same graphics but using a lighter tint color with setColor so they appear brighter, or literally drawing lit up editions of the graphics like from different images). The bright parts of the scene will appear as the parts lit by the lamps.
However, that won't work well if you want multiple lights overlapping each other and the effect accumulating between them.
For that, there's another method which is a relative color change -- you are painting shapes or images onto the screen with the "add" blending mode, pushing the colors on screen in some direction like lighting them up.
You can mask the image or shape used for additive blending based on the fact that a black color results in no change (the color being overpainted will stay the same).
PS sometimes the interpolation between two colors results in a muddy intermediary color that doesn't look right, and that's because the blending is happening while both colors are in gamma space (sRGB). It's a nuance anyway and people don't notice while playing, but if you want to fix that, you can either turn on the gamma correction mode in conf.lua or doing the color conversions yourself in a pixel shader. You can search the forums about this, or also read more here if interested:
- https://blog.johnnovak.net/2016/09/21/w ... r-blending
- https://love2d.org/wiki/love.graphics.isGammaCorrect
- http://www.gamedev.net/forums/topic/709 ... d/5438887/
While I can think of two ways of doing that, one is better than the other.
The first way is: you draw the entire scene at night (like using nighttime editions of all background and foreground graphics, or using a dark tint color set by love.graphics.setColor so it multiplies with their original colors), then after that you re-paint parts of the scene using the "lit up" version of those graphics (like drawing the same graphics but using a lighter tint color with setColor so they appear brighter, or literally drawing lit up editions of the graphics like from different images). The bright parts of the scene will appear as the parts lit by the lamps.
However, that won't work well if you want multiple lights overlapping each other and the effect accumulating between them.
For that, there's another method which is a relative color change -- you are painting shapes or images onto the screen with the "add" blending mode, pushing the colors on screen in some direction like lighting them up.
You can mask the image or shape used for additive blending based on the fact that a black color results in no change (the color being overpainted will stay the same).
PS sometimes the interpolation between two colors results in a muddy intermediary color that doesn't look right, and that's because the blending is happening while both colors are in gamma space (sRGB). It's a nuance anyway and people don't notice while playing, but if you want to fix that, you can either turn on the gamma correction mode in conf.lua or doing the color conversions yourself in a pixel shader. You can search the forums about this, or also read more here if interested:
- https://blog.johnnovak.net/2016/09/21/w ... r-blending
- https://love2d.org/wiki/love.graphics.isGammaCorrect
- http://www.gamedev.net/forums/topic/709 ... d/5438887/
-
- Prole
- Posts: 4
- Joined: Sat Nov 23, 2024 3:14 pm
Re: 2d Lighting with shaders
Thanks for your reply. I was hoping to do it with shaders. I'll give that a try tho
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 2 guests