From 9251685d26d255f7a5b2d2d46129b950370b0384 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 29 Sep 2024 14:46:46 +0100 Subject: [PATCH] Handle subtractive lights --- KeepersCompound.LGS/Database/Chunks/WorldRep.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/KeepersCompound.LGS/Database/Chunks/WorldRep.cs b/KeepersCompound.LGS/Database/Chunks/WorldRep.cs index 36081ff..e0ce010 100644 --- a/KeepersCompound.LGS/Database/Chunks/WorldRep.cs +++ b/KeepersCompound.LGS/Database/Chunks/WorldRep.cs @@ -232,16 +232,16 @@ public class WorldRep : IChunk } // TODO: This ONLY works for rgba (bpp = 4)!!! - public void AddLight(int layer, int x, int y, byte r, byte g, byte b) + public readonly void AddLight(int layer, int x, int y, float r, float g, float b) { var idx = (x + y * Width + layer * Width * Height) * Bpp; - Pixels[idx] = (byte)Math.Min(Pixels[idx] + b, 255); - Pixels[idx + 1] = (byte)Math.Min(Pixels[idx + 1] + g, 255); - Pixels[idx + 2] = (byte)Math.Min(Pixels[idx + 2] + r, 255); + Pixels[idx] = (byte)Math.Clamp(Pixels[idx] + r, 0, 255); + Pixels[idx + 1] = (byte)Math.Clamp(Pixels[idx + 1] + g, 0, 255); + Pixels[idx + 2] = (byte)Math.Clamp(Pixels[idx + 2] + b, 0, 255); Pixels[idx + 3] = 255; } - public void AddLight(int layer, int x, int y, Vector3 color, float strength, bool hdr) + public readonly void AddLight(int layer, int x, int y, Vector3 color, float strength, bool hdr) { if (hdr) { @@ -264,7 +264,7 @@ public class WorldRep : IChunk c /= ratio; } - AddLight(layer, x, y, (byte)c.X, (byte)c.Y, (byte)c.Z); + AddLight(layer, x, y, c.Z, c.Y, c.X); } public readonly void Write(BinaryWriter writer)