From 7ff7eb2f227c8131b8659996f1074ad707ebef4d Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 26 Mar 2020 12:33:50 -0400 Subject: [PATCH] [rs] Change NDC Y axis --- wgpu/examples/framework.rs | 2 +- wgpu/examples/shadow/forward.frag | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/wgpu/examples/framework.rs b/wgpu/examples/framework.rs index bbadbc2610..6a33a0222b 100644 --- a/wgpu/examples/framework.rs +++ b/wgpu/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/wgpu/examples/shadow/forward.frag b/wgpu/examples/shadow/forward.frag index fdd587ae6d..8a3e2579dc 100644 --- a/wgpu/examples/shadow/forward.frag +++ b/wgpu/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 );