From dca1b1e5edc117423886837b23085a083ba7dcd1 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 26 Sep 2024 12:12:14 +0100 Subject: [PATCH] Extract light strength calculation to method in prep for inner radius handling --- KeepersCompound.Lightmapper/Program.cs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/KeepersCompound.Lightmapper/Program.cs b/KeepersCompound.Lightmapper/Program.cs index 98e4746..d98a1d2 100644 --- a/KeepersCompound.Lightmapper/Program.cs +++ b/KeepersCompound.Lightmapper/Program.cs @@ -339,15 +339,7 @@ class Program var hit = hitResult && Math.Abs(hitResult.Distance - direction.Length()) < MathUtils.Epsilon; if (hit) { - // Calculate light strength at a given point. As far as I can tell - // this is exact to Dark (I'm a genius??). It's just an inverse distance - // falloff with diffuse angle, except we have to scale the length. - var dir = light.position - pos; - var angle = Vector3.Dot(Vector3.Normalize(dir), plane.Normal); - var len = dir.Length(); - var slen = len / 4.0f; - var strength = (angle + 1.0f) / slen; - + var strength = CalculateLightStrengthAtPoint(light, pos, plane); lightmap.AddLight(0, x, y, light.color, strength, hdr); } } @@ -361,6 +353,20 @@ class Program Console.Write("\n"); } + private static float CalculateLightStrengthAtPoint(Light light, Vector3 point, Plane plane) + { + // Calculate light strength at a given point. As far as I can tell + // this is exact to Dark (I'm a genius??). It's just an inverse distance + // falloff with diffuse angle, except we have to scale the length. + var dir = light.position - point; + var angle = Vector3.Dot(Vector3.Normalize(dir), plane.Normal); + var len = dir.Length(); + var slen = len / 4.0f; + var strength = (angle + 1.0f) / slen; + + return strength; + } + private static void ResetLightmap(Vector3 ambientLight, WorldRep.Cell.Lightmap lightmap, bool hdr) { for (var i = 0; i < lightmap.Pixels.Length; i++)