sunag 4 anos atrás
pai
commit
5a57795b67

+ 43 - 30
examples/jsm/renderers/nodes/accessors/CameraNode.js

@@ -16,40 +16,43 @@ class CameraNode extends Node {
 		this.updateType = NodeUpdateType.Frame;
 
 		this.scope = scope;
-		
-		this.inputNode = null;
+
+		this._inputNode = null;
 
 	}
 
 	getType() {
 
-		if ( this.scope === CameraNode.PROJECTION || this.scope === CameraNode.VIEW ) {
-			
+		const scope = this.scope;
+
+		if ( scope === CameraNode.PROJECTION || scope === CameraNode.VIEW ) {
+
 			return 'mat4';
-			
+
 		}
 
 		return 'vec3';
 
 	}
-	
+
 	update( frame ) {
 
 		const camera = frame.camera;
-		const inputNode = this.inputNode;
+		const inputNode = this._inputNode;
+		const scope = this.scope;
+
+		if ( scope === CameraNode.PROJECTION ) {
 
-		if ( this.scope === CameraNode.PROJECTION ) {
-			
 			inputNode.value = camera.projectionMatrix;
-			
-		} else if ( this.scope === CameraNode.VIEW ) {
-			
+
+		} else if ( scope === CameraNode.VIEW ) {
+
 			inputNode.value = camera.matrixWorldInverse;
-			
-		} else if ( this.scope === CameraNode.POSITION ) {
-			
+
+		} else if ( scope === CameraNode.POSITION ) {
+
 			camera.getWorldPosition( inputNode.value );
-			
+
 		}
 
 	}
@@ -58,23 +61,33 @@ class CameraNode extends Node {
 
 		const nodeData = builder.getDataFromNode( this );
 
-		if ( this.initialized !== true ) {
-			
-			if ( this.scope === CameraNode.PROJECTION || this.scope === CameraNode.VIEW ) {
-				
-				this.inputNode = new Matrix4Node( null );
-				
-			} else {
-				
-				this.inputNode = new Vector3Node();
-				
+		let inputNode = this._inputNode;
+
+		if ( nodeData.inputNode === undefined ) {
+
+			const scope = this.scope;
+
+			if ( scope === CameraNode.PROJECTION || scope === CameraNode.VIEW ) {
+
+				if ( !inputNode || !inputNode.isMatrix4Node ) {
+
+					inputNode = new Matrix4Node( null );
+
+				}
+
+			} else if ( !inputNode || !inputNode.isVector3Node ) {
+
+				inputNode = new Vector3Node();
+
 			}
-			
-			nodeData.initialized = true;
-			
+
+			this._inputNode = inputNode;
+
+			nodeData.inputNode = inputNode;
+
 		}
 
-		return this.inputNode.build( builder, output );
+		return inputNode.build( builder, output );
 
 	}
 

+ 12 - 8
examples/jsm/renderers/nodes/accessors/ModelNode.js

@@ -15,14 +15,14 @@ class ModelNode extends Node {
 
 		this.updateType = NodeUpdateType.Object;
 
-		this.inputNode = null;
+		this._inputNode = null;
 
 	}
 
 	update( frame ) {
 
 		const object = frame.object;
-		const inputNode = this.inputNode;
+		const inputNode = this._inputNode;
 
 		inputNode.value = object.modelViewMatrix;
 
@@ -32,15 +32,19 @@ class ModelNode extends Node {
 
 		const nodeData = builder.getDataFromNode( this );
 
-		if ( this.initialized !== true ) {
-			
-			this.inputNode = new Matrix4Node( null );
+		let inputNode = this._inputNode;
+
+		if ( nodeData.inputNode === undefined ) {
+
+			inputNode = new Matrix4Node( null );
+
+			this._inputNode = inputNode;
+
+			nodeData.inputNode = inputNode;
 
-			nodeData.initialized = true;
-			
 		}
 
-		return this.inputNode.build( builder, output );
+		return inputNode.build( builder, output );
 
 	}
 

+ 2 - 2
examples/jsm/renderers/nodes/accessors/PositionNode.js

@@ -21,9 +21,9 @@ class PositionNode extends Node {
 		let positionNode = nodeData.positionNode;
 
 		if ( positionNode === undefined ) {
-			
+
 			positionNode = new AttributeNode( 'position', 'vec3' );
-			
+
 			nodeData.positionNode = positionNode;
 
 		}

+ 1 - 1
examples/jsm/renderers/nodes/accessors/WVPNode.js

@@ -8,7 +8,7 @@ class WVPNode extends Node {
 
 	constructor( position = new PositionNode() ) {
 
-		super('vec4');
+		super( 'vec4' );
 
 		this.position = position;
 

+ 14 - 14
examples/jsm/renderers/nodes/core/AttributeNode.js

@@ -32,27 +32,27 @@ class AttributeNode extends Node {
 		const attribute = builder.getAttribute( attributeName, attributeType );
 
 		if ( builder.isShaderStage( 'vertex' ) ) {
-		
-			return builder.format( attributeName, attributeType, output );
-			
+
+			return builder.format( attribute.name, attribute.type, output );
+
 		} else {
-			
+
 			const nodeData = builder.getDataFromNode( this, builder.shaderStage );
-			
+
 			let nodeVary = nodeData.varyNode;
-			
+
 			if ( nodeVary === undefined ) {
-				
-				nodeVary = builder.getVaryFromNode( this, attributeType, attributeName );
-				
+
+				nodeVary = builder.getVaryFromNode( this, attribute.type, attributeName );
+
 				nodeData.nodeVary = nodeVary;
-				
+
 			}
-			
+
 			const varyName = builder.getPropertyName( nodeVary );
-			
-			return builder.format( varyName, attributeType, output );
-			
+
+			return builder.format( varyName, attribute.type, output );
+
 		}
 
 	}

+ 41 - 41
examples/jsm/renderers/nodes/core/NodeBuilder.js

@@ -60,7 +60,7 @@ class NodeBuilder {
 
 	getTexture( /* textureProperty, uvSnippet */ ) {
 
-
+		console.warn( 'Abstract function.' );
 
 	}
 
@@ -83,13 +83,13 @@ class NodeBuilder {
 		// find attribute
 
 		for ( const attribute of attributes ) {
-			
+
 			if ( attribute.name === name ) {
-				
+
 				return attribute;
-				
+
 			}
-			
+
 		}
 
 		// create a new if no exist
@@ -109,23 +109,23 @@ class NodeBuilder {
 	}
 
 	isVector( type ) {
-		
+
 		return /vec\d/.test( type );
-		
+
 	}
 
 	isMatrix( type ) {
-		
+
 		return /mat\d/.test( type );
-		
+
 	}
-	
+
 	isShaderStage( shaderStage ) {
-		
+
 		return this.shaderStage === shaderStage;
-		
+
 	}
-	
+
 	getVectorType( type ) {
 
 		if ( type === 'color' ) return 'vec3';
@@ -199,7 +199,7 @@ class NodeBuilder {
 	}
 
 	getVaryFromNode( node, type, value ) {
-		
+
 		const nodeData = this.getDataFromNode( node );
 
 		let nodeVary = nodeData.vary;
@@ -218,7 +218,7 @@ class NodeBuilder {
 		}
 
 		return nodeVary;
-		
+
 	}
 
 	/*
@@ -255,31 +255,31 @@ class NodeBuilder {
 
 	getAttributesBodySnippet( /*shaderStage*/ ) {
 
-
+		console.warn( 'Abstract function.' );
 
 	}
 
 	getAttributesHeaderSnippet( /*shaderStage*/ ) {
 
-
+		console.warn( 'Abstract function.' );
 
 	}
-	
+
 	getVarysHeaderSnippet( /*shaderStage*/ ) {
-		
-		
-		
+
+		console.warn( 'Abstract function.' );
+
 	}
-	
+
 	getVarysBodySnippet( /*shaderStage*/ ) {
-		
-		
-		
+
+		console.warn( 'Abstract function.' );
+
 	}
 
-	getUniformsHeaderSnippet( shaderStage ) {
+	getUniformsHeaderSnippet( /*shaderStage*/ ) {
 
-		
+		console.warn( 'Abstract function.' );
 
 	}
 
@@ -317,7 +317,7 @@ class NodeBuilder {
 			this.define( shaderStage, 'NODE_HEADER_UNIFORMS', this.getUniformsHeaderSnippet( shaderStage ) );
 			this.define( shaderStage, 'NODE_HEADER_ATTRIBUTES', this.getAttributesHeaderSnippet( shaderStage ) );
 			this.define( shaderStage, 'NODE_HEADER_VARYS', this.getVarysHeaderSnippet( shaderStage ) );
-			
+
 			this.define( shaderStage, 'NODE_BODY_VARYS', this.getVarysBodySnippet( shaderStage ) );
 
 			shaderData[ shaderStage ] = this._buildDefines( shaderStage );
@@ -330,7 +330,7 @@ class NodeBuilder {
 		return this;
 
 	}
-	
+
 	format( snippet, fromType, toType ) {
 
 		fromType = this.getVectorType( fromType );
@@ -345,26 +345,26 @@ class NodeBuilder {
 			case 'float to vec4' : return `vec4( vec3( ${snippet} ), 1.0 )`;
 
 			case 'vec2 to float' : return `${snippet}.x`;
-			case 'vec2 to vec3'  : return `vec3( ${snippet}, 0.0 )`;
-			case 'vec2 to vec4'  : return `vec4( ${snippet}.xy, 0.0, 1.0 )`;
+			case 'vec2 to vec3' : return `vec3( ${snippet}, 0.0 )`;
+			case 'vec2 to vec4' : return `vec4( ${snippet}.xy, 0.0, 1.0 )`;
 
 			case 'vec3 to float' : return `${snippet}.x`;
-			case 'vec3 to vec2'  : return `${snippet}.xy`;
-			case 'vec3 to vec4'  : return `vec4( ${snippet}, 1.0 )`;
+			case 'vec3 to vec2' : return `${snippet}.xy`;
+			case 'vec3 to vec4' : return `vec4( ${snippet}, 1.0 )`;
 
 			case 'vec4 to float' : return `${snippet}.x`;
-			case 'vec4 to vec2'  : return `${snippet}.xy`;
-			case 'vec4 to vec3'  : return `${snippet}.xyz`;
+			case 'vec4 to vec2' : return `${snippet}.xy`;
+			case 'vec4 to vec3' : return `${snippet}.xyz`;
 
 			case 'mat3 to float' : return `( ${snippet} * vec3( 1.0 ) ).x`;
-			case 'mat3 to vec2'  : return `( ${snippet} * vec3( 1.0 ) ).xy`;
-			case 'mat3 to vec3'  : return `( ${snippet} * vec3( 1.0 ) ).xyz`;
-			case 'mat3 to vec4'  : return `vec4( ${snippet} * vec3( 1.0 ), 1.0 )`;
+			case 'mat3 to vec2' : return `( ${snippet} * vec3( 1.0 ) ).xy`;
+			case 'mat3 to vec3' : return `( ${snippet} * vec3( 1.0 ) ).xyz`;
+			case 'mat3 to vec4' : return `vec4( ${snippet} * vec3( 1.0 ), 1.0 )`;
 
 			case 'mat4 to float' : return `( ${snippet} * vec4( 1.0 ) ).x`;
-			case 'mat4 to vec2'  : return `( ${snippet} * vec4( 1.0 ) ).xy`;
-			case 'mat4 to vec3'  : return `( ${snippet} * vec4( 1.0 ) ).xyz`;
-			case 'mat4 to vec4'  : return `( ${snippet} * vec4( 1.0 ) )`;
+			case 'mat4 to vec2' : return `( ${snippet} * vec4( 1.0 ) ).xy`;
+			case 'mat4 to vec3' : return `( ${snippet} * vec4( 1.0 ) ).xyz`;
+			case 'mat4 to vec4' : return `( ${snippet} * vec4( 1.0 ) )`;
 
 		}
 

+ 3 - 3
examples/jsm/renderers/nodes/core/VaryNode.js

@@ -11,11 +11,11 @@ class VaryNode extends Node {
 	}
 
 	getType( builder ) {
-		
+
 		// VaryNode is auto type
-		
+
 		return this.value.getType( builder );
-		
+
 	}
 
 	generate( builder, output ) {

+ 1 - 1
examples/jsm/renderers/nodes/core/constants.js

@@ -2,7 +2,7 @@ export const NodeUpdateType = {
 	None: 'none',
 	Frame: 'frame',
 	Object: 'object'
-}
+};
 
 export const NodeType = {
 	Float: 'float',

+ 2 - 0
examples/jsm/renderers/nodes/inputs/ColorNode.js

@@ -8,6 +8,8 @@ class ColorNode extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isColorNode', { value: true } );
+
 	}
 
 }

+ 2 - 0
examples/jsm/renderers/nodes/inputs/FloatNode.js

@@ -8,6 +8,8 @@ class FloatNode extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isFloatNode', { value: true } );
+
 	}
 
 }

+ 2 - 0
examples/jsm/renderers/nodes/inputs/Matrix3Node.js

@@ -9,6 +9,8 @@ class Matrix3Node extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isMatrix3Node', { value: true } );
+
 	}
 
 }

+ 2 - 0
examples/jsm/renderers/nodes/inputs/Matrix4Node.js

@@ -9,6 +9,8 @@ class Matrix4Node extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isMatrix4Node', { value: true } );
+
 	}
 
 }

+ 2 - 0
examples/jsm/renderers/nodes/inputs/TextureNode.js

@@ -10,6 +10,8 @@ class TextureNode extends InputNode {
 		this.value = value;
 		this.uv = uv;
 
+		Object.defineProperty( this, 'isTextureNode', { value: true } );
+
 	}
 
 	generate( builder, output ) {

+ 2 - 0
examples/jsm/renderers/nodes/inputs/Vector2Node.js

@@ -8,6 +8,8 @@ class Vector2Node extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isVector2Node', { value: true } );
+
 	}
 
 }

+ 2 - 0
examples/jsm/renderers/nodes/inputs/Vector3Node.js

@@ -9,6 +9,8 @@ class Vector3Node extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isVector3Node', { value: true } );
+
 	}
 
 }

+ 2 - 0
examples/jsm/renderers/nodes/inputs/Vector4Node.js

@@ -9,6 +9,8 @@ class Vector4Node extends InputNode {
 
 		this.value = value;
 
+		Object.defineProperty( this, 'isVector4Node', { value: true } );
+
 	}
 
 }

+ 11 - 11
examples/jsm/renderers/nodes/math/OperatorNode.js

@@ -41,11 +41,11 @@ class OperatorNode extends Node {
 		return typeA;
 
 	}
-	
+
 	getVectorFromMatrix( type ) {
-		
+
 		return 'vec' + type.substr( 3 );
-		
+
 	}
 
 	generate( builder, output ) {
@@ -56,25 +56,25 @@ class OperatorNode extends Node {
 		let type = this.getType( builder );
 
 		if ( builder.isMatrix( typeA ) && builder.isVector( typeB ) ) {
-			
+
 			// matrix x vector
-			
+
 			type = typeB = this.getVectorFromMatrix( typeA );
 
 		} else if ( builder.isVector( typeA ) && builder.isMatrix( typeB ) ) {
-			
+
 			// vector x matrix
-			
+
 			type = typeB = this.getVectorFromMatrix( typeB );
 
 		} else {
-			
+
 			// anytype x anytype
-			
+
 			typeA = typeB = type;
-			
+
 		}
-		
+
 		const a = this.a.build( builder, typeA );
 		const b = this.b.build( builder, typeB );
 

+ 1 - 4
examples/jsm/renderers/webgpu/WebGPUBindings.js

@@ -1,6 +1,3 @@
-import WebGPUUniformsGroup from './WebGPUUniformsGroup.js';
-import { Matrix3Uniform, Matrix4Uniform } from './WebGPUUniform.js';
-
 class WebGPUBindings {
 
 	constructor( device, info, properties, textures, pipelines, computePipelines, attributes, nodes ) {
@@ -95,7 +92,7 @@ class WebGPUBindings {
 
 		for ( const binding of bindings ) {
 
-			const isShared = binding.isShared;;
+			const isShared = binding.isShared;
 			const isUpdated = updateMap.get( binding ) === frame;
 
 			if ( isShared && isUpdated ) continue;

+ 18 - 19
examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js

@@ -1,6 +1,6 @@
 import WebGPUNodeUniformsGroup from './WebGPUNodeUniformsGroup.js';
-import { 
-	FloatNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform, 
+import {
+	FloatNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
 	ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
 } from './WebGPUNodeUniform.js';
 import WebGPUSampler from '../WebGPUSampler.js';
@@ -75,7 +75,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 	getPropertyName( node ) {
 
-		if (node.isNodeUniform) {
+		if ( node.isNodeUniform ) {
 
 			const name = node.name;
 			const type = node.type;
@@ -89,9 +89,9 @@ class WebGPUNodeBuilder extends NodeBuilder {
 				return `nodeUniforms.${name}`;
 
 			}
-			
+
 		}
-		
+
 		return super.getPropertyName( node );
 
 	}
@@ -183,9 +183,9 @@ class WebGPUNodeBuilder extends NodeBuilder {
 			nodeData.uniformGPU = uniformGPU;
 
 			if ( shaderStage === 'vertex' ) {
-				
+
 				this.bindingsOffset[ 'fragment' ] = bindings.length;
-				
+
 			}
 
 		}
@@ -202,14 +202,14 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 			const attributes = this.attributes;
 
-			for ( let index = 0; index < attributes.length; index++ ) {
-				
+			for ( let index = 0; index < attributes.length; index ++ ) {
+
 				const attribute = attributes[ index ];
-				
+
 				snippet += `layout(location = ${index}) in ${attribute.type} ${attribute.name};`;
-			
+
 			}
-			
+
 		}
 
 		return snippet;
@@ -224,12 +224,12 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 		const ioStage = shaderStage === 'vertex' ? 'out' : 'in';
 
-		for ( let index = 0; index < varys.length; index++ ) {
-				
+		for ( let index = 0; index < varys.length; index ++ ) {
+
 			const vary = varys[ index ];
-			
+
 			snippet += `layout(location = ${index}) ${ioStage} ${vary.type} ${vary.name};`;
-		
+
 		}
 
 		return snippet;
@@ -247,7 +247,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
 				snippet += `${vary.name} = ${vary.value};`;
 
 			}
-			
+
 		}
 
 		return snippet;
@@ -311,8 +311,7 @@ class WebGPUNodeBuilder extends NodeBuilder {
 
 		this.vertexShader = this.composeShaderCode( this.nativeShader.vertexShader, this.vertexShader );
 		this.fragmentShader = this.composeShaderCode( this.nativeShader.fragmentShader, this.fragmentShader );
-console.log( this.vertexShader );
-console.log( this.fragmentShader );
+
 		return this;
 
 	}