From 2e1c90b88a8f24f302c16fec2b0c5ea807f0d40e Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Thu, 26 Dec 2024 17:12:28 +0000 Subject: [PATCH] Close #10: Apply ambient light zones --- KeepersCompound.Lightmapper/LightMapper.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/KeepersCompound.Lightmapper/LightMapper.cs b/KeepersCompound.Lightmapper/LightMapper.cs index 7d256a1..7ac43ff 100644 --- a/KeepersCompound.Lightmapper/LightMapper.cs +++ b/KeepersCompound.Lightmapper/LightMapper.cs @@ -19,7 +19,7 @@ public class LightMapper private struct Settings { - public Vector3 AmbientLight; + public Vector3[] AmbientLight; public bool Hdr; public SoftnessMode MultiSampling; public float MultiSamplingCenterWeight; @@ -76,12 +76,19 @@ public class LightMapper Direction = Vector3.Normalize(rendParams.sunlightDirection), Color = Utils.HsbToRgb(rendParams.sunlightHue, rendParams.sunlightSaturation, rendParams.sunlightBrightness), }; + + var ambientLight = rendParams.ambientLightZones.ToList(); + ambientLight.Insert(0, rendParams.ambientLight); + for (var i = 0; i < ambientLight.Count; i++) + { + ambientLight[i] *= 255; + } // TODO: lmParams LightmappedWater doesn't mean the game will actually *use* the lightmapped water hmm var settings = new Settings { Hdr = worldRep.DataHeader.LightmapFormat == 2, - AmbientLight = rendParams.ambientLight * 255, + AmbientLight = [..ambientLight], MultiSampling = lmParams.ShadowSoftness, MultiSamplingCenterWeight = lmParams.CenterWeight, LightmappedWater = lmParams.LightmappedWater, @@ -475,7 +482,9 @@ public class LightMapper lightmap.Reset(Vector3.One * 255f, settings.Hdr); continue; } - lightmap.Reset(settings.AmbientLight, settings.Hdr); + + var ambientLight = settings.AmbientLight[cell.ZoneInfo.GetAmbientLightZoneIndex()]; + lightmap.Reset(ambientLight, settings.Hdr); // Get world position of lightmap (0, 0) (+0.5 so we cast from the center of a pixel) var topLeft = cell.Vertices[cell.Indices[cellIdxOffset]];