From ca3d8038cf7eca5d6e66e0f0d40c00a2143fd78f Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 24 Oct 2019 12:27:10 -0400 Subject: [PATCH] [rs] Fix shadow sampling outside of the positive hemisphere --- wgpu/examples/shadow/forward.frag | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/wgpu/examples/shadow/forward.frag b/wgpu/examples/shadow/forward.frag index 7af5dbdc7f..fdd587ae6d 100644 --- a/wgpu/examples/shadow/forward.frag +++ b/wgpu/examples/shadow/forward.frag @@ -28,6 +28,19 @@ layout(set = 1, binding = 0) uniform Entity { vec4 u_Color; }; +float fetch_shadow(int light_id, vec4 homogeneous_coords) { + if (homogeneous_coords.w <= 0.0) { + return 1.0; + } + // compute texture coordinates for shadow lookup + vec4 light_local = vec4( + (homogeneous_coords.xy/homogeneous_coords.w + 1.0) / 2.0, + light_id, + homogeneous_coords.z / homogeneous_coords.w + ); + // do the lookup, using HW PCF and comparison + return texture(sampler2DArrayShadow(t_Shadow, s_Shadow), light_local); +} void main() { vec3 normal = normalize(v_Normal); @@ -37,13 +50,7 @@ void main() { for (int i=0; i