Slight GetTracePoints refactor

This commit is contained in:
Jarrod Doyle 2025-01-26 12:33:01 +00:00
parent 3f6ed89667
commit 223aee980e
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 24 additions and 22 deletions

View File

@ -824,12 +824,22 @@ public class LightMapper
MathUtils.PlanePointMapper planeMapper, MathUtils.PlanePointMapper planeMapper,
Vector2[] v2ds) Vector2[] v2ds)
{ {
polyCenter += planeMapper.Normal * 0.25f;
var tracePoints = new Vector3[offsets.Length]; var tracePoints = new Vector3[offsets.Length];
for (var i = 0; i < offsets.Length; i++) for (var i = 0; i < offsets.Length; i++)
{ {
var offset = offsets[i]; var offset = offsets[i];
var pos = basePosition + offset; var pos = basePosition + offset;
// If the target lightmap point is in view of the center
// then we can use it as-is. Using it straight fixes seams and such.
if (!TraceOcclusion(polyCenter, pos))
{
tracePoints[i] = pos;
continue;
}
// If we can't see our target point from the center of the poly // If we can't see our target point from the center of the poly
// then we need to clip the point to slightly inside the poly // then we need to clip the point to slightly inside the poly
// and retrace to avoid two problems: // and retrace to avoid two problems:
@ -837,24 +847,17 @@ public class LightMapper
// the polygon but is partially contained in the polygon // the polygon but is partially contained in the polygon
// 2. Darkened spots from linear filtering of points outside the // 2. Darkened spots from linear filtering of points outside the
// polygon which have missed // polygon which have missed
var occluded = TraceOcclusion(polyCenter + planeMapper.Normal * 0.25f, pos);
if (occluded)
{
var p2d = planeMapper.MapTo2d(pos); var p2d = planeMapper.MapTo2d(pos);
p2d = MathUtils.ClipPointToPoly2d(p2d, v2ds); p2d = MathUtils.ClipPointToPoly2d(p2d, v2ds);
pos = planeMapper.MapTo3d(p2d); pos = planeMapper.MapTo3d(p2d);
// If the clipping fails, just say screw it and cast :( // If the clipping fails, just say screw it and cast :(
// TODO: This fails if there's an immovable object blocking the poly center. Need give object polys a different type and do a filtered cast/loop cast ignoring immobile hits if (TraceOcclusion(polyCenter, pos))
occluded = TraceOcclusion(polyCenter + planeMapper.Normal * 0.25f, pos);
if (occluded)
{ {
var origin = polyCenter + planeMapper.Normal * 0.25f;
var direction = pos - origin;
var hitResult = _scene.Trace(new Ray var hitResult = _scene.Trace(new Ray
{ {
Origin = polyCenter + planeMapper.Normal * 0.25f, Origin = polyCenter,
Direction = Vector3.Normalize(direction), Direction = Vector3.Normalize(pos - polyCenter),
}); });
if (hitResult) if (hitResult)
@ -862,7 +865,6 @@ public class LightMapper
pos = hitResult.Position; pos = hitResult.Position;
} }
} }
}
tracePoints[i] = pos; tracePoints[i] = pos;
} }