浏览代码

BasicNodeMaterial: Add mask property

Signed-off-by: martinRenou <[email protected]>
martinRenou 5 年之前
父节点
当前提交
b10d36046f

+ 1 - 0
examples/jsm/nodes/materials/BasicNodeMaterial.d.ts

@@ -7,6 +7,7 @@ export class BasicNodeMaterial extends NodeMaterial {
 
 	color: Node;
 	alpha: Node;
+	mask: Node;
 	position: Node;
 
 }

+ 1 - 0
examples/jsm/nodes/materials/nodes/BasicNode.d.ts

@@ -8,6 +8,7 @@ export class BasicNode extends Node {
 	position: Node;
 	color: Node;
 	alpha: Node;
+	mask: Node;
 	nodeType: string;
 
 	build( builder: NodeBuilder ): string;

+ 21 - 6
examples/jsm/nodes/materials/nodes/BasicNode.js

@@ -34,12 +34,12 @@ BasicNode.prototype.generate = function ( builder ) {
 
 			output.push(
 				position.code,
-				position.result ? "gl_Position = " + position.result + ";" : ''
+				position.result ? "gl_Position = projectionMatrix * modelViewMatrix * vec4(" + position.result + ", 1.0);" : ''
 			);
 
 		} else {
 
-			output.push( "gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.0)" );
+			output.push( "gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1.0);" );
 
 		}
 
@@ -51,10 +51,12 @@ BasicNode.prototype.generate = function ( builder ) {
 		this.color.analyze( builder, { slot: 'color' } );
 
 		if ( this.alpha ) this.alpha.analyze( builder );
+		if ( this.mask ) this.mask.analyze( builder );
 
 		// Build code
 		var color = this.color.flow( builder, 'c', { slot: 'color' } );
 		var alpha = this.alpha ? this.alpha.flow( builder, 'f' ) : undefined;
+		var mask = this.mask ? this.mask.flow( builder, 'b' ) : undefined;
 
 		builder.requires.transparent = alpha !== undefined;
 
@@ -62,6 +64,15 @@ BasicNode.prototype.generate = function ( builder ) {
 			color.code,
 		];
 
+		if ( mask ) {
+
+			output.push(
+				mask.code,
+				'if ( ! ' + mask.result + ' ) discard;'
+			);
+
+		}
+
 		if ( alpha ) {
 
 			output.push(
@@ -97,9 +108,11 @@ BasicNode.prototype.copy = function ( source ) {
 
 	Node.prototype.copy.call( this, source );
 
-	this.position = source.position;
 	this.color = source.color;
-	this.alpha = source.alpha;
+
+	if ( source.position ) this.position = source.position;
+	if ( source.alpha ) this.alpha = source.alpha;
+	if ( source.mask ) this.mask = source.mask;
 
 	return this;
 
@@ -113,9 +126,11 @@ BasicNode.prototype.toJSON = function ( meta ) {
 
 		data = this.createJSONNode( meta );
 
-		data.position = this.position.toJSON( meta ).uuid;
 		data.color = this.color.toJSON( meta ).uuid;
-		data.alpha = this.alpha.toJSON( meta ).uuid;
+
+		if ( this.position ) data.position = this.position.toJSON( meta ).uuid;
+		if ( this.alpha ) data.alpha = this.alpha.toJSON( meta ).uuid;
+		if ( this.mask ) data.mask = this.mask.toJSON( meta ).uuid;
 
 	}