Hi,
For some reason onBeforeCompile
gets triggered twice here for a single material. I’m surprised about this. Especially because there’s nothing about this on three.js docs.
Of course I did some debugging to see if there’s anything executed twice in my code, but that doesn’t seem to be the case. I’m only binding onBeforeCompile
to a handler once, it’s only used on a single material and even the material is only used on just a single plane mesh.
I don’t see any logic in firing this twice as according to the docs onBeforeCompile
should be executed for the whole program, not just for just a vertexShader or fragmentShader.
In the project I’m changing a material of an object imported with the gltfLoader.
Example
// import scene from gltf with gtlfLoader
this.myObj = this.scn.getObjectByName('myObject');
this.myMat = this.myObj.material;
console.log('bind onBeforeCompile');
this.myMat.onBeforeCompile = (shader) => {
console.log('onBeforeCompile', Date());
});
output:
As you can see the onBeforeCompile is bound only once, but executed twice right after eachother (only 14 msec difference).
I don’t get why this gets fired twice. Is this intended behaviour or is something else going on? And if intended, why is that the case?
Thanks in advance!
Threejs version: 0.136.0
[edit] when binding the same material to another object in Blender too (so material bound to two objects) and export the scene to gltf and import it in threejs the onBeforeCompile
still gets fired twice, so no additional times. So it’s independent to the amount of object-material binds.
[edit2] changing camera and renderer don’t have any influence on this either (which makes sense, but just in case I’ve tested it). And I just tested with just a single execution of renderer.render()
; same result; double firing.