From f274119da64d9d8b7aac1d3784f6249cbbacbc1c Mon Sep 17 00:00:00 2001 From: Aaron Fenyes Date: Thu, 22 Aug 2024 18:17:01 -0700 Subject: [PATCH] Enable depth testing To get the right order, flip the sign of the `z` component in the output of the projection map. --- app-proto/inversive-display/src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app-proto/inversive-display/src/main.rs b/app-proto/inversive-display/src/main.rs index 72846fc..5afbb04 100644 --- a/app-proto/inversive-display/src/main.rs +++ b/app-proto/inversive-display/src/main.rs @@ -150,6 +150,9 @@ fn main() { let vertex_array = ctx.create_vertex_array().unwrap(); ctx.bind_vertex_array(Some(&vertex_array)); + // enable depth testing + ctx.enable(WebGl2RenderingContext::DEPTH_TEST); + // set the projection map let focal_length = 3.0_f32; let near_clip = 0.1_f32; @@ -158,8 +161,8 @@ fn main() { let world_to_clip: [f32; 16] = [ focal_length, 0.0, 0.0, 0.0, 0.0, focal_length, 0.0, 0.0, - 0.0, 0.0, (near_clip + far_clip) * depth_inv, -1., - 0.0, 0.0, 2. * near_clip * far_clip * depth_inv, 0.0 + 0.0, 0.0, -(near_clip + far_clip) * depth_inv, -1., + 0.0, 0.0, -2. * near_clip * far_clip * depth_inv, 0.0 ]; ctx.uniform_matrix4fv_with_f32_array(world_to_clip_loc.as_ref(), false, &world_to_clip);