Swap inner and outer pixel tracing loop

This commit is contained in:
Jarrod Doyle 2024-12-09 12:28:52 +00:00
parent 27f8dab8fe
commit c2b69cda46
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 52 additions and 43 deletions

View File

@ -1,4 +1,3 @@
using System.Diagnostics;
using System.Numerics;
using KeepersCompound.LGS;
using KeepersCompound.LGS.Database;
@ -394,6 +393,27 @@ public class LightMapper
var planeMapper = new MathUtils.PlanePointMapper(plane.Normal, vs[0], vs[1]);
var v2ds = planeMapper.MapTo2d(vs);
var (texU, texV) = renderPoly.TextureVectors;
var (offsets, weights) =
GetTraceOffsetsAndWeights(settings.MultiSampling, texU, texV, settings.MultiSamplingCenterWeight);
var (quadOffsets, quadWeights) = settings.MultiSampling == SoftnessMode.HighFourPoint
? (offsets, weights)
: GetTraceOffsetsAndWeights(SoftnessMode.HighFourPoint, texU, texV, settings.MultiSamplingCenterWeight);
for (var y = 0; y < lightmap.Height; y++)
{
for (var x = 0; x < lightmap.Width; x++)
{
var pos = topLeft;
pos += x * 0.25f * renderPoly.TextureVectors.Item1;
pos += y * 0.25f * renderPoly.TextureVectors.Item2;
// TODO: Handle quad lit lights better. Right now we're computing two sets of points for every
// luxel. Maybe it's better to only compute if we encounter a quadlit light?
var tracePoints = GetTracePoints(pos, offsets, renderPoly.Center, planeMapper, v2ds);
var quadTracePoints = settings.MultiSampling == SoftnessMode.HighFourPoint
? tracePoints
: GetTracePoints(pos, quadOffsets, renderPoly.Center, planeMapper, v2ds);
foreach (var light in _lights)
{
var layer = 0;
@ -423,23 +443,12 @@ public class LightMapper
continue;
}
for (var y = 0; y < lightmap.Height; y++)
{
for (var x = 0; x < lightmap.Width; x++)
{
var pos = topLeft;
pos += x * 0.25f * renderPoly.TextureVectors.Item1;
pos += y * 0.25f * renderPoly.TextureVectors.Item2;
var softnessMode = light.QuadLit ? SoftnessMode.HighFourPoint : settings.MultiSampling;
var (texU, texV) = renderPoly.TextureVectors;
var (offsets, weights) = GetTraceOffsetsAndWeights(softnessMode, texU, texV,settings.MultiSamplingCenterWeight);
var tracePoints = GetTracePoints(pos, offsets, renderPoly.Center, planeMapper, v2ds);
var strength = 0f;
for (var idx = 0; idx < tracePoints.Length; idx++)
var targetPoints = light.QuadLit ? quadTracePoints : tracePoints;
var targetWeights = light.QuadLit ? quadWeights : weights;
for (var idx = 0; idx < targetPoints.Length; idx++)
{
var point = tracePoints[idx];
var point = targetPoints[idx];
// If we're out of range there's no point casting a ray
// There's probably a better way to discard the entire lightmap
@ -451,7 +460,7 @@ public class LightMapper
if (TraceRay(light.Position, point))
{
strength += weights[idx] * light.StrengthAtPoint(point, plane);
strength += targetWeights[idx] * light.StrengthAtPoint(point, plane);
}
}