-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
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
WebGLRender & NodeMaterials program caching errors #26225
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
@@ -44,6 +44,9 @@ class NodeMaterial extends ShaderMaterial { | |||
|
|||
this.positionNode = null; | |||
|
|||
this.vertexShader = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these properties are already created by ShaderMaterial?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They have the text for a minimal shader applied.
three.js/src/materials/ShaderMaterial.js
Lines 21 to 22 in 8d2430f
this.vertexShader = default_vertex; | |
this.fragmentShader = default_fragment; |
setting these to null ensures the new 'shader missing' code in getParameters() is triggered and hence material.onBuild()
I considered that, downsides it relies on authors coding it consistently and may miss changes of shader text and possible sharing of programs between different materials. Admittedly those may be corner cases, and there may be other consumers of the onBuild() mechanism. |
Closing in favor of #26227 |
** Program caching issue with Node materials and the webgl renderer **
With certain NodeMaterials eg MeshBasicNodeMaterial and MeshPhongNodeMaterial, program caching can fail with various breakages: example test case added in the PR: examples\webgl_nodes_test.html based on webgl_nodes_materials_physical_clearcoat.html.
The root cause is that program parameters from programCache.getParameters() are relied on to generate a unique key value, however the parameters and key are derived in turn from the material's shaders.
In the NodeMaterials which derive from ShaderMaterial, all node materials have the default ShaderMaterial shaders at this point, and the real shaders are only built later via onBuild(). Depending on the material's other parameters it is possible to get duplicate cache keys for different NodeMaterials, and hence the wrong programs being used for some materials.
I have have removed the inherited shaders in NodeMaterial and moved the material.onBuild() call into getParameters() to ensure accurate customShaderID values are generated.
I am not sure if this is the best solution, but it fixes the problem.
@sunag