WebGLPrograms: Improve performance of getParameters().#19673
WebGLPrograms: Improve performance of getParameters().#19673mrdoob merged 4 commits intomrdoob:devfrom
Conversation
|
Too bad, this approach does not work. There is an unfortunate dependency to |
|
Thanks for the effort! Unfortunately I still see light state changes in a scene rendering only a |
Yes, but the overhead related to |
|
Sorry, you are right of course: I have to check with my larger scene, but I assumes this would fix my performance issues. But you say it would lead to incorrect results if I would change material properties in Thanks again for your efforts, much appreciated! |
|
Sorry, but I see no way to fix this without refactoring @mrdoob In the meanwhile, it seems to me And now, even the name This will definitely be a problem if the engine wants to have multiple programs per material, see #15047. I also think that the code of this PR is the right one since it saves a certain amount of overhead in |
|
|
||
| parameters.uniforms = programCache.getUniforms( material, parameters ); | ||
|
|
||
| material.onBeforeCompile( parameters, _this ); |
There was a problem hiding this comment.
Need to pass in parameters so user code actually modifies the correct vertexShader and fragmentShader used for shader compilation.
|
While we are at it: #17567 should be merged to solve a conceptual issue with If the user implements three.js/src/renderers/webgl/WebGLPrograms.js Line 339 in 681ba71 This leads so identical program cache keys and thus prevents different shaders. Merging #17567 might provide an API for |
Merged! 👍 |
|
I've not studied this PR yet but, just so you know, I've updated |
Cool! 👍 Sidenote: This whole topic is quite complicated and I had to invest a lot of time today in order to recall all the details^^. It might be necessary to target |
|
@sunag It seems Meaning instead of having this code in three.js/examples/jsm/nodes/materials/NodeMaterial.js Lines 47 to 53 in 5dbfa90 it should be: this.customProgramCacheKey = function () {
return this.computeHash();
};Otherwise it's necessary that if ( material.isNodeMaterial === true && material.requiresBuild() === true ) {
material.build( { renderer: _this } );
}However, |
|
Is there currently an example that fails using this PR? I had some issues using |
Yes, it's |
|
Related |
|
@Mugen87 Interesting... |
|
Yes. But it seems only If you can manage to compute a key or hash that represents the configuration of a |
|
It seems a good opportunity to create a |
|
Sounds good! This should also fix #18347. |
|
hi @Mugen87 , what needs to be done to fix this issue pls ? Im facing this error on my project TypeError: d.customProgramCacheKey is not a functionthree.min.js:103:324 |
|
You need to share some more details about this issue. Do you mind demonstrating it with a live example? https://jsfiddle.net/hyok6tvj/ |
|
@Mugen87 > You need to share some more details about this issue. Do you mind demonstrating it with a live example? https://jsfiddle.net/hyok6tvj/ sure. (https://codesandbox.io/s/elated-bas-jm9ze) its on /js/Light/Lights.js If I comment out line 93 ( scene.add(light2); ) it works . |
|
Sorry, but I'm afraid your app setup is incorrect. You include Another thing which is unrelated to your issue: You use the latest Please use the forum if you need help to clean up these inconsistencies. |
Sure. I see and thank you for helping me. Im just starting at this threejs and js world. will get updates :) |
|
Thanks! |
|
Yay! 🎉 |


I've realized today that cloning uniforms in
getParameters()should not be necessary. This potential expensive task can be done only when shader program actually needs a compilation. Besides, uniforms are not necessary to compute the program cache key.@carstenschwede Can you please check if this PR mitigates your performance issue?