Extract light strength calculation to method in prep for inner radius handling

This commit is contained in:
Jarrod Doyle 2024-09-26 12:12:14 +01:00
parent dcecc33bcd
commit dca1b1e5ed
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 15 additions and 9 deletions

View File

@ -339,15 +339,7 @@ class Program
var hit = hitResult && Math.Abs(hitResult.Distance - direction.Length()) < MathUtils.Epsilon;
if (hit)
{
// Calculate light strength at a given point. As far as I can tell
// this is exact to Dark (I'm a genius??). It's just an inverse distance
// falloff with diffuse angle, except we have to scale the length.
var dir = light.position - pos;
var angle = Vector3.Dot(Vector3.Normalize(dir), plane.Normal);
var len = dir.Length();
var slen = len / 4.0f;
var strength = (angle + 1.0f) / slen;
var strength = CalculateLightStrengthAtPoint(light, pos, plane);
lightmap.AddLight(0, x, y, light.color, strength, hdr);
}
}
@ -361,6 +353,20 @@ class Program
Console.Write("\n");
}
private static float CalculateLightStrengthAtPoint(Light light, Vector3 point, Plane plane)
{
// Calculate light strength at a given point. As far as I can tell
// this is exact to Dark (I'm a genius??). It's just an inverse distance
// falloff with diffuse angle, except we have to scale the length.
var dir = light.position - point;
var angle = Vector3.Dot(Vector3.Normalize(dir), plane.Normal);
var len = dir.Length();
var slen = len / 4.0f;
var strength = (angle + 1.0f) / slen;
return strength;
}
private static void ResetLightmap(Vector3 ambientLight, WorldRep.Cell.Lightmap lightmap, bool hdr)
{
for (var i = 0; i < lightmap.Pixels.Length; i++)