[rs] Change NDC Y axis

This commit is contained in:
Dzmitry Malyshau authored and Dzmitry Malyshau committed 2020-03-30 09:36:36 -04:00
1 parent 2ebde4bb9d
commit 7ff7eb2f22
2 files changed
+4 -2

No files matched your search

+1 -1
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,
);
+3 -1
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
);