How to rotate texture of frozen material

Hi,
i have a material which is frozen for better performance. Now i want to rotate its texture.
How can i do this? Here is a Playground: Babylon.js Playground
The texture rotation is not changing. I’m calling markDirty() already on the material and would expect that this would help.
If i remove line 27 (mat.freeze()) it works.

How can i rotate the texture without un-freezing the material?

Note: In my real application i change the texture rotation only in rare cases, not as an amiation like in the PG. Thats why i would like to keep the material frozen.

You can unfreeze the material to make your changes, then freeze it again:

I use setTimeout(..., 0) before freezing again to give the system time to update the material in the current frame.

That will not work i think. I can only freeze it after the meshes which are using the material were rendered. Depending on the camera the mesh may not be visible. How can i know that the material was really updated?
Why does markDirty() not help? Seems like a bug to me.

markDirty() will help re-run the isReadyForSubMesh() code, which is used to rebuild a new effect if necessary, but won’t force the code in bindForSubMesh() to be run. It is not a problem when a material is not frozen because the code is always run in that case, but when it is, the code is not executed.

I think we could force the code in bindForSubMesh to be run the next time it is called when markDirty() has been called, so here’s a PR that does that and will fix your first PG:

However, instead of doing markDirty(), you will need to call markDirty(true) to force everything to be recomputed when the material is frozen. Also, it will work even if the mesh is out of view at the time markDiry(true) is called.

2 Likes