From db8a8f03bb2a6ad02af30ff97bc1b771e6950c0e Mon Sep 17 00:00:00 2001 From: sebavan Date: Fri, 26 Jul 2024 01:43:10 +0200 Subject: [PATCH 1/3] Fix Texture Decals shader recompilation --- packages/dev/core/src/Meshes/meshUVSpaceRenderer.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/dev/core/src/Meshes/meshUVSpaceRenderer.ts b/packages/dev/core/src/Meshes/meshUVSpaceRenderer.ts index 604db867bb6..ee36ac54298 100644 --- a/packages/dev/core/src/Meshes/meshUVSpaceRenderer.ts +++ b/packages/dev/core/src/Meshes/meshUVSpaceRenderer.ts @@ -166,6 +166,8 @@ export class MeshUVSpaceRenderer { uvEdgeBlending: false, ...options, }; + + this._createDiffuseRTT(); } /** From bf6a3206102151d84a60f899d8727021e45198e6 Mon Sep 17 00:00:00 2001 From: sebavan Date: Tue, 30 Jul 2024 01:44:41 +0200 Subject: [PATCH 2/3] Support getAlphaFromRGB in transparent shadow maps --- .../core/src/Lights/Shadows/shadowGenerator.ts | 2 +- .../shadowMapFragmentExtraDeclaration.fx | 2 +- .../shadowMapFragmentSoftTransparentShadow.fx | 2 +- .../dev/core/src/Shaders/shadowMap.fragment.fx | 15 ++++++++++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts b/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts index f620e6203c8..8b691c16fc6 100644 --- a/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts +++ b/packages/dev/core/src/Lights/Shadows/shadowGenerator.ts @@ -1244,7 +1244,7 @@ export class ShadowGenerator implements IShadowGenerator { } if (isTransparent && this.enableSoftTransparentShadow) { - effect.setFloat("softTransparentShadowSM", effectiveMesh.visibility * material.alpha); + effect.setFloat2("softTransparentShadowSM", effectiveMesh.visibility * material.alpha, this._opacityTexture?.getAlphaFromRGB ? 1 : 0); } if (shadowDepthWrapper) { diff --git a/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentExtraDeclaration.fx b/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentExtraDeclaration.fx index 726bf67250f..4720730320f 100644 --- a/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentExtraDeclaration.fx +++ b/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentExtraDeclaration.fx @@ -5,7 +5,7 @@ #if SM_SOFTTRANSPARENTSHADOW == 1 #include - uniform float softTransparentShadowSM; + uniform vec2 softTransparentShadowSM; #endif varying float vDepthMetricSM; diff --git a/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentSoftTransparentShadow.fx b/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentSoftTransparentShadow.fx index ed1f6bc4f12..56973bae6de 100644 --- a/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentSoftTransparentShadow.fx +++ b/packages/dev/core/src/Shaders/ShadersInclude/shadowMapFragmentSoftTransparentShadow.fx @@ -1,3 +1,3 @@ #if SM_SOFTTRANSPARENTSHADOW == 1 - if ((bayerDither8(floor(mod(gl_FragCoord.xy, 8.0)))) / 64.0 >= softTransparentShadowSM * alpha) discard; + if ((bayerDither8(floor(mod(gl_FragCoord.xy, 8.0)))) / 64.0 >= softTransparentShadowSM.x * alpha) discard; #endif diff --git a/packages/dev/core/src/Shaders/shadowMap.fragment.fx b/packages/dev/core/src/Shaders/shadowMap.fragment.fx index 2c6d2073e5c..bac9173016b 100644 --- a/packages/dev/core/src/Shaders/shadowMap.fragment.fx +++ b/packages/dev/core/src/Shaders/shadowMap.fragment.fx @@ -15,7 +15,16 @@ void main(void) #include #ifdef ALPHATEXTURE - float alphaFromAlphaTexture = texture2D(diffuseSampler, vUV).a; + vec4 opacityMap = texture2D(diffuseSampler, vUV); + + float alphaFromAlphaTexture = 1.; + if (softTransparentShadowSM.y == 1.0) { + opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11); + alphaFromAlphaTexture = opacityMap.x + opacityMap.y + opacityMap.z; + } else { + alphaFromAlphaTexture = opacityMap.a; + } + #ifdef ALPHATESTVALUE if (alphaFromAlphaTexture < ALPHATESTVALUE) discard; @@ -24,9 +33,9 @@ void main(void) #if SM_SOFTTRANSPARENTSHADOW == 1 #ifdef ALPHATEXTURE - if ((bayerDither8(floor(mod(gl_FragCoord.xy, 8.0)))) / 64.0 >= softTransparentShadowSM * alphaFromAlphaTexture) discard; + if ((bayerDither8(floor(mod(gl_FragCoord.xy, 8.0)))) / 64.0 >= softTransparentShadowSM.x * alphaFromAlphaTexture) discard; #else - if ((bayerDither8(floor(mod(gl_FragCoord.xy, 8.0)))) / 64.0 >= softTransparentShadowSM) discard; + if ((bayerDither8(floor(mod(gl_FragCoord.xy, 8.0)))) / 64.0 >= softTransparentShadowSM.x) discard; #endif #endif From b1f0a55b1d4bfcef6465857cad8e4e131232bb2d Mon Sep 17 00:00:00 2001 From: sebavan Date: Tue, 30 Jul 2024 14:23:19 +0200 Subject: [PATCH 3/3] fix --- .../dev/core/src/Shaders/shadowMap.fragment.fx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/dev/core/src/Shaders/shadowMap.fragment.fx b/packages/dev/core/src/Shaders/shadowMap.fragment.fx index bac9173016b..eb478178ae3 100644 --- a/packages/dev/core/src/Shaders/shadowMap.fragment.fx +++ b/packages/dev/core/src/Shaders/shadowMap.fragment.fx @@ -17,13 +17,14 @@ void main(void) #ifdef ALPHATEXTURE vec4 opacityMap = texture2D(diffuseSampler, vUV); - float alphaFromAlphaTexture = 1.; - if (softTransparentShadowSM.y == 1.0) { - opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11); - alphaFromAlphaTexture = opacityMap.x + opacityMap.y + opacityMap.z; - } else { - alphaFromAlphaTexture = opacityMap.a; - } + float alphaFromAlphaTexture = opacityMap.a; + + #if SM_SOFTTRANSPARENTSHADOW == 1 + if (softTransparentShadowSM.y == 1.0) { + opacityMap.rgb = opacityMap.rgb * vec3(0.3, 0.59, 0.11); + alphaFromAlphaTexture = opacityMap.x + opacityMap.y + opacityMap.z; + } + #endif #ifdef ALPHATESTVALUE if (alphaFromAlphaTexture < ALPHATESTVALUE)