Add lightmapped water

This commit is contained in:
Jarrod Doyle 2024-11-04 18:39:10 +00:00
parent 1d96c06032
commit b3a71e6827
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 14 additions and 3 deletions

View File

@ -21,6 +21,7 @@ public class LightMapper
public bool Hdr; public bool Hdr;
public SoftnessMode MultiSampling; public SoftnessMode MultiSampling;
public float MultiSamplingCenterWeight; public float MultiSamplingCenterWeight;
public bool LightmappedWater;
} }
private ResourcePathManager.CampaignResources _campaign; private ResourcePathManager.CampaignResources _campaign;
@ -56,14 +57,16 @@ public class LightMapper
return; return;
} }
// TODO: lmParams LightmappedWater doesn't mean the game will actually *use* the lightmapped water hmm
var settings = new Settings var settings = new Settings
{ {
Hdr = worldRep.DataHeader.LightmapFormat == 2, Hdr = worldRep.DataHeader.LightmapFormat == 2,
AmbientLight = rendParams.ambientLight * 255, AmbientLight = rendParams.ambientLight * 255,
MultiSampling = lmParams.ShadowSoftness, MultiSampling = lmParams.ShadowSoftness,
MultiSamplingCenterWeight = lmParams.CenterWeight, MultiSamplingCenterWeight = lmParams.CenterWeight,
LightmappedWater = lmParams.LightmappedWater,
}; };
Timing.TimeStage("Gather Lights", BuildLightList); Timing.TimeStage("Gather Lights", BuildLightList);
Timing.TimeStage("Set Light Indices", SetCellLightIndices); Timing.TimeStage("Set Light Indices", SetCellLightIndices);
Timing.TimeStage("Trace Scene", () => TraceScene(settings)); Timing.TimeStage("Trace Scene", () => TraceScene(settings));
@ -390,9 +393,9 @@ public class LightMapper
return; return;
} }
var maxPolyIdx = Math.Min(numRenderPolys, numPolys - numPortalPolys); var solidPolys = numPolys - numPortalPolys;
var cellIdxOffset = 0; var cellIdxOffset = 0;
for (var polyIdx = 0; polyIdx < maxPolyIdx; polyIdx++) for (var polyIdx = 0; polyIdx < numRenderPolys; polyIdx++)
{ {
var poly = cell.Polys[polyIdx]; var poly = cell.Polys[polyIdx];
var plane = cell.Planes[poly.PlaneId]; var plane = cell.Planes[poly.PlaneId];
@ -401,6 +404,14 @@ public class LightMapper
var lightmap = cell.Lightmaps[polyIdx]; var lightmap = cell.Lightmaps[polyIdx];
info.AnimLightBitmask = 0; 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); lightmap.Reset(settings.AmbientLight, settings.Hdr);
// Get world position of lightmap (0, 0) (+0.5 so we cast from the center of a pixel) // Get world position of lightmap (0, 0) (+0.5 so we cast from the center of a pixel)