Add light falloff and diffuse angle

This commit is contained in:
Jarrod Doyle 2024-09-23 20:32:47 +01:00
parent e004292e53
commit 10a8a31520
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 11 additions and 2 deletions

View File

@ -1,4 +1,4 @@
using System.Numerics; using System.Numerics;
using KeepersCompound.LGS.Database; using KeepersCompound.LGS.Database;
using KeepersCompound.LGS.Database.Chunks; using KeepersCompound.LGS.Database.Chunks;
using TinyEmbree; using TinyEmbree;
@ -286,7 +286,16 @@ class Program
var hit = hitResult && Math.Abs(hitResult.Distance - direction.Length()) < 0.001; var hit = hitResult && Math.Abs(hitResult.Distance - direction.Length()) < 0.001;
if (hit) if (hit)
{ {
lightmap.AddLight(0, x, y, (byte)light.color.X, (byte)light.color.Y, (byte)light.color.Z); // TODO: This isn't perfectly accurate, but it's pretty fucking close tbh
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;
strength = Math.Min(1.0f, strength);
var c = light.color * strength;
lightmap.AddLight(0, x, y, (byte)c.X, (byte)c.Y, (byte)c.Z);
} }
} }
} }