From b3a71e68276ba66d25cab9ac7bdfcb72923cd1b4 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 4 Nov 2024 18:39:10 +0000 Subject: [PATCH] Add lightmapped water --- KeepersCompound.Lightmapper/LightMapper.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/KeepersCompound.Lightmapper/LightMapper.cs b/KeepersCompound.Lightmapper/LightMapper.cs index 93e6899..adaab96 100644 --- a/KeepersCompound.Lightmapper/LightMapper.cs +++ b/KeepersCompound.Lightmapper/LightMapper.cs @@ -21,6 +21,7 @@ public class LightMapper public bool Hdr; public SoftnessMode MultiSampling; public float MultiSamplingCenterWeight; + public bool LightmappedWater; } private ResourcePathManager.CampaignResources _campaign; @@ -56,14 +57,16 @@ public class LightMapper return; } + // 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, MultiSampling = lmParams.ShadowSoftness, MultiSamplingCenterWeight = lmParams.CenterWeight, + LightmappedWater = lmParams.LightmappedWater, }; - + Timing.TimeStage("Gather Lights", BuildLightList); Timing.TimeStage("Set Light Indices", SetCellLightIndices); Timing.TimeStage("Trace Scene", () => TraceScene(settings)); @@ -390,9 +393,9 @@ public class LightMapper return; } - var maxPolyIdx = Math.Min(numRenderPolys, numPolys - numPortalPolys); + var solidPolys = numPolys - numPortalPolys; var cellIdxOffset = 0; - for (var polyIdx = 0; polyIdx < maxPolyIdx; polyIdx++) + for (var polyIdx = 0; polyIdx < numRenderPolys; polyIdx++) { var poly = cell.Polys[polyIdx]; var plane = cell.Planes[poly.PlaneId]; @@ -401,6 +404,14 @@ public class LightMapper var lightmap = cell.Lightmaps[polyIdx]; info.AnimLightBitmask = 0; + + // We have to reset the lightmaps for water, but we don't want to do anything else + var waterPoly = polyIdx >= solidPolys; + if (!settings.LightmappedWater && waterPoly) + { + lightmap.Reset(Vector3.One * 255f, settings.Hdr); + continue; + } lightmap.Reset(settings.AmbientLight, settings.Hdr); // Get world position of lightmap (0, 0) (+0.5 so we cast from the center of a pixel)