From c8690240d4769496721bf6d8a65ef5e6b93043f6 Mon Sep 17 00:00:00 2001 From: Martin Valigursky <59932779+mvaligursky@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:33:59 +0000 Subject: [PATCH] [BREAKING] Removed support for VSM8 shadow type (#7146) * [BREAKING] Removed support for VSM8 shadow type * lint * cleanup --------- Co-authored-by: Martin Valigursky --- .../graphics/shadow-cascades.controls.mjs | 1 - src/framework/components/light/component.js | 1 - src/platform/graphics/constants.js | 1 + src/scene/constants.js | 17 ++-------- src/scene/light.js | 6 ++-- src/scene/renderer/shadow-renderer.js | 32 +++++++------------ .../shader-lib/chunks/chunk-validation.js | 6 ++-- src/scene/shader-lib/chunks/chunks.js | 2 -- .../shader-lib/chunks/lit/frag/blurVSM.js | 21 ------------ .../shader-lib/chunks/lit/frag/shadowVSM8.js | 26 --------------- src/scene/shader-lib/programs/lit-shader.js | 27 +++------------- 11 files changed, 27 insertions(+), 113 deletions(-) delete mode 100644 src/scene/shader-lib/chunks/lit/frag/shadowVSM8.js diff --git a/examples/src/examples/graphics/shadow-cascades.controls.mjs b/examples/src/examples/graphics/shadow-cascades.controls.mjs index 861e3a08342..19e048301e1 100644 --- a/examples/src/examples/graphics/shadow-cascades.controls.mjs +++ b/examples/src/examples/graphics/shadow-cascades.controls.mjs @@ -24,7 +24,6 @@ export const controls = ({ observer, ReactPCUI, React, jsx, fragment }) => { { v: pc.SHADOW_PCF1_16F, t: 'PCF1_16F' }, { v: pc.SHADOW_PCF3_16F, t: 'PCF3_16F' }, { v: pc.SHADOW_PCF5_16F, t: 'PCF5_16F' }, - { v: pc.SHADOW_VSM8, t: 'VSM8' }, { v: pc.SHADOW_VSM_16F, t: 'VSM_16F' }, { v: pc.SHADOW_VSM_32F, t: 'VSM_32F' } ] diff --git a/src/framework/components/light/component.js b/src/framework/components/light/component.js index 5fe05972866..e771499ce68 100644 --- a/src/framework/components/light/component.js +++ b/src/framework/components/light/component.js @@ -553,7 +553,6 @@ class LightComponent extends Component { * - {@link SHADOW_PCF1_16F} * - {@link SHADOW_PCF3_16F} * - {@link SHADOW_PCF5_16F} - * - {@link SHADOW_VSM8} * - {@link SHADOW_VSM_16F} * - {@link SHADOW_VSM_32F} * - {@link SHADOW_PCSS_32F} diff --git a/src/platform/graphics/constants.js b/src/platform/graphics/constants.js index 5ad3432c578..7a52d8a1627 100644 --- a/src/platform/graphics/constants.js +++ b/src/platform/graphics/constants.js @@ -2372,3 +2372,4 @@ export const CHUNKAPI_1_62 = '1.62'; export const CHUNKAPI_1_65 = '1.65'; export const CHUNKAPI_1_70 = '1.70'; export const CHUNKAPI_2_1 = '2.1'; +export const CHUNKAPI_2_3 = '2.3'; diff --git a/src/scene/constants.js b/src/scene/constants.js index c843388c9a7..917e5fad06e 100644 --- a/src/scene/constants.js +++ b/src/scene/constants.js @@ -1,4 +1,4 @@ -import { PIXELFORMAT_DEPTH, PIXELFORMAT_DEPTH16, PIXELFORMAT_R32F, PIXELFORMAT_RGBA16F, PIXELFORMAT_RGBA32F, PIXELFORMAT_RGBA8 } from '../platform/graphics/constants.js'; +import { PIXELFORMAT_DEPTH, PIXELFORMAT_DEPTH16, PIXELFORMAT_R32F, PIXELFORMAT_RGBA16F, PIXELFORMAT_RGBA32F } from '../platform/graphics/constants.js'; /** * Subtract the color of the source fragment from the destination fragment and write the result to @@ -286,21 +286,11 @@ export const SHADOW_PCF3_32F = 0; /** @deprecated */ export const SHADOW_PCF3 = 0; // alias for SHADOW_PCF3_32F for backwards compatibility -/** - * A shadow sampling technique using a 16-bit exponential variance shadow map packed into - * {@link PIXELFORMAT_RGBA8} that leverages variance to approximate shadow boundaries, enabling soft - * shadows. All shadow receivers must also cast shadows for this mode to work correctly. - * - * @type {number} - * @category Graphics - */ -export const SHADOW_VSM8 = 1; - /** * A shadow sampling technique using a 16-bit exponential variance shadow map that leverages * variance to approximate shadow boundaries, enabling soft shadows. Only supported when - * {@link GraphicsDevice#textureHalfFloatRenderable} is true. Falls back to {@link SHADOW_VSM8}, if not - * supported. + * {@link GraphicsDevice#textureHalfFloatRenderable} is true. Falls back to {@link SHADOW_PCF3_32F}, + * if not supported. * * @type {number} * @category Graphics @@ -397,7 +387,6 @@ export const shadowTypeInfo = new Map([ [SHADOW_PCF1_16F, { name: 'PCF1_16F', format: PIXELFORMAT_DEPTH16, pcf: true }], [SHADOW_PCF3_16F, { name: 'PCF3_16F', format: PIXELFORMAT_DEPTH16, pcf: true }], [SHADOW_PCF5_16F, { name: 'PCF5_16F', format: PIXELFORMAT_DEPTH16, pcf: true }], - [SHADOW_VSM8, { name: 'VSM8', format: PIXELFORMAT_RGBA8, vsm: true }], [SHADOW_VSM_16F, { name: 'VSM_16F', format: PIXELFORMAT_RGBA16F, vsm: true }], [SHADOW_VSM_32F, { name: 'VSM_32F', format: PIXELFORMAT_RGBA32F, vsm: true }], [SHADOW_PCSS_32F, { name: 'PCSS_32F', format: PIXELFORMAT_R32F }] diff --git a/src/scene/light.js b/src/scene/light.js index cd435ae44f4..e3c91e2e361 100644 --- a/src/scene/light.js +++ b/src/scene/light.js @@ -8,7 +8,7 @@ import { BLUR_GAUSSIAN, LIGHTTYPE_DIRECTIONAL, LIGHTTYPE_OMNI, LIGHTTYPE_SPOT, MASK_BAKE, MASK_AFFECT_DYNAMIC, - SHADOW_PCF1_32F, SHADOW_PCF3_32F, SHADOW_VSM8, SHADOW_VSM_16F, SHADOW_VSM_32F, SHADOW_PCSS_32F, + SHADOW_PCF1_32F, SHADOW_PCF3_32F, SHADOW_VSM_16F, SHADOW_VSM_32F, SHADOW_PCSS_32F, SHADOWUPDATE_NONE, SHADOWUPDATE_REALTIME, SHADOWUPDATE_THISFRAME, LIGHTSHAPE_PUNCTUAL, LIGHTFALLOFF_LINEAR, shadowTypeInfo, @@ -398,9 +398,9 @@ class Light { value = SHADOW_VSM_16F; } - // fallback from vsm16 to vsm8 + // fallback from vsm16 to pcf3 if (value === SHADOW_VSM_16F && !device.textureHalfFloatRenderable) { - value = SHADOW_VSM8; + value = SHADOW_PCF3_32F; } const shadowInfo = shadowTypeInfo.get(value); diff --git a/src/scene/renderer/shadow-renderer.js b/src/scene/renderer/shadow-renderer.js index ef47b72a711..b61adea89d5 100644 --- a/src/scene/renderer/shadow-renderer.js +++ b/src/scene/renderer/shadow-renderer.js @@ -11,7 +11,6 @@ import { BLUR_GAUSSIAN, LIGHTTYPE_DIRECTIONAL, LIGHTTYPE_OMNI, SHADER_SHADOW, - SHADOW_VSM8, SHADOW_VSM_32F, SHADOWUPDATE_NONE, SHADOWUPDATE_THISFRAME, SORTKEY_DEPTH, shadowTypeInfo @@ -91,12 +90,9 @@ class ShadowRenderer { this.pixelOffsetId = scope.resolve('pixelOffset'); this.weightId = scope.resolve('weight[0]'); this.blurVsmShaderCode = [shaderChunks.blurVSMPS, `#define GAUSS\n${shaderChunks.blurVSMPS}`]; - const packed = '#define PACKED\n'; - this.blurPackedVsmShaderCode = [packed + this.blurVsmShaderCode[0], packed + this.blurVsmShaderCode[1]]; // cache for vsm blur shaders this.blurVsmShader = [{}, {}]; - this.blurPackedVsmShader = [{}, {}]; this.blurVsmWeights = {}; @@ -118,8 +114,13 @@ class ShadowRenderer { const shadowCam = LightCamera.create('ShadowCamera', type, face); + const shadowInfo = shadowTypeInfo.get(shadowType); + Debug.assert(shadowInfo); + const isVsm = shadowInfo?.vsm ?? false; + const isPcf = shadowInfo?.pcf ?? false; + // don't clear the color buffer if rendering a depth map - if (shadowType >= SHADOW_VSM8 && shadowType <= SHADOW_VSM_32F) { + if (isVsm) { shadowCam.clearColor = new Color(0, 0, 0, 0); } else { shadowCam.clearColor = new Color(1, 1, 1, 1); @@ -128,12 +129,8 @@ class ShadowRenderer { shadowCam.clearDepthBuffer = true; shadowCam.clearStencilBuffer = false; - const shadowInfo = shadowTypeInfo.get(shadowType); - Debug.assert(shadowInfo); - // clear color buffer only when using it - const hwPcf = shadowInfo?.pcf ?? false; - shadowCam.clearColorBuffer = !hwPcf; + shadowCam.clearColorBuffer = !isPcf; return shadowCam; } @@ -470,21 +467,17 @@ class ShadowRenderer { } } - getVsmBlurShader(isVsm8, blurMode, filterSize) { + getVsmBlurShader(blurMode, filterSize) { - const cache = isVsm8 ? this.blurPackedVsmShader : this.blurVsmShader; + const cache = this.blurVsmShader; let blurShader = cache[blurMode][filterSize]; if (!blurShader) { this.blurVsmWeights[filterSize] = gaussWeights(filterSize); const blurVS = shaderChunks.fullscreenQuadVS; let blurFS = `#define SAMPLES ${filterSize}\n`; - if (isVsm8) { - blurFS += this.blurPackedVsmShaderCode[blurMode]; - } else { - blurFS += this.blurVsmShaderCode[blurMode]; - } - const blurShaderName = `blurVsm${blurMode}${filterSize}${isVsm8}`; + blurFS += this.blurVsmShaderCode[blurMode]; + const blurShaderName = `blurVsm${blurMode}${filterSize}`; blurShader = createShaderFromCode(this.device, blurVS, blurFS, blurShaderName); cache[blurMode][filterSize] = blurShader; } @@ -511,10 +504,9 @@ class ShadowRenderer { const tempShadowMap = this.renderer.shadowMapCache.get(device, light); const tempRt = tempShadowMap.renderTargets[0]; - const isVsm8 = light._shadowType === SHADOW_VSM8; const blurMode = light.vsmBlurMode; const filterSize = light._vsmBlurSize; - const blurShader = this.getVsmBlurShader(isVsm8, blurMode, filterSize); + const blurShader = this.getVsmBlurShader(blurMode, filterSize); blurScissorRect.z = light._shadowResolution - 2; blurScissorRect.w = blurScissorRect.z; diff --git a/src/scene/shader-lib/chunks/chunk-validation.js b/src/scene/shader-lib/chunks/chunk-validation.js index ce3b349cbca..26e963cefb1 100644 --- a/src/scene/shader-lib/chunks/chunk-validation.js +++ b/src/scene/shader-lib/chunks/chunk-validation.js @@ -1,4 +1,4 @@ -import { CHUNKAPI_1_51, CHUNKAPI_1_55, CHUNKAPI_1_56, CHUNKAPI_1_57, CHUNKAPI_1_60, CHUNKAPI_1_62, CHUNKAPI_1_65, CHUNKAPI_1_70, CHUNKAPI_2_1 } from '../../../platform/graphics/constants.js'; +import { CHUNKAPI_1_51, CHUNKAPI_1_55, CHUNKAPI_1_56, CHUNKAPI_1_57, CHUNKAPI_1_60, CHUNKAPI_1_62, CHUNKAPI_1_65, CHUNKAPI_1_70, CHUNKAPI_2_1, CHUNKAPI_2_3 } from '../../../platform/graphics/constants.js'; import { Debug } from '../../../core/debug.js'; import { shaderChunks } from './chunks.js'; @@ -63,7 +63,6 @@ const chunkVersions = { shadowEVSMnPS: CHUNKAPI_1_62, shadowStandardPS: CHUNKAPI_1_62, shadowStandardGL2PS: CHUNKAPI_1_62, - shadowVSM8PS: CHUNKAPI_1_62, spotPS: CHUNKAPI_1_62, TBNPS: CHUNKAPI_1_62, TBNObjectSpacePS: CHUNKAPI_1_62, @@ -104,7 +103,8 @@ const removedChunks = { specularAaToksvigPS: CHUNKAPI_1_55, specularAaToksvigFastPS: CHUNKAPI_1_55, skyboxEnvPS: CHUNKAPI_2_1, - skyboxHDRPS: CHUNKAPI_2_1 + skyboxHDRPS: CHUNKAPI_2_1, + shadowVSM8PS: CHUNKAPI_2_3 }; // compare two "major.minor" semantic version strings and return true if a is a smaller version than b. diff --git a/src/scene/shader-lib/chunks/chunks.js b/src/scene/shader-lib/chunks/chunks.js index 4f5b50dbcb0..05d440c8c14 100644 --- a/src/scene/shader-lib/chunks/chunks.js +++ b/src/scene/shader-lib/chunks/chunks.js @@ -153,7 +153,6 @@ import shadowPCSSPS from './lit/frag/shadowPCSS.js'; import shadowSampleCoordPS from './lit/frag/shadowSampleCoord.js'; import shadowStandardPS from './lit/frag/shadowStandard.js'; import shadowStandardGL2PS from './lit/frag/shadowStandardGL2.js'; -import shadowVSM8PS from './lit/frag/shadowVSM8.js'; import shadowVSM_commonPS from './lit/frag/shadowVSM_common.js'; import skinBatchTexVS from './common/vert/skinBatchTex.js'; import skinTexVS from './common/vert/skinTex.js'; @@ -354,7 +353,6 @@ const shaderChunks = { shadowSampleCoordPS, shadowStandardPS, shadowStandardGL2PS, - shadowVSM8PS, shadowVSM_commonPS, skinBatchTexVS, skinTexVS, diff --git a/src/scene/shader-lib/chunks/lit/frag/blurVSM.js b/src/scene/shader-lib/chunks/lit/frag/blurVSM.js index f9fe2f71cd2..bef1395f302 100644 --- a/src/scene/shader-lib/chunks/lit/frag/blurVSM.js +++ b/src/scene/shader-lib/chunks/lit/frag/blurVSM.js @@ -8,29 +8,12 @@ uniform vec2 pixelOffset; uniform float weight[SAMPLES]; #endif -#ifdef PACKED -float decodeFloatRG(vec2 rg) { - return rg.y*(1.0/255.0) + rg.x; -} - -vec2 encodeFloatRG( float v ) { - vec2 enc = vec2(1.0, 255.0) * v; - enc = fract(enc); - enc -= enc.yy * vec2(1.0/255.0, 1.0/255.0); - return enc; -} -#endif - void main(void) { vec3 moments = vec3(0.0); vec2 uv = vUv0 - pixelOffset * (float(SAMPLES) * 0.5); for (int i=0; i