# Logarithmic Depth Buffer and webgl2 shader

**URL:** <https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226>\
**Category:** Questions\
**Tags:** webgl2\
**Created:** [August 26, 2019, 9:43am UTC](https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226 "2019-08-26T09:43:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alejandro\_Insua](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/alejandro_insua/32/3958_2.png) [@Alejandro\_Insua](https://discourse.threejs.org/u/Alejandro_Insua)\
**Post date:** [August 26, 2019, 9:43am UTC](https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226/1 "2019-08-26T09:43:02Z")

</div>

Hi all.

Is there anyway to use a webgl2 shader with Logarithmic Depth Buffer support?

By now I have been using a workaround setting the near and far camera settings depending on the camera position, but it is not enough. My scene is very complex and many times I face the superposition issue.

Could anybody show me an example using Logarithmic Depth Buffer in a webgl2 context?

Many thanks in advanced.

Best regards

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [August 26, 2019, 10:58am UTC](https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226/2 "2019-08-26T10:58:32Z")

</div>

> [@Alejandro\_Insua](#):
>
> webgl2 shader

Are you talking about custom shaders or built-in materials? The official example seems to work just fine with a WebGL 2 rendering context (tested locally on my computer).

[https://threejs.org/examples/webgl\_camera\_logarithmicdepthbuffer](https://threejs.org/examples/webgl_camera_logarithmicdepthbuffer)

---

<div class="post-metadata">

**Author:** ![Fyrestar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/fyrestar/32/52793_2.png) [@Fyrestar](https://discourse.threejs.org/u/Fyrestar)\
**Post date:** [August 26, 2019, 1:49pm UTC](https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226/3 "2019-08-26T13:49:02Z")

</div>

There is no issue with using logarithmic depth buffer and WebGL2.

> [@Alejandro\_Insua](#):
>
> My scene is very complex and many times I face the superposition issue

This probably isn’t related to the depth buffer, you can only get depth fighting issues there, depending on what you mean with superposition. WebGL highest precision is 32 bit, on mobile it can be even just 16, if you use high values or too large distances from the origin there will be precision issues like jumping vertices, or flickering textures with huge uv coordinates, regardless using the logarithmic depth buffer. Same goes for using too small decimal numbers.

---

<div class="post-metadata">

**Author:** ![Alejandro\_Insua](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/alejandro_insua/32/3958_2.png) [@Alejandro\_Insua](https://discourse.threejs.org/u/Alejandro_Insua)\
**Post date:** [August 28, 2019, 6:08am UTC](https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226/4 "2019-08-28T06:08:39Z")

</div>

> [@Fyrestar](#):
>
> buffer

Hi

I will try to provide a fiddle example of my issue.

Many thanks in advanced

---

<div class="post-metadata">

**Author:** ![Alejandro\_Insua](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/alejandro_insua/32/3958_2.png) [@Alejandro\_Insua](https://discourse.threejs.org/u/Alejandro_Insua)\
**Post date:** [August 28, 2019, 6:12am UTC](https://discourse.threejs.org/t/logarithmic-depth-buffer-and-webgl2-shader/9226/5 "2019-08-28T06:12:25Z")

</div>

Hi Michael.

I am takling about using a custom shader material.

Best regards
