Slight GetTracePoints refactor
This commit is contained in:
parent
3f6ed89667
commit
223aee980e
|
@ -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;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue