@@ -12,7 +12,7 @@ export function wrapOverlaysMaterial( material, previousOnBeforeCompile ) {
1212
1313 const params = {
1414 layerMaps : { value : [ ] } ,
15- layerColor : { value : [ ] } ,
15+ layerInfo : { value : [ ] } ,
1616 } ;
1717
1818 material [ OVERLAY_PARAMS ] = params ;
@@ -74,13 +74,16 @@ export function wrapOverlaysMaterial( material, previousOnBeforeCompile ) {
7474 . replace ( / v o i d m a i n \( / , value => /* glsl */ `
7575
7676 #if LAYER_COUNT != 0
77- struct LayerTint {
77+ struct LayerInfo {
7878 vec3 color;
7979 float opacity;
80+
81+ int alphaMask;
82+ int alphaInvert;
8083 };
8184
8285 uniform sampler2D layerMaps[ LAYER_COUNT ];
83- uniform LayerTint layerColor [ LAYER_COUNT ];
86+ uniform LayerInfo layerInfo [ LAYER_COUNT ];
8487 #endif
8588
8689 #pragma unroll_loop_start
@@ -126,11 +129,27 @@ export function wrapOverlaysMaterial( material, previousOnBeforeCompile ) {
126129 smoothstep( 1.0 + wDelta, 1.0, layerUV.z );
127130
128131 // apply tint & opacity
129- tint.rgb *= layerColor[ i ].color;
130- tint.rgba *= layerColor[ i ].opacity * wOpacity;
132+ tint.rgb *= layerInfo[ i ].color;
133+ tint.rgba *= layerInfo[ i ].opacity * wOpacity;
134+
135+ // invert the alpha
136+ if ( layerInfo[ i ].alphaInvert > 0 ) {
137+
138+ tint.a = 1.0 - tint.a;
139+
140+ }
141+
142+ // apply the alpha across all existing layers if alpha mask is true
143+ if ( layerInfo[ i ].alphaMask > 0 ) {
144+
145+ diffuseColor.a *= tint.a;
146+
147+ } else {
148+
149+ // premultiplied alpha equation
150+ diffuseColor = tint + diffuseColor * ( 1.0 - tint.a );
131151
132- // premultiplied alpha equation
133- diffuseColor = tint + diffuseColor * ( 1.0 - tint.a );
152+ }
134153
135154 #endif
136155
0 commit comments