diff --git a/wgpu/examples/shadow/bake.vert b/wgpu/examples/shadow/bake.vert index 32e257c6b7..e4426b7455 100644 --- a/wgpu/examples/shadow/bake.vert +++ b/wgpu/examples/shadow/bake.vert @@ -13,6 +13,4 @@ layout(set = 1, binding = 0) uniform Entity { void main() { gl_Position = u_ViewProj * u_World * vec4(a_Pos); - // convert from -1,1 Z to 0,1 - gl_Position.z = 0.5 * (gl_Position.z + gl_Position.w); } diff --git a/wgpu/examples/shadow/forward.frag b/wgpu/examples/shadow/forward.frag index 9a2bd8fc67..7af5dbdc7f 100644 --- a/wgpu/examples/shadow/forward.frag +++ b/wgpu/examples/shadow/forward.frag @@ -39,7 +39,8 @@ void main() { // project into the light space vec4 light_local = light.proj * v_Position; // compute texture coordinates for shadow lookup - light_local.xyw = (light_local.xyz/light_local.w + 1.0) / 2.0; + light_local.xy = (light_local.xy/light_local.w + 1.0) / 2.0; + light_local.w = light_local.z / light_local.w; light_local.z = i; // do the lookup, using HW PCF and comparison float shadow = texture(sampler2DArrayShadow(t_Shadow, s_Shadow), light_local); diff --git a/wgpu/examples/shadow/main.rs b/wgpu/examples/shadow/main.rs index e0608d425e..8a4cc86a4a 100644 --- a/wgpu/examples/shadow/main.rs +++ b/wgpu/examples/shadow/main.rs @@ -113,7 +113,8 @@ impl Light { near: self.depth.start, far: self.depth.end, }; - let mx_view_proj = cgmath::Matrix4::from(projection.to_perspective()) * mx_view; + let mx_correction = framework::opengl_to_wgpu_matrix(); + let mx_view_proj = mx_correction * cgmath::Matrix4::from(projection.to_perspective()) * mx_view; LightRaw { proj: *mx_view_proj.as_ref(), pos: [self.pos.x, self.pos.y, self.pos.z, 1.0],