Enable depth testing
To get the right order, flip the sign of the `z` component in the output of the projection map.
This commit is contained in:
parent
1fbeb23194
commit
f274119da6
@ -150,6 +150,9 @@ fn main() {
|
|||||||
let vertex_array = ctx.create_vertex_array().unwrap();
|
let vertex_array = ctx.create_vertex_array().unwrap();
|
||||||
ctx.bind_vertex_array(Some(&vertex_array));
|
ctx.bind_vertex_array(Some(&vertex_array));
|
||||||
|
|
||||||
|
// enable depth testing
|
||||||
|
ctx.enable(WebGl2RenderingContext::DEPTH_TEST);
|
||||||
|
|
||||||
// set the projection map
|
// set the projection map
|
||||||
let focal_length = 3.0_f32;
|
let focal_length = 3.0_f32;
|
||||||
let near_clip = 0.1_f32;
|
let near_clip = 0.1_f32;
|
||||||
@ -158,8 +161,8 @@ fn main() {
|
|||||||
let world_to_clip: [f32; 16] = [
|
let world_to_clip: [f32; 16] = [
|
||||||
focal_length, 0.0, 0.0, 0.0,
|
focal_length, 0.0, 0.0, 0.0,
|
||||||
0.0, focal_length, 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, -(near_clip + far_clip) * depth_inv, -1.,
|
||||||
0.0, 0.0, 2. * near_clip * far_clip * depth_inv, 0.0
|
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);
|
ctx.uniform_matrix4fv_with_f32_array(world_to_clip_loc.as_ref(), false, &world_to_clip);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user