I add fog underwater. When I use StandardMaterial it works well, but not with MixMaterial.
If I put my camera underwater, I get the fog, but if I go back above the ground, the fog is stay on the ground, it seems to have disappeared from the rest of the environment because we see the Sky. Only the terrain has a part of the fog which is very strange.
It seems that the problem comes from FOGMODE_LINEAR because it works if I switch the fog mode to FOGMODE_EXP and play with fogDensity In place of BABYLON.Scene.FOGMODE_NONE
It’s strange. I also had a shadow problem that did not display which now works using FOGMODE_EXP
Is this normal with LINEAR Mode or can it be a bug?
So I use the EXP mode that works, but the LINEAR mode allowe me to give a start and an end to the fog.
In fact you think it works in your second PG because by setting the density to 0 you make the fog disappear, but the fog code is still there whereas it should not.
As a workaround, you can set the checkReadyOnEveryCall property of the mix material to true to make it work:
What I’ve done is kept the fog as linear, but I’ve raised the level where the fog switches between NONE and LINEAR.
If you go up above 50 in y, you can see the fog disappear, but then as soon as you drop back below 50, you can see the fog reappears, but not correctly as when it’s first rendered.
Still doing some digging, but definitely doesn’t seem right.
You need to set the checkReadyOnEveryCall to true to make it work.
I think it’s because the ground has been processed a first time when it had no sub meshes (before the call to optimize, which happens later as it is asynchronous), and the effect has been created at that time. Later on, when the structure of the mesh is modified (by the call to optimize which creates several submeshes) it is not noticed by the engine because the effect was already ok with the previous structure, so it does not refresh the effect. Setting checkReadyOnEveryCall makes the engine check everything is in order at each frame.
As an aside, checkReadyOnEveryCall can be reset back to false after the engine has reprocessed the mesh, which is normally the next frame after optimize has been called.
Thanks @Evgeni_Popov! And that’s a fantastic suggestion to set it back to false after it’s reprocessed the mesh. That would be a great way to save perf!
Yes it works better with checkReadyOnEveryCall, but if I use the LINEAR mode of the fog my shadows disappear, but not with the EXP mode.
In addition if I deactivate after checkReadyOnEveryCall to false and my linear shadow appears, it will recreate the same problem. I should always leave checkReadyOnEveryCall at true, but for performance it is not very good.
In fact, with EXP Mode no problem with shading and putting checkReadyOnEveryCall.
I still think there is a little problem well hidden.
I tried to do a PG, but I can’t reproduce the problem I have at home.
So I try to understand what is happening on my side. Because it works if I use fog EXP mode and it also works if I use StandardMaterial instead of MixMaterial. So I can’t understand why it works in the current PG. If I can understand it I will come back.
Yes it works now with LINEAR and without checkReadyOnEveryCall at true.
For my shadow problem, it is always present. In fact the shadows appear when the fog activates underwater and disappears when I go back to the ground. Maybe a problem adjusting my shadows or some other problem ?
Ok, my shadow was actually very weak. I had to play with shadowMaxZ and set a smaller value to 100 instead of 500 for it to display correctly.
Everything is ok now.