Skip to content

Commit f100d30

Browse files
mvaligurskyMartin Valigursky
and
Martin Valigursky
authored
Fixes to VSM shadow sampling (#7436)
Co-authored-by: Martin Valigursky <mvaligursky@snapchat.com>
1 parent b15f3f1 commit f100d30

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/scene/shader-lib/chunks/lit/frag/lighting/shadowEVSM.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ float calculateEVSM(vec3 moments, float Z, float vsmBias, float exponent) {
4141
// ------ VSM 16 ------
4242
4343
float VSM16(TEXTURE_ACCEPT(tex), vec2 texCoords, float resolution, float Z, float vsmBias, float exponent) {
44-
vec3 moments = texture2D(tex, texCoords).xyz;
44+
vec3 moments = texture2DLod(tex, texCoords, 0.0).xyz;
4545
return calculateEVSM(moments, Z, vsmBias, exponent);
4646
}
4747
@@ -58,18 +58,19 @@ float getShadowSpotVSM16(TEXTURE_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shado
5858
float VSM32(TEXTURE_ACCEPT(tex), vec2 texCoords, float resolution, float Z, float vsmBias, float exponent) {
5959
6060
#ifdef CAPS_TEXTURE_FLOAT_FILTERABLE
61-
vec3 moments = texture2D(tex, texCoords).xyz;
61+
vec3 moments = texture2DLod(tex, texCoords, 0.0).xyz;
6262
#else
6363
// manual bilinear filtering
6464
float pixelSize = 1.0 / resolution;
6565
texCoords -= vec2(pixelSize);
66-
vec3 s00 = texture2D(tex, texCoords).xyz;
67-
vec3 s10 = texture2D(tex, texCoords + vec2(pixelSize, 0)).xyz;
68-
vec3 s01 = texture2D(tex, texCoords + vec2(0, pixelSize)).xyz;
69-
vec3 s11 = texture2D(tex, texCoords + vec2(pixelSize)).xyz;
66+
vec3 s00 = texture2DLod(tex, texCoords, 0.0).xyz;
67+
vec3 s10 = texture2DLod(tex, texCoords + vec2(pixelSize, 0), 0.0).xyz;
68+
vec3 s01 = texture2DLod(tex, texCoords + vec2(0, pixelSize), 0.0).xyz;
69+
vec3 s11 = texture2DLod(tex, texCoords + vec2(pixelSize), 0.0).xyz;
7070
vec2 fr = fract(texCoords * resolution);
7171
vec3 h0 = mix(s00, s10, fr.x);
7272
vec3 h1 = mix(s01, s11, fr.x);
73+
vec3 moments = mix(h0, h1, fr.y);
7374
#endif
7475
7576
return calculateEVSM(moments, Z, vsmBias, exponent);

0 commit comments

Comments
 (0)