holes backface when box face does

This commit is contained in:
ethan merchant 2024-11-10 15:38:40 -05:00
parent 2eb15dd992
commit 470fa38107

View file

@ -9,6 +9,7 @@ static class Arts
static Dictionary<string, Mesh> meshes = new(); static Dictionary<string, Mesh> meshes = new();
static Material mat_mono = new Material("mono.hlsl"); static Material mat_mono = new Material("mono.hlsl");
static Material mat_unlit = new Material("unlit.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_backbox = new Material("backbox.hlsl");
static Material mat_justcolor = new Material("justcolor.hlsl"); static Material mat_justcolor = new Material("justcolor.hlsl");
@ -155,17 +156,23 @@ static class Arts
// holes // holes
foreach (KeyValuePair<XYZi, XYZi> hole in Mono.holes) foreach (KeyValuePair<XYZi, XYZi> hole in Mono.holes)
{ {
meshes["Hole"].Draw( Vec3 hole_normal = V.XYZ(
mat_unlit, Maths.abs(hole.Value.x) * Maths.sign(hole.Key.x),
Matrix.TRS( Maths.abs(hole.Value.y) * Maths.sign(hole.Key.y),
hole.Key.ToVec3, Maths.abs(hole.Value.z) * Maths.sign(hole.Key.z)
Quat.LookDir(hole.Value.ToVec3),
1
)
); );
// [!] 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( meshes["Hole"].Draw(
mat_backbox, back_hole ? mat_backbox : mat_unlit,
Matrix.TRS( Matrix.TRS(
hole.Key.ToVec3, hole.Key.ToVec3,
Quat.LookDir(hole.Value.ToVec3), Quat.LookDir(hole.Value.ToVec3),