Enabling depth pass on a material plugin

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

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.

1 Like

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.