From 1d96c060325dd48190bd7d1d2a3cb0cfb629fb16 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 4 Nov 2024 18:09:39 +0000 Subject: [PATCH] Add water surfaces to the Embree scene and surface type map --- KeepersCompound.Lightmapper/LightMapper.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/KeepersCompound.Lightmapper/LightMapper.cs b/KeepersCompound.Lightmapper/LightMapper.cs index 94c6adf..93e6899 100644 --- a/KeepersCompound.Lightmapper/LightMapper.cs +++ b/KeepersCompound.Lightmapper/LightMapper.cs @@ -128,9 +128,9 @@ public class LightMapper continue; } - 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 meshIndexOffset = vertices.Count; @@ -141,9 +141,17 @@ public class LightMapper vertices.Add(vertex); } - // For now we're only differentiating between solid and sky because portal polys are skipped + // We need to know what type of surface this poly is so we can map Embree primitive IDs to surface + // types var renderPoly = cell.RenderPolys[polyIdx]; - var primType = renderPoly.TextureId == 249 ? SurfaceType.Sky : SurfaceType.Solid; + var primType = SurfaceType.Solid; + if (renderPoly.TextureId == 249) + { + primType = SurfaceType.Sky; + } else if (polyIdx >= solidPolys) + { + primType = SurfaceType.Water; + } // Cell polygons are n-sided, but fortunately they're convex so we can just do a fan triangulation for (var j = 1; j < numPolyVertices - 1; j++)