@@ -13,7 +13,7 @@ import { positionLocal, positionView } from '../../nodes/accessors/Position.js';
13
13
import { skinning } from '../../nodes/accessors/SkinningNode.js' ;
14
14
import { morphReference } from '../../nodes/accessors/MorphNode.js' ;
15
15
import { mix } from '../../nodes/math/MathNode.js' ;
16
- import { float , vec3 , vec4 } from '../../nodes/tsl/TSLBase.js' ;
16
+ import { float , vec3 , vec4 , bool } from '../../nodes/tsl/TSLBase.js' ;
17
17
import AONode from '../../nodes/lighting/AONode.js' ;
18
18
import { lightingContext } from '../../nodes/lighting/LightingContextNode.js' ;
19
19
import IrradianceNode from '../../nodes/lighting/IrradianceNode.js' ;
@@ -229,6 +229,15 @@ class NodeMaterial extends Material {
229
229
*/
230
230
this . alphaTestNode = null ;
231
231
232
+
233
+ /**
234
+ * Discards the fragment if the mask value is `false`.
235
+ *
236
+ * @type {?Node<bool> }
237
+ * @default null
238
+ */
239
+ this . maskNode = null ;
240
+
232
241
/**
233
242
* The local vertex positions are computed based on multiple factors like the
234
243
* attribute data, morphing or skinning. This node property allows to overwrite
@@ -774,6 +783,14 @@ class NodeMaterial extends Material {
774
783
775
784
let colorNode = this . colorNode ? vec4 ( this . colorNode ) : materialColor ;
776
785
786
+ // MASK
787
+
788
+ if ( this . maskNode !== null ) {
789
+
790
+ bool ( this . maskNode ) . discard ( ) ;
791
+
792
+ }
793
+
777
794
// VERTEX COLORS
778
795
779
796
if ( this . vertexColors === true && geometry . hasAttribute ( 'color' ) ) {
@@ -782,7 +799,7 @@ class NodeMaterial extends Material {
782
799
783
800
}
784
801
785
- // Instanced colors
802
+ // INSTANCED COLORS
786
803
787
804
if ( object . instanceColor ) {
788
805
@@ -800,7 +817,6 @@ class NodeMaterial extends Material {
800
817
801
818
}
802
819
803
-
804
820
// COLOR
805
821
806
822
diffuseColor . assign ( colorNode ) ;
@@ -812,14 +828,20 @@ class NodeMaterial extends Material {
812
828
813
829
// ALPHA TEST
814
830
831
+ let alphaTestNode ;
832
+
815
833
if ( this . alphaTestNode !== null || this . alphaTest > 0 ) {
816
834
817
- const alphaTestNode = this . alphaTestNode !== null ? float ( this . alphaTestNode ) : materialAlphaTest ;
835
+ alphaTestNode = this . alphaTestNode !== null ? float ( this . alphaTestNode ) : materialAlphaTest ;
836
+
837
+ } else {
818
838
819
- diffuseColor . a . lessThanEqual ( alphaTestNode ) . discard ( ) ;
839
+ alphaTestNode = float ( 0 ) ;
820
840
821
841
}
822
842
843
+ diffuseColor . a . lessThanEqual ( alphaTestNode ) . discard ( ) ;
844
+
823
845
// ALPHA HASH
824
846
825
847
if ( this . alphaHash === true ) {
@@ -1189,6 +1211,7 @@ class NodeMaterial extends Material {
1189
1211
this . backdropNode = source . backdropNode ;
1190
1212
this . backdropAlphaNode = source . backdropAlphaNode ;
1191
1213
this . alphaTestNode = source . alphaTestNode ;
1214
+ this . maskNode = source . maskNode ;
1192
1215
1193
1216
this . positionNode = source . positionNode ;
1194
1217
this . geometryNode = source . geometryNode ;
0 commit comments