How to show objects 20KM+ away

Hi, I’ve read this…

material.useLogarithmicDepth = true;

Especially the part about being able to see large distances like planet size…

Was trying to enable it and ended up using generateDepthBuffer in engine options.

const engine = new Engine(canvas, true, {generateDepthBuffer:true})

I want to show stuff that is really far away but raising camera far doesnt do anything and the options above neither ^

Have you tried edit the camera’s maxZ ?

this.activeCam.maxZ = 1000000;

Yes i h ave. I can barely see a mile ahead of me.

I want to see something like this:

image

UPDATE **

https://www.babylonjs-playground.com/#W2N9TD#2

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.

Adding @Evgeni_Popov

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:
image

Try now uncommenting line 29 which sets the “infinite far plane” mode (it will only work once the PR is merged):
image

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:

https://playground.babylonjs.com/#W2N9TD#21

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.

4 Likes

Thank you that resolved it! Looking forward to that PR getting merged too.

Thanks for the rapid response.

1 Like