Currently i have the problem that my materials are getting darker when i disable the shadows for a light like this: light.shadowEnabled = false.
This only happens if the materials are frozen. I’m calling markDirty() already for each material. The question is how can i correctly update my materials after disabling the shadows (without unfreezing them)?
You need to let the system be able to recreate the effects with the new settings when you enable/disable shadows. When materials are frozen it can’t do it. So you should unfreeze the materials for the next frame then refreeze them:
Ok i can unfreeze and freeze them again but i think this will get complicated.
If i unfreeze them lets say for one frame, then only the currently visible meshes/materials would be updated or? How can i be sure that i can freeze the material again? Isn’t there a way to update all at once?
As expected it does not work
Here a PG to show the issue: https://playground.babylonjs.com/#5EPWDN#3
In this PG i unfreeze the materials and freeze them again after rendering.
If you load it and press directly on “Toggle Shadows” it works correktly because all the meshes are visible. But if you do the following it is not working and the materials are dark:
reload the PG
press “Toggle Camera”
press “Toggle Shadows”
press “Toggle Camera” again
As i was expecting if a mesh is currently not visible the material will not update. When is the correct time to freeze the materials again? How can i be sure that all subMeshes for this mterial were rendered?
I think it would be easier if there would be a way to reset the internal “wasReady” state for a material and the related effects.
Note that I could not make the PG fail even when following your instructions.
Anyway, the problem is that the “frozen” flag is on the material, not the submesh. If you have a submesh A visible and another B which isn’t, you would need to keep the “frozen” flag cleared until B is drawn, even if A has already been drawn, before setting frozen to true.
Having said that, it seems your very first PG does now work…
I switched to version 4.2.0 in the playground because this is the version we are using. If i use the latest version i also can’t reproduce this. So its fixed in 5.0.0 ?
I think for for version 4.2.0 i will have to unfreeze all materials permanently and live with the performance drop for now. In the end its very unlikely that the user is looking in every necessary direction to get all meshes rendered. The materials would stay unfrozen a very long time anyway.