I am a bit perplexed by the behavior of meshes having ignoreCameraMaxZ set to true.
Firstly: In the PG provided, I expect that meshes having ignoreCameraMaxZ set to true will always render, however they don’t after some distance from the camera. Why?
Secondly: In the PG provided, I expect the meshes having ignoreCameraMaxZ set to true to be properly depth sorted and be visually occluded as normal by other meshes, however this is not the case. Why?
After discussing with @carolhmj I agree the behavior is somehow unintuitive.
ignoreCameraMaxZ only changes the transform matrix of the camera to prevent clipping on the GPU.
It does not interfer with mesh selection and clipping. As it is mostly to be used with skyboxes, it is never culled. In your case you can use alwaysSelectAsActiveMesh https://playground.babylonjs.com/#BB16LV#1 to prevent clipping.
We do not do it automatically to prevent bloating the mesh selection which is one of the bottleneck with too many edge case as it should in theory still clip on x and y but z.
About the second point, It might be a side effect of pushing everything on z.
May I ask why you are trying to rely on this feature to see if there could be a better way ?
Thank you @sebavan ! In one of our environments which has a large span in world space, we would like to have certain meshes, such as prominent buildings, the ground, and far away clouds (not from sky box, by design, but meshes), always fully visible unless fully or partly occluded by another mesh. Other meshes such as small bushes, outdoor seating, and such we want to be culled due to the camera’s maxZ setting.
Yes, the transformation matrix is not the same when the far plane is at infinity, so the depth values are different than when ignoreCameraMaxZ is not used. This means that you cannot mix objects with this flag set and others with the flag not set, unless the objects do not write to the depth buffer (like a skybox).
We should add that to the docstring then as a general recommendation. Maybe something like “intended for use only for objects that don’t write to the depth buffer, like skyboxes”?
Yes, but the other valid use case would be to set this flag for all objects. That way, even if they write to the depth buffer, it still works because they all use the same type of transformation matrix.