# Enabling depth pass on a material plugin

**URL:** <https://forum.babylonjs.com/t/enabling-depth-pass-on-a-material-plugin/26122>\
**Category:** Questions\
**Tags:** material\
**Created:** [December 16, 2021, 1:04pm UTC](https://forum.babylonjs.com/t/enabling-depth-pass-on-a-material-plugin/26122 "2021-12-16T13:04:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunobg](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brunobg/32/5523_2.png) [@brunobg](https://forum.babylonjs.com/u/brunobg)\
**Post date:** [December 16, 2021, 1:04pm UTC](https://forum.babylonjs.com/t/enabling-depth-pass-on-a-material-plugin/26122/1 "2021-12-16T13:04:09Z")

</div>

How do I enable the depth pass in a material plugin and get access to it on the shader?

In short, I want the depth value on the fragment shader, which seems to be `vViewPos.z`. I tried setting `needDepthPrePass`, but it wasn’t enough.

My attempt in a PG: [https://playground.babylonjs.com/#P8B91Z#33](https://playground.babylonjs.com/#P8B91Z#33)

---

<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:** [December 16, 2021, 2:34pm UTC](https://forum.babylonjs.com/t/enabling-depth-pass-on-a-material-plugin/26122/2 "2021-12-16T14:34:54Z")

</div>

You do not need a depth pass for this, you ll need to customize your vertex to add a varying and store the depth in that you would reuse from the fragment. you should not use the current pre path infra for this.

---

<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:** [December 16, 2021, 2:44pm UTC](https://forum.babylonjs.com/t/enabling-depth-pass-on-a-material-plugin/26122/3 "2021-12-16T14:44:12Z")

</div>

As @sebavan said. If the non linear z value is ok for you it’s easier as you simply need to read `gl_FragCoord.z`.
