-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Node Materials Not Compiling #16668
Conversation
…ated afterwards with needsUpdate=false
…has been fixed either way now
Also I don't think this is a great way of triggering the recompile, because
That being said, it's not a heavily used feature so I understand why it doesn't justify major code change |
I think we can do a little different this time about // remove this var self = this;
this.onBeforeCompile.toString = ... replace
to this.defines["NEEDS_COMPILE"]
this.defines["NEEDS_COMPILE"] = value; and add onBeforeCompile = function ( shader, renderer ) {
if ( this.needsUpdate ) {
this.build( { renderer: renderer } );
shader.uniforms = this.uniforms;
shader.vertexShader = this.vertexShader;
shader.fragmentShader = this.fragmentShader;
this.needsUpdate = false;
}
}; I did not test but I think it should work. |
I think that |
To improve this, it is necessary to improve the hash generator in the core. |
About core, I think all this string generate in I also think that we should improve that part specifically, which is the cause of three.js/src/renderers/webgl/WebGLPrograms.js Line 250 in f186b20
|
I've been using @sunag's awesome node graph system plenty as of late, and have stumbled across another bug
Testing:
webgl_materials_nodes.html
to expose bug")webgl_materials_nodes.html
--- The 2nd commit will fix the bug
--- The 3rd commit will undo the first commit (exposing the bug)
Explanation of cause:
77:
NodeMaterial.prototype.onBeforeCompile
belongs to the prototype, so all instances of NodeMaterial share it (per the exact same subclass, eg. PhongNodeMaterial, since each subclass duplicates the prototype)39:
this.onBeforeCompile.toString
treatsonBeforeCompile
as being uniquely instanced for each class, but actually when you overrideonBeforeCompile.toString
it overrides it for all instancesTherefore, all instances of the same subclass will share the same, most recent instance of onBeforeCompile.toString, which is used by WebGLRenderer to decide whether or not the recompile is actually needed