From cbd7160821b49af21a23c9ce6d03d9ec23135482 Mon Sep 17 00:00:00 2001 From: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed, 1 May 2024 09:21:40 +0100 Subject: [PATCH] Remove parts of shader chunks only used on WebGL1 (#6327) * Remove parts of shader chunks only used on WebGL1 * removed the define --------- Co-authored-by: Martin Valigursky --- .../examples/graphics/grab-pass/config.mjs | 7 +- src/extras/gizmo/axis-shapes.js | 16 +- .../chunks/common/frag/linearizeDepth.js | 10 -- .../shader-lib/chunks/common/frag/msdf.js | 16 -- .../chunks/common/frag/screenDepth.js | 16 +- .../chunks/lit/frag/clusteredLight.js | 9 +- .../chunks/lit/frag/clusteredLightShadows.js | 167 ++++-------------- .../chunks/lit/frag/shadowCascades.js | 18 +- .../shader-lib/chunks/lit/frag/shadowPCSS.js | 27 +-- .../chunks/lit/frag/shadowStandard.js | 67 ------- 10 files changed, 52 insertions(+), 301 deletions(-) diff --git a/examples/src/examples/graphics/grab-pass/config.mjs b/examples/src/examples/graphics/grab-pass/config.mjs index 1da9ba87a11..dbd2cc1c39c 100644 --- a/examples/src/examples/graphics/grab-pass/config.mjs +++ b/examples/src/examples/graphics/grab-pass/config.mjs @@ -62,11 +62,8 @@ export default { vec3 grabColor = texture2DLodEXT(uSceneColorMap, grabUv + offset, mipmap).rgb; // tint the material based on mipmap - // (note - this could be worked around by using a series of if statements in this case) - #ifdef GL2 - float tintIndex = clamp(mipmap, 0.0, 3.0); - grabColor *= tints[int(tintIndex)]; - #endif + float tintIndex = clamp(mipmap, 0.0, 3.0); + grabColor *= tints[int(tintIndex)]; // brighten the refracted texture a little bit // brighten even more the rough parts of the glass diff --git a/src/extras/gizmo/axis-shapes.js b/src/extras/gizmo/axis-shapes.js index 2208cd47dfc..b7a1052d859 100644 --- a/src/extras/gizmo/axis-shapes.js +++ b/src/extras/gizmo/axis-shapes.js @@ -46,12 +46,10 @@ const SHADER = { void main(void) { gl_Position = matrix_viewProjection * matrix_model * vec4(vertex_position, 1.0); vColor = vertex_color; - #ifdef GL2 - // store z/w for later use in fragment shader - vZW = gl_Position.zw; - // disable depth clipping - gl_Position.z = 0.0; - #endif + // store z/w for later use in fragment shader + vZW = gl_Position.zw; + // disable depth clipping + gl_Position.z = 0.0; }`, frag: /* glsl */` precision highp float; @@ -59,10 +57,8 @@ const SHADER = { varying vec2 vZW; void main(void) { gl_FragColor = vColor; - #ifdef GL2 - // clamp depth in Z to [0, 1] range - gl_FragDepth = max(0.0, min(1.0, (vZW.x / vZW.y + 1.0) * 0.5)); - #endif + // clamp depth in Z to [0, 1] range + gl_FragDepth = max(0.0, min(1.0, (vZW.x / vZW.y + 1.0) * 0.5)); }` }; diff --git a/src/scene/shader-lib/chunks/common/frag/linearizeDepth.js b/src/scene/shader-lib/chunks/common/frag/linearizeDepth.js index a2afd32cc47..521ac512fb4 100644 --- a/src/scene/shader-lib/chunks/common/frag/linearizeDepth.js +++ b/src/scene/shader-lib/chunks/common/frag/linearizeDepth.js @@ -15,18 +15,8 @@ float linearizeDepth(float z, vec4 cameraParams) { uniform vec4 camera_params; // x: 1 / camera_far, y: camera_far, z: camera_near, w: is_ortho #endif -#ifdef GL2 float linearizeDepth(float z) { return linearizeDepth(z, camera_params); } -#else -#ifndef UNPACKFLOAT -#define UNPACKFLOAT -float unpackFloat(vec4 rgbaDepth) { - const vec4 bitShift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0); - return dot(rgbaDepth, bitShift); -} -#endif -#endif #endif `; diff --git a/src/scene/shader-lib/chunks/common/frag/msdf.js b/src/scene/shader-lib/chunks/common/frag/msdf.js index 160f60ce34f..22fba89ddec 100644 --- a/src/scene/shader-lib/chunks/common/frag/msdf.js +++ b/src/scene/shader-lib/chunks/common/frag/msdf.js @@ -1,14 +1,6 @@ export default /* glsl */` uniform sampler2D texture_msdfMap; -#ifdef GL_OES_standard_derivatives -#define USE_FWIDTH -#endif - -#ifdef GL2 -#define USE_FWIDTH -#endif - float median(float r, float g, float b) { return max(min(r, g), min(max(r, g), b)); } @@ -46,17 +38,9 @@ vec4 applyMsdf(vec4 color) { // too large value (0.5) creates a dark glow around the letters float smoothingMax = 0.2; - #ifdef USE_FWIDTH // smoothing depends on size of texture on screen vec2 w = fwidth(vUv0); float smoothing = clamp(w.x * font_textureWidth / font_pxrange, 0.0, smoothingMax); - #else - float font_size = 16.0; // TODO fix this - // smoothing gets smaller as the font size gets bigger - // don't have fwidth we can approximate from font size, this doesn't account for scaling - // so a big font scaled down will be wrong... - float smoothing = clamp(font_pxrange / font_size, 0.0, smoothingMax); - #endif float mapMin = 0.05; float mapMax = clamp(1.0 - font_sdfIntensity, mapMin, 1.0); diff --git a/src/scene/shader-lib/chunks/common/frag/screenDepth.js b/src/scene/shader-lib/chunks/common/frag/screenDepth.js index a42f1aaff64..e0b41a9a521 100644 --- a/src/scene/shader-lib/chunks/common/frag/screenDepth.js +++ b/src/scene/shader-lib/chunks/common/frag/screenDepth.js @@ -18,31 +18,17 @@ uniform vec4 camera_params; // x: 1 / camera_far, y: camera_far, z: cam #endif #define LINEARIZE_DEPTH -#ifdef GL2 float linearizeDepth(float z) { if (camera_params.w == 0.0) return (camera_params.z * camera_params.y) / (camera_params.y + z * (camera_params.z - camera_params.y)); else return camera_params.z + z * (camera_params.y - camera_params.z); } -#else // GL2 -#ifndef UNPACKFLOAT -#define UNPACKFLOAT -float unpackFloat(vec4 rgbaDepth) { - const vec4 bitShift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0); - return dot(rgbaDepth, bitShift); -} -#endif -#endif #endif // LINEARIZE_DEPTH // Retrieves rendered linear camera depth by UV float getLinearScreenDepth(vec2 uv) { - #ifdef GL2 - return linearizeDepth(texture2D(uSceneDepthMap, uv).r); - #else - return unpackFloat(texture2D(uSceneDepthMap, uv)) * camera_params.y; - #endif + return linearizeDepth(texture2D(uSceneDepthMap, uv).r); } #ifndef VERTEXSHADER diff --git a/src/scene/shader-lib/chunks/lit/frag/clusteredLight.js b/src/scene/shader-lib/chunks/lit/frag/clusteredLight.js index c5cd209489f..eb3a3db568f 100644 --- a/src/scene/shader-lib/chunks/lit/frag/clusteredLight.js +++ b/src/scene/shader-lib/chunks/lit/frag/clusteredLight.js @@ -48,13 +48,8 @@ struct ClusterLightData { // area light sizes / orientation vec3 halfHeight; - #ifdef GL2 - // light index - int lightIndex; - #else - // v coordinate to look up the light textures - this is the same as lightIndex but in 0..1 range - float lightV; - #endif + // light index + int lightIndex; // world space position vec3 position; diff --git a/src/scene/shader-lib/chunks/lit/frag/clusteredLightShadows.js b/src/scene/shader-lib/chunks/lit/frag/clusteredLightShadows.js index f8810e3b989..4401f14ee21 100644 --- a/src/scene/shader-lib/chunks/lit/frag/clusteredLightShadows.js +++ b/src/scene/shader-lib/chunks/lit/frag/clusteredLightShadows.js @@ -1,7 +1,6 @@ export default /* glsl */` // Clustered Omni Sampling using atlas - void _getShadowCoordPerspZbuffer(mat4 shadowMatrix, vec4 shadowParams, vec3 wPos) { vec4 projPos = shadowMatrix * vec4(wPos, 1.0); projPos.xyz /= projPos.w; @@ -21,157 +20,69 @@ vec3 normalOffsetPointShadow(vec4 shadowParams, vec3 lightPos, inout vec3 lightD return dir; } -#ifdef GL2 - - #if defined(CLUSTER_SHADOW_TYPE_PCF1) - - float getShadowOmniClusteredPCF1(SHADOWMAP_ACCEPT(shadowMap), vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { - - float shadowTextureResolution = shadowParams.x; - vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); - - float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; - return textureShadow(shadowMap, vec3(uv, shadowZ)); - } - - #endif - - #if defined(CLUSTER_SHADOW_TYPE_PCF3) - - float getShadowOmniClusteredPCF3(SHADOWMAP_ACCEPT(shadowMap), vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { - - float shadowTextureResolution = shadowParams.x; - vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); - - float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; - vec3 shadowCoord = vec3(uv, shadowZ); - return getShadowPCF3x3(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); - } - - #endif - - #if defined(CLUSTER_SHADOW_TYPE_PCF5) +#if defined(CLUSTER_SHADOW_TYPE_PCF1) - float getShadowOmniClusteredPCF5(SHADOWMAP_ACCEPT(shadowMap), vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { +float getShadowOmniClusteredPCF1(SHADOWMAP_ACCEPT(shadowMap), vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { - float shadowTextureResolution = shadowParams.x; - vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); + float shadowTextureResolution = shadowParams.x; + vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); - float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; - vec3 shadowCoord = vec3(uv, shadowZ); - return getShadowPCF5x5(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); - } - - #endif - -#else - - #if defined(CLUSTER_SHADOW_TYPE_PCF1) - - float getShadowOmniClusteredPCF1(sampler2D shadowMap, vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { - - float shadowTextureResolution = shadowParams.x; - vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); - - // no filter shadow sampling - float depth = unpackFloat(textureShadow(shadowMap, uv)); - float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; - return depth > shadowZ ? 1.0 : 0.0; - } - - #endif + float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; + return textureShadow(shadowMap, vec3(uv, shadowZ)); +} - #if defined(CLUSTER_SHADOW_TYPE_PCF3) +#endif - float getShadowOmniClusteredPCF3(sampler2D shadowMap, vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { +#if defined(CLUSTER_SHADOW_TYPE_PCF3) - float shadowTextureResolution = shadowParams.x; - vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); +float getShadowOmniClusteredPCF3(SHADOWMAP_ACCEPT(shadowMap), vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { - // pcf3 - float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; - vec3 shadowCoord = vec3(uv, shadowZ); - return getShadowPCF3x3(shadowMap, shadowCoord, shadowParams); - } + float shadowTextureResolution = shadowParams.x; + vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); - #endif + float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; + vec3 shadowCoord = vec3(uv, shadowZ); + return getShadowPCF3x3(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); +} - #if defined(CLUSTER_SHADOW_TYPE_PCF5) +#endif - // we don't have PCF5 implementation for webgl1, use PCF3 - float getShadowOmniClusteredPCF5(sampler2D shadowMap, vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { +#if defined(CLUSTER_SHADOW_TYPE_PCF5) - float shadowTextureResolution = shadowParams.x; - vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); +float getShadowOmniClusteredPCF5(SHADOWMAP_ACCEPT(shadowMap), vec4 shadowParams, vec3 omniAtlasViewport, float shadowEdgePixels, vec3 lightDir) { - // pcf3 - float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; - vec3 shadowCoord = vec3(uv, shadowZ); - return getShadowPCF3x3(shadowMap, shadowCoord, shadowParams); - } + float shadowTextureResolution = shadowParams.x; + vec2 uv = getCubemapAtlasCoordinates(omniAtlasViewport, shadowEdgePixels, shadowTextureResolution, lightDir); - #endif + float shadowZ = length(lightDir) * shadowParams.w + shadowParams.z; + vec3 shadowCoord = vec3(uv, shadowZ); + return getShadowPCF5x5(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); +} #endif - // Clustered Spot Sampling using atlas -#ifdef GL2 - - #if defined(CLUSTER_SHADOW_TYPE_PCF1) - - float getShadowSpotClusteredPCF1(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shadowParams) { - return textureShadow(shadowMap, shadowCoord); - } - - #endif - - #if defined(CLUSTER_SHADOW_TYPE_PCF3) - - float getShadowSpotClusteredPCF3(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shadowParams) { - return getShadowSpotPCF3x3(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); - } - - #endif - - #if defined(CLUSTER_SHADOW_TYPE_PCF5) - - float getShadowSpotClusteredPCF5(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shadowParams) { - return getShadowPCF5x5(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); - } - #endif - -#else +#if defined(CLUSTER_SHADOW_TYPE_PCF1) - #if defined(CLUSTER_SHADOW_TYPE_PCF1) - - float getShadowSpotClusteredPCF1(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - - float depth = unpackFloat(textureShadow(shadowMap, shadowCoord.xy)); - - return depth > shadowCoord.z ? 1.0 : 0.0; - - } - - #endif - - #if defined(CLUSTER_SHADOW_TYPE_PCF3) +float getShadowSpotClusteredPCF1(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shadowParams) { + return textureShadow(shadowMap, shadowCoord); +} - float getShadowSpotClusteredPCF3(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - return getShadowSpotPCF3x3(shadowMap, shadowCoord, shadowParams); - } +#endif - #endif +#if defined(CLUSTER_SHADOW_TYPE_PCF3) - #if defined(CLUSTER_SHADOW_TYPE_PCF5) +float getShadowSpotClusteredPCF3(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shadowParams) { + return getShadowSpotPCF3x3(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); +} - // we don't have PCF5 implementation for webgl1, use PCF3 - float getShadowSpotClusteredPCF5(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - return getShadowSpotPCF3x3(shadowMap, shadowCoord, shadowParams); - } +#endif - #endif +#if defined(CLUSTER_SHADOW_TYPE_PCF5) +float getShadowSpotClusteredPCF5(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 shadowParams) { + return getShadowPCF5x5(SHADOWMAP_PASS(shadowMap), shadowCoord, shadowParams); +} #endif `; diff --git a/src/scene/shader-lib/chunks/lit/frag/shadowCascades.js b/src/scene/shader-lib/chunks/lit/frag/shadowCascades.js index 120e6c7b86d..37be385e21e 100644 --- a/src/scene/shader-lib/chunks/lit/frag/shadowCascades.js +++ b/src/scene/shader-lib/chunks/lit/frag/shadowCascades.js @@ -23,23 +23,7 @@ void getShadowCascadeMatrix(mat4 shadowMatrixPalette[4], float shadowCascadeDist cascadeIndex = min(cascadeIndex, shadowCascadeCount - 1.0); // pick shadow matrix - #ifdef GL2 - cascadeShadowMat = shadowMatrixPalette[int(cascadeIndex)]; - #else - // webgl 1 does not allow non-cost index array lookup - if (cascadeIndex == 0.0) { - cascadeShadowMat = shadowMatrixPalette[0]; - } - else if (cascadeIndex == 1.0) { - cascadeShadowMat = shadowMatrixPalette[1]; - } - else if (cascadeIndex == 2.0) { - cascadeShadowMat = shadowMatrixPalette[2]; - } - else { - cascadeShadowMat = shadowMatrixPalette[3]; - } - #endif + cascadeShadowMat = shadowMatrixPalette[int(cascadeIndex)]; } void fadeShadow(float shadowCascadeDistances[4]) { diff --git a/src/scene/shader-lib/chunks/lit/frag/shadowPCSS.js b/src/scene/shader-lib/chunks/lit/frag/shadowPCSS.js index 7aecdd740cd..b281ea99658 100644 --- a/src/scene/shader-lib/chunks/lit/frag/shadowPCSS.js +++ b/src/scene/shader-lib/chunks/lit/frag/shadowPCSS.js @@ -7,7 +7,6 @@ export default /* glsl */` * - https://github.com/pboechat/PCSS */ - #define PCSS_SAMPLE_COUNT 16 uniform float pcssDiskSamples[PCSS_SAMPLE_COUNT]; uniform float pcssSphereSamples[PCSS_SAMPLE_COUNT]; @@ -34,14 +33,6 @@ float noise(vec2 screenPos) { return fract(sin(dot(screenPos * PHI, screenPos)) * screenPos.x); } -#ifndef UNPACKFLOAT -#define UNPACKFLOAT -float unpackFloat(vec4 rgbaDepth) { - const vec4 bitShift = vec4(1.0 / (256.0 * 256.0 * 256.0), 1.0 / (256.0 * 256.0), 1.0 / 256.0, 1.0); - return dot(rgbaDepth, bitShift); -} -#endif - float viewSpaceDepth(float depth, mat4 invProjection) { float z = depth * 2.0 - 1.0; vec4 clipSpace = vec4(0.0, 0.0, z, 1.0); @@ -57,11 +48,7 @@ float PCSSBlockerDistance(TEXTURE_ACCEPT(shadowMap), vec2 sampleCoords[PCSS_SAMP vec2 offset = sampleCoords[i] * searchSize; vec2 sampleUV = shadowCoords + offset; - #ifdef GL2 float blocker = textureLod(shadowMap, sampleUV, 0.0).r; - #else // GL1 - float blocker = unpackFloat(texture2D(shadowMap, sampleUV)); - #endif float isBlocking = step(blocker, z); blockers += isBlocking; averageBlocker += blocker * isBlocking; @@ -100,11 +87,7 @@ float PCSS(TEXTURE_ACCEPT(shadowMap), vec3 shadowCoords, vec4 cameraParams, vec2 vec2 sampleUV = samplePoints[i] * filterRadius; sampleUV = shadowCoords.xy + sampleUV; - #ifdef GL2 float depth = textureLod(shadowMap, sampleUV, 0.0).r; - #else // GL1 - float depth = unpackFloat(texture2D(shadowMap, sampleUV)); - #endif shadow += step(receiverDepth, depth); } return shadow / float(PCSS_SAMPLE_COUNT); @@ -118,11 +101,7 @@ float PCSSCubeBlockerDistance(samplerCube shadowMap, vec3 lightDirNorm, vec3 sam vec3 sampleDir = lightDirNorm + samplePoints[i] * shadowSearchArea; sampleDir = normalize(sampleDir); - #ifdef GL2 float blocker = textureCubeLodEXT(shadowMap, sampleDir, 0.0).r; - #else // GL1 - float blocker = unpackFloat(textureCube(shadowMap, sampleDir)); - #endif float isBlocking = step(blocker, z); blockers += isBlocking; averageBlocker += blocker * isBlocking; @@ -159,11 +138,7 @@ float PCSSCube(samplerCube shadowMap, vec4 shadowParams, vec3 shadowCoords, vec4 vec3 sampleDir = lightDirNorm + offset; sampleDir = normalize(sampleDir); - #ifdef GL2 - float depth = textureCubeLodEXT(shadowMap, sampleDir, 0.0).r; - #else // GL1 - float depth = unpackFloat(textureCube(shadowMap, sampleDir)); - #endif + float depth = textureCubeLodEXT(shadowMap, sampleDir, 0.0).r; shadow += step(receiverDepth, depth); } return shadow / float(PCSS_SAMPLE_COUNT); diff --git a/src/scene/shader-lib/chunks/lit/frag/shadowStandard.js b/src/scene/shader-lib/chunks/lit/frag/shadowStandard.js index ed41f487a48..e7697ff212a 100644 --- a/src/scene/shader-lib/chunks/lit/frag/shadowStandard.js +++ b/src/scene/shader-lib/chunks/lit/frag/shadowStandard.js @@ -13,8 +13,6 @@ vec3 lessThan2(vec3 a, vec3 b) { // ----- Direct/Spot Sampling ----- -#ifdef GL2 - float _getShadowPCF3x3(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec3 shadowParams) { float z = shadowCoord.z; vec2 uv = shadowCoord.xy * shadowParams.x; // 1 unit - 1 texel @@ -70,71 +68,6 @@ float getShadowSpotPCF1x1(SHADOWMAP_ACCEPT(shadowMap), vec3 shadowCoord, vec4 sh return textureShadow(shadowMap, shadowCoord); } -#else // GL1 - -float _xgetShadowPCF3x3(mat3 depthKernel, vec3 shadowCoord, sampler2D shadowMap, vec3 shadowParams) { - mat3 shadowKernel; - vec3 shadowZ = vec3(shadowCoord.z); - shadowKernel[0] = vec3(greaterThan(depthKernel[0], shadowZ)); - shadowKernel[1] = vec3(greaterThan(depthKernel[1], shadowZ)); - shadowKernel[2] = vec3(greaterThan(depthKernel[2], shadowZ)); - - vec2 fractionalCoord = fract( shadowCoord.xy * shadowParams.x ); - - shadowKernel[0] = mix(shadowKernel[0], shadowKernel[1], fractionalCoord.x); - shadowKernel[1] = mix(shadowKernel[1], shadowKernel[2], fractionalCoord.x); - - vec4 shadowValues; - shadowValues.x = mix(shadowKernel[0][0], shadowKernel[0][1], fractionalCoord.y); - shadowValues.y = mix(shadowKernel[0][1], shadowKernel[0][2], fractionalCoord.y); - shadowValues.z = mix(shadowKernel[1][0], shadowKernel[1][1], fractionalCoord.y); - shadowValues.w = mix(shadowKernel[1][1], shadowKernel[1][2], fractionalCoord.y); - - return dot( shadowValues, vec4( 1.0 ) ) * 0.25; -} - -float _getShadowPCF3x3(sampler2D shadowMap, vec3 shadowCoord, vec3 shadowParams) { - float xoffset = 1.0 / shadowParams.x; // 1/shadow map width - float dx0 = -xoffset; - float dx1 = xoffset; - - mat3 depthKernel; - depthKernel[0][0] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(dx0, dx0))); - depthKernel[0][1] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(dx0, 0.0))); - depthKernel[0][2] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(dx0, dx1))); - depthKernel[1][0] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(0.0, dx0))); - depthKernel[1][1] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy)); - depthKernel[1][2] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(0.0, dx1))); - depthKernel[2][0] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(dx1, dx0))); - depthKernel[2][1] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(dx1, 0.0))); - depthKernel[2][2] = unpackFloat(textureShadow(shadowMap, shadowCoord.xy + vec2(dx1, dx1))); - - return _xgetShadowPCF3x3(depthKernel, shadowCoord, shadowMap, shadowParams); -} - -float getShadowPCF3x3(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - return _getShadowPCF3x3(shadowMap, shadowCoord, shadowParams.xyz); -} - -float getShadowSpotPCF3x3(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - return _getShadowPCF3x3(shadowMap, shadowCoord, shadowParams.xyz); -} - -float _getShadowPCF1x1(sampler2D shadowMap, vec3 shadowCoord) { - float shadowSample = unpackFloat(textureShadow(shadowMap, shadowCoord.xy)); - return shadowSample > shadowCoord.z ? 1.0 : 0.0; -} - -float getShadowPCF1x1(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - return _getShadowPCF1x1(shadowMap, shadowCoord); -} - -float getShadowSpotPCF1x1(sampler2D shadowMap, vec3 shadowCoord, vec4 shadowParams) { - return _getShadowPCF1x1(shadowMap, shadowCoord); -} -#endif - - // ----- Omni Sampling ----- #ifndef WEBGPU