From b47a7536c48887922c93ce87feb986e616a4d342 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 4 Nov 2024 18:08:54 +0000 Subject: [PATCH] Ray traces now continue through any water they hit (unless the water surface is the target) --- KeepersCompound.Lightmapper/LightMapper.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/KeepersCompound.Lightmapper/LightMapper.cs b/KeepersCompound.Lightmapper/LightMapper.cs index 4c81ff1..94c6adf 100644 --- a/KeepersCompound.Lightmapper/LightMapper.cs +++ b/KeepersCompound.Lightmapper/LightMapper.cs @@ -612,13 +612,23 @@ public class LightMapper private bool TraceRay(Vector3 origin, Vector3 target) { - var direction = target - origin; - var hitResult = _scene.Trace(new Ray + var hitDistanceFromTarget = float.MinValue; + var hitSurfaceType = SurfaceType.Water; + while (hitDistanceFromTarget < -MathUtils.Epsilon && hitSurfaceType == SurfaceType.Water) { - Origin = origin, - Direction = Vector3.Normalize(direction), - }); - return hitResult && Math.Abs(hitResult.Distance - direction.Length()) < MathUtils.Epsilon; + var direction = target - origin; + var hitResult = _scene.Trace(new Ray + { + Origin = origin, + Direction = Vector3.Normalize(direction), + }); + + hitDistanceFromTarget = hitResult.Distance - direction.Length(); + hitSurfaceType = _triangleTypeMap[(int)hitResult.PrimId]; + origin = hitResult.Position += direction * MathUtils.Epsilon; + } + + return Math.Abs(hitDistanceFromTarget) < MathUtils.Epsilon; } private void SetAnimLightCellMaps()