Browse Source

auto build postprocessing

sunag 7 years ago
parent
commit
224d24d5ff

+ 29 - 3
examples/js/nodes/postprocessing/NodePass.js

@@ -6,6 +6,8 @@ THREE.NodePass = function () {
 
 	THREE.ShaderPass.call( this );
 
+	var self = this;
+
 	this.name = "";
 	this.uuid = THREE.Math.generateUUID();
 
@@ -18,7 +20,15 @@ THREE.NodePass = function () {
 	this.node = new THREE.NodeMaterial();
 	this.node.fragment = this.fragment;
 
-	this.build();
+	this.needsUpdate = true;
+
+	this.node.build = function ( params ) {
+
+		THREE.NodeMaterial.prototype.build.call( this, params );
+
+		self.uniforms = this.uniforms;
+
+	};
 
 };
 
@@ -27,13 +37,29 @@ THREE.NodePass.prototype.constructor = THREE.NodePass;
 
 THREE.NodeMaterial.addShortcuts( THREE.NodePass.prototype, 'fragment', [ 'value' ] );
 
-THREE.NodePass.prototype.build = function () {
+THREE.NodePass.prototype.render = function () {
 
-	this.node.build();
+	if ( this.needsUpdate ) {
+
+		this.node.dispose();
+
+		this.needsUpdate = false;
+
+	}
 
 	this.uniforms = this.node.uniforms;
 	this.material = this.node;
 
+	THREE.ShaderPass.prototype.render.apply( this, arguments );
+
+};
+
+THREE.NodePass.prototype.build = function () {
+
+	this.node.build();
+
+	this.needsUpdate = false;
+
 };
 
 THREE.NodePass.prototype.toJSON = function ( meta ) {

+ 1 - 2
examples/webgl_postprocessing_nodes.html

@@ -504,7 +504,7 @@
 
 				}
 
-				nodepass.build();
+				nodepass.needsUpdate = true;
 
 				// test serialization
 /*
@@ -515,7 +515,6 @@
 				var json = nodepass.toJSON();
 
 				nodepass.value = new THREE.NodeMaterialLoader( null, library ).parse( json ).value;
-				nodepass.build();
 */
 			}