So i'm working on a little tile based lighting system, And to my surprise, It's coming along nicely. As of now it supports multiple light sources with various radiuses/radii(or whatever the god damn plural is). So the next thing i want to implement is colored lights. And that's where the problem lies, I have no idea how i would handle multiple lights with varying colors overlapping.
I will attach the .love, But i thought it may help to explain briefly how the whole system works.
So i have a grid of cells, Each cell has a light_level parameter (It's really just the alpha value for the cell, but light_level looks cooler), And a boolean which tells the system if the cell is a light source or not (meaning it emits light)
Then to update the lights i loop through all the cells, On each cell i loop through all the light sources, And check if the cell is within the radius of any of them, Then based on the distance between the cell and the sources i calculate the light_level for the cell, If the cell is within the range of multiple lights, I calculate the light_level for the lights individually, Then add them together. I'm not updating the lights each frame so it's not as inefficient as it sounds (Could probably be more efficient though)
So yeah, Any help would be greatly appreciated, Thanks in advance.
.love controls:
Left click to add a light at mouse position, Right click to remove it. And the mouse wheel to adjust the radius of the lights. (The light you're about to place that is not the ones that are already there)
Tile based lights with different colors overlapping
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Tile based lights with different colors overlapping
- Attachments
-
- Tile lights.love
- (2.14 KiB) Downloaded 195 times
Re: Tile based lights with different colors overlapping
I really suggest you to simply use stencil (or whatever) based lights system. Easier to implement (or reuse), nicer result.
Re: Tile based lights with different colors overlapping
Could you elaborate? I'm not sure what you mean by "stencil based"raidho36 wrote:I really suggest you to simply use stencil (or whatever) based lights system. Easier to implement (or reuse), nicer result.
Re: Tile based lights with different colors overlapping
Well not really stencil based, but I've seen people doing it using stencils and shaders rather than offscreen surfaces.
Anyway, here's the thing: you create two surfaces, one for accumulation of total color and other for current processing, for every light souce fill the current surface with light and shadows, apply to accumulation surface with addition mode, repeat. Finally, apply resulted surface with "multiplication" color mode to the plain lit white image.
Anyway, here's the thing: you create two surfaces, one for accumulation of total color and other for current processing, for every light souce fill the current surface with light and shadows, apply to accumulation surface with addition mode, repeat. Finally, apply resulted surface with "multiplication" color mode to the plain lit white image.
- Ranguna259
- Party member
- Posts: 911
- Joined: Tue Jun 18, 2013 10:58 pm
- Location: I'm right next to you
Re: Tile based lights with different colors overlapping
Or you could make a layer for each light source ?
(Here's a side view exemple of each layer)
('c' being the center of the circle and '_' being the ever darker light)
Inicial(no light source):
(0 layers)
one light source:
(1 layer)
two light sources:
(2 layers)
three light sources
(3 layers)
You see, each source has it's own layer so it is l being the number of the layer, each layer has only one source.
You could also do
Since each source has it's own layer and each cell has it's alpha value then love will take care or overlaping all the layers so each cell will be on top of the other creating a different colors when there are two cells from two layers with different colors each, this happens due to the alpha's value.
I don't think I explained well enough, tell me if you didn't understand, and once you are done please post the final .love, I want see the pretty colors too
(Here's a side view exemple of each layer)
('c' being the center of the circle and '_' being the ever darker light)
Inicial(no light source):
Code: Select all
one light source:
Code: Select all
: ______c______
two light sources:
Code: Select all
: ______c______
: ______c______
three light sources
Code: Select all
: _________________c_________________
: ______c______
: ______c______
You see, each source has it's own layer so it is
Code: Select all
cell[x][y][l]
You could also do
Code: Select all
cell[l].x
cell[l].y
I don't think I explained well enough, tell me if you didn't understand, and once you are done please post the final .love, I want see the pretty colors too
Re: Tile based lights with different colors overlapping
How about this: Separate the light into three channels for red, green and blue. Process each channel as you describe in the quote. In other words: Just "add" the value for red, green and blue separately.veethree wrote:Then to update the lights i loop through all the cells, On each cell i loop through all the light sources, And check if the cell is within the radius of any of them, Then based on the distance between the cell and the sources i calculate the light_level for the cell, If the cell is within the range of multiple lights, I calculate the light_level for the lights individually, Then add them together. I'm not updating the lights each frame so it's not as inefficient as it sounds (Could probably be more efficient though)
Check out my blog on gamedev
Re: Tile based lights with different colors overlapping
I can't figure out if that would work or not..Good idea though, Gonna try that at some point. Thanks.micha wrote:How about this: Separate the light into three channels for red, green and blue. Process each channel as you describe in the quote. In other words: Just "add" the value for red, green and blue separately.veethree wrote:Then to update the lights i loop through all the cells, On each cell i loop through all the light sources, And check if the cell is within the radius of any of them, Then based on the distance between the cell and the sources i calculate the light_level for the cell, If the cell is within the range of multiple lights, I calculate the light_level for the lights individually, Then add them together. I'm not updating the lights each frame so it's not as inefficient as it sounds (Could probably be more efficient though)
Re: Tile based lights with different colors overlapping
When increasing the lights' size I was expecting to increase the radius of the light source itself but it only increases the radius of the area where the light is banished, so for example I would expect to increase the size of the lamp bulb if they where lamps, and that means that the area affected by the light gets increased too.
Who is online
Users browsing this forum: Google [Bot] and 207 guests