Skip to content
This repository was archived by the owner on Jun 18, 2021. It is now read-only.

Commit 02f7ac9

Browse files
committed
Change NDC Y axis
1 parent 0e7fc82 commit 02f7ac9

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

examples/framework.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use winit::event::WindowEvent;
44
#[allow(unused)]
55
pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
66
1.0, 0.0, 0.0, 0.0,
7-
0.0, -1.0, 0.0, 0.0,
7+
0.0, 1.0, 0.0, 0.0,
88
0.0, 0.0, 0.5, 0.0,
99
0.0, 0.0, 0.5, 1.0,
1010
);

examples/shadow/forward.frag

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ float fetch_shadow(int light_id, vec4 homogeneous_coords) {
3232
if (homogeneous_coords.w <= 0.0) {
3333
return 1.0;
3434
}
35+
// compensate for the Y-flip difference between the NDC and texture coordinates
36+
const vec2 flip_correction = vec2(0.5, -0.5);
3537
// compute texture coordinates for shadow lookup
3638
vec4 light_local = vec4(
37-
(homogeneous_coords.xy/homogeneous_coords.w + 1.0) / 2.0,
39+
homogeneous_coords.xy * flip_correction/homogeneous_coords.w + 0.5,
3840
light_id,
3941
homogeneous_coords.z / homogeneous_coords.w
4042
);

0 commit comments

Comments
 (0)