Skip to content

Commit

Permalink
Merge pull request #15342 from sebavan/work1
Browse files Browse the repository at this point in the history
Support getAlphaFromRGB in transparent shadow maps
  • Loading branch information
sebavan authored Jul 30, 2024
2 parents 0ead0bf + b1f0a55 commit 3613144
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/dev/core/src/Lights/Shadows/shadowGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#if SM_SOFTTRANSPARENTSHADOW == 1
#include<bayerDitherFunctions>

uniform float softTransparentShadowSM;
uniform vec2 softTransparentShadowSM;
#endif

varying float vDepthMetricSM;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
16 changes: 13 additions & 3 deletions packages/dev/core/src/Shaders/shadowMap.fragment.fx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ void main(void)
#include<clipPlaneFragment>

#ifdef ALPHATEXTURE
float alphaFromAlphaTexture = texture2D(diffuseSampler, vUV).a;
vec4 opacityMap = texture2D(diffuseSampler, vUV);

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)
discard;
Expand All @@ -24,9 +34,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

Expand Down

0 comments on commit 3613144

Please sign in to comment.