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,30 +847,22 @@ 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); var p2d = planeMapper.MapTo2d(pos);
if (occluded) p2d = MathUtils.ClipPointToPoly2d(p2d, v2ds);
pos = planeMapper.MapTo3d(p2d);
// If the clipping fails, just say screw it and cast :(
if (TraceOcclusion(polyCenter, pos))
{ {
var p2d = planeMapper.MapTo2d(pos); var hitResult = _scene.Trace(new Ray
p2d = MathUtils.ClipPointToPoly2d(p2d, v2ds);
pos = planeMapper.MapTo3d(p2d);
// 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
occluded = TraceOcclusion(polyCenter + planeMapper.Normal * 0.25f, pos);
if (occluded)
{ {
var origin = polyCenter + planeMapper.Normal * 0.25f; Origin = polyCenter,
var direction = pos - origin; Direction = Vector3.Normalize(pos - polyCenter),
var hitResult = _scene.Trace(new Ray });
{
Origin = polyCenter + planeMapper.Normal * 0.25f,
Direction = Vector3.Normalize(direction),
});
if (hitResult) if (hitResult)
{ {
pos = hitResult.Position; pos = hitResult.Position;
}
} }
} }