I’m using Babylon v5 and it looks like this doesn’t work anymore :
engine.useReverseDepthBuffer = true;
In the playground example it works only on 4.2, but in my own scene, for 4.2 or 5.0 i cant get useReverseDepthBuffer to show objects far away, doesn’t render anything after about 1 mile.
The previous implementation of useReverseDepthBuffer (in 4.2) is bugged: try using a camera.minZ value > 1 in your PG, the meshes will disappear.
This PR will enable the “infinite far plane” mode in reverse depth buffer mode:
Use camera.maxZ = 0 to enable “infinite far plane”. It’s the real setting that improves things when engine.useReverseDepthBuffer = true. In this PG that is using reverse depth buffer, you will see artifacts:
Try now uncommenting line 29 which sets the “infinite far plane” mode (it will only work once the PR is merged):
That’s because using a reverse depth buffer does not really improve things in WebGL. See Depth Precision Visualized | NVIDIA Developer for in-depth explanations. Also, logarithmic is not compatible with reverse depth buffer: use either one or the other.
So, in WebGL you should not use the reverse depth buffer but the logarithmic depth instead:
Note that you need to set a real far plane (the “infinite far plane” mode is not supported) for the logarithmic depth to work as expected (as the far plane value is used as part as some internal computations).
Note also that in WebGPU you should always use the reverse depth buffer mode as it is working as expected there, and you save some performance over logarithmic depth because we don’t have to set the depth in the fragment shader.
Now, does webgl2 support reverse depth buffer? In this pg using reverse depth buffer in webgl2 and disallowing logarithmic depth has the same effect. Why in WebGL you should not use the reverse depth buffer but the logarithmic depth instead?
edit1: Now it is found that the shadow generator is not working.
No, WebGL2 does not support the reverse depth buffer and never will. This is because in the NDC coordinate system, the Z range is [-1…1] and not [0…1]. This range can be modified in OpenGL, and the reverse depth buffer is supported, but not in WebGL2.