From 470fa381073ac80dcac42500460fcb665efb28a7 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Sun, 10 Nov 2024 15:38:40 -0500 Subject: [PATCH] holes backface when box face does --- src/Arts.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Arts.cs b/src/Arts.cs index 13213c7..a5c75f9 100644 --- a/src/Arts.cs +++ b/src/Arts.cs @@ -9,6 +9,7 @@ static class Arts static Dictionary meshes = new(); static Material mat_mono = new Material("mono.hlsl"); static Material mat_unlit = new Material("unlit.hlsl"); + // [!] have backfaces on a mat run a separate backbox/face shader]? *to try and reduce drawcalls static Material mat_backbox = new Material("backbox.hlsl"); static Material mat_justcolor = new Material("justcolor.hlsl"); @@ -155,17 +156,23 @@ static class Arts // holes foreach (KeyValuePair hole in Mono.holes) { - meshes["Hole"].Draw( - mat_unlit, - Matrix.TRS( - hole.Key.ToVec3, - Quat.LookDir(hole.Value.ToVec3), - 1 - ) + Vec3 hole_normal = V.XYZ( + Maths.abs(hole.Value.x) * Maths.sign(hole.Key.x), + Maths.abs(hole.Value.y) * Maths.sign(hole.Key.y), + Maths.abs(hole.Value.z) * Maths.sign(hole.Key.z) ); - // [!] have backfaces on a mat run a separate backbox/face shader]? *to try and reduce drawcalls + Vec3 hole_world_normal = Mono.box_pose.orientation * hole_normal; + Vec3 hole_world = Mono.box_pose.ToMatrix(Mono.box_scale) * V.XYZ( + hole.Key.x - hole.Value.x * 0.5f, + hole.Key.y - hole.Value.y * 0.5f, + hole.Key.z - hole.Value.z * 0.5f + ); + // Vec3 cam_dir = (Rig.head.orientation * Vec3.Forward); + Vec3 hole_view_dir = Vec3.Direction(hole_world, Rig.head.position); + bool back_hole = Vec3.Dot(hole_world_normal, hole_view_dir) < 0.0; + meshes["Hole"].Draw( - mat_backbox, + back_hole ? mat_backbox : mat_unlit, Matrix.TRS( hole.Key.ToVec3, Quat.LookDir(hole.Value.ToVec3),