# How to show objects 20KM+ away

**URL:** <https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462>\
**Category:** Questions\
**Created:** [November 21, 2021, 5:51am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462 "2021-11-21T05:51:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bozworth](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bozworth/32/6484_2.png) [@bozworth](https://forum.babylonjs.com/u/bozworth)\
**Post date:** [November 21, 2021, 5:51am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/1 "2021-11-21T05:51:22Z")

</div>

Hi, I’ve read this…

> **[Logarithmic Depth Buffer | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/materials/advanced/logarithmicDepthBuffer)**
>
> Learn how to use the logarithmic depth buffer in Babylon.js.

`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 ^

---

<div class="post-metadata">

**Author:** ![musk](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/musk/32/17156_2.png) [@musk](https://forum.babylonjs.com/u/musk)\
**Post date:** [November 21, 2021, 6:38am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/2 "2021-11-21T06:38:09Z")

</div>

Have you tried edit the camera’s maxZ ?

> **[Camera | Babylon.js Documentation](https://doc.babylonjs.com/typedoc/classes/babylon.camera#maxz)**
>
> This is the base class of all the camera used in the application. \[API\]

---

<div class="post-metadata">

**Author:** ![bozworth](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bozworth/32/6484_2.png) [@bozworth](https://forum.babylonjs.com/u/bozworth)\
**Post date:** [November 21, 2021, 6:39am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/3 "2021-11-21T06:39:04Z")

</div>

```
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](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/6/0/60917a0040f26ea8d18250092ec9cf4bd3ef5b4e.jpeg)

UPDATE \*\*

[https://www.babylonjs-playground.com/#W2N9TD#2](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.

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [November 21, 2021, 11:21am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/4 "2021-11-21T11:21:25Z")

</div>

Adding @Evgeni_Popov

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [November 21, 2021, 11:21am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/5 "2021-11-21T11:21:35Z")

</div>



---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 21, 2021, 3:39pm UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/6 "2021-11-21T15:39:24Z")

</div>

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:

> <https://github.com/BabylonJS/Babylon.js/pull/11509>
>
> See https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/5

Use `camera.maxZ = 0` to enable “infinite far plane”. It’s the real setting that improves things when `engine.useReverseDepthBuffer = true`. In [this PG](https://playground.babylonjs.com/#W2N9TD#20) that is using reverse depth buffer, you will see artifacts:  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/9/5/95d8e89d4e3bdc7038e97bedae9a07f6cf854600.png)

Try now uncommenting line 29 which sets the “infinite far plane” mode (it will only work once the PR is merged):  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/0/507393bf61db99a08e8b91ddb85f49f4d0c69ca1.png)

That’s because using a reverse depth buffer does not really improve things in WebGL. See [Depth Precision Visualized | NVIDIA Developer](https://developer.nvidia.com/content/depth-precision-visualized) 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](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.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [November 21, 2021, 3:39pm UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/7 "2021-11-21T15:39:33Z")

</div>



---

<div class="post-metadata">

**Author:** ![bozworth](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bozworth/32/6484_2.png) [@bozworth](https://forum.babylonjs.com/u/bozworth)\
**Post date:** [November 22, 2021, 12:50am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/8 "2021-11-22T00:50:30Z")

</div>

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

Thanks for the rapid response.

---

<div class="post-metadata">

**Author:** ![zhangyahan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/zhangyahan/32/31789_2.png) [@zhangyahan](https://forum.babylonjs.com/u/zhangyahan)\
**Post date:** [June 29, 2023, 6:47am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/9 "2023-06-29T06:47:00Z")

</div>

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?

> **[Babylon.js Playground](https://playground.babylonjs.com/#W2N9TD%2332)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

edit1: Now it is found that the shadow generator is not working.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [June 29, 2023, 9:06am UTC](https://forum.babylonjs.com/t/how-to-show-objects-20km-away/25462/10 "2023-06-29T09:06:33Z")

</div>

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.
