Adding ShaderMaterial.onBeforeBindObservable?

material.onBindObservable is notified after shaderMaterial update effect’s uniforms, so there will be one frame delay when using material.setxxx in material.onBindObservable. So I was wondering if it is possible to add an Observable like onBeforeBindObservable.
Or maybe there is a good way to set uniforms that I don’t know, please tell me.

1 Like

You have the option to control it per mesh with mesh.onBeforeRenderMeshToEffect

Could that work?

In my situation, the mesh is rendered both in scene and a rtt, it use pbr material in scene and shader material in rtt to do some simple calculation.

If the observer is on the mesh, I can just use mesh.onBeforeBindObservable, but I believe I need to get the effectiveMaterial to judge the render is for scene or the rtt, source code is using mesh._internalMeshDataInfo._effectiveMaterial which is private.

And after checking the code, it seems onBeforeRenderMeshToEffect is not exist on mesh but only effectLayer?

You have the option to catch the change with rtt.onBeforeBindObservable maybe?

1 Like

Thanks this do work! However it is kind strange for me to write the code near the rtt but not the shaderMaterial.

agreed but at least it works :slight_smile: