Skip to content

Commit

Permalink
Fixed NodeMaterial not compiling when a material of same class is cre…
Browse files Browse the repository at this point in the history
…ated afterwards with needsUpdate=false
  • Loading branch information
DanielSturk committed Jun 3, 2019
1 parent dca1fac commit 1b8c82f
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions examples/js/nodes/materials/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ function NodeMaterial( vertex, fragment ) {

this.updaters = [];

// onBeforeCompile can't be in the prototype because onBeforeCompile.toString varies per material

this.onBeforeCompile = function ( shader, renderer ) {

if ( this.needsUpdate ) {

this.build( { renderer: renderer } );

shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;

}

};

// it fix the programCache and share the code with others materials

this.onBeforeCompile.toString = function() {
Expand Down Expand Up @@ -74,20 +90,6 @@ NodeMaterial.prototype.updateFrame = function ( frame ) {

};

NodeMaterial.prototype.onBeforeCompile = function ( shader, renderer ) {

if ( this.needsUpdate ) {

this.build( { renderer: renderer } );

shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;

}

};

NodeMaterial.prototype.build = function ( params ) {

params = params || {};
Expand Down

0 comments on commit 1b8c82f

Please sign in to comment.