[rs] Change NDC Y axis

This commit is contained in:
Dzmitry Malyshau
2020-03-26 12:33:50 -04:00
committed by Dzmitry Malyshau
parent 2ebde4bb9d
commit 7ff7eb2f22
2 changed files with 4 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ use winit::event::WindowEvent;
#[allow(unused)]
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
1.0, 0.0, 0.0, 0.0,
0.0, -1.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.0, 0.0, 0.5, 1.0,
);

View File

@@ -32,9 +32,11 @@ float fetch_shadow(int light_id, vec4 homogeneous_coords) {
if (homogeneous_coords.w <= 0.0) {
return 1.0;
}
// compensate for the Y-flip difference between the NDC and texture coordinates
const vec2 flip_correction = vec2(0.5, -0.5);
// compute texture coordinates for shadow lookup
vec4 light_local = vec4(
(homogeneous_coords.xy/homogeneous_coords.w + 1.0) / 2.0,
homogeneous_coords.xy * flip_correction/homogeneous_coords.w + 0.5,
light_id,
homogeneous_coords.z / homogeneous_coords.w
);