diff --git a/examples/framework.rs b/examples/framework.rs index bbadbc2610..6a33a0222b 100644 --- a/examples/framework.rs +++ b/examples/framework.rs @@ -4,7 +4,7 @@ use winit::event::WindowEvent; #[allow(unused)] pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4 = 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, ); diff --git a/examples/shadow/forward.frag b/examples/shadow/forward.frag index fdd587ae6d..8a3e2579dc 100644 --- a/examples/shadow/forward.frag +++ b/examples/shadow/forward.frag @@ -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 );