I've been working on my per-tile lighting system, currently it is very simple and supports coloured lighting.
PROBLEM 1:I started to notice that lighting wouldn't work for random tiles, here is an example:

At first i thought it was a problem in my tiling system, however if i disabled lighting the tiles were fine.
Here is my lighting code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| public void updateLightValues() { for (Tile t : Engine.getMap().getVisibleTiles()) { Point p1 = new Point((int) x, (int) y); double tileDistance = p1.distance((double) t.getX(), (double) t.getY()); tileDistance /= Tile.SIZE; if (tileDistance > lightDistance) continue; float light = lightDistance; light -= tileDistance; light /= 10; light += Engine.getMap().getLightModifier(); if (light < 0) light = 0; if (light > 1) light = 1;
float a = light + t.getLightValue() * (1 - light); float r = ((red * a) + (t.getLightRed() * t.getLightValue())) / a; float g = ((green * a) + (t.getLightGreen() * t.getLightValue())) / a; float b = ((blue * a) + (t.getLightBlue() * t.getLightValue())) / a; t.setLightValues(r, g, b, a); } } |
That method is called every tick and will update light values around the light source.
Note that a light is represented by a LightSource, and the lightsource class holds all variables including this method.
PROBLEM 2:My second problem is with the colour blending. It seems that a light source will blend into another light source, however the light source it's blending into won't be counter-blended, producing a weird blend like this:

Thankyou for your time.