Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
doubledan's avatar
doubledan
Explorer
7 years ago

Depth in shader (Unity)

I'm struggling to get depth in a shader to work on the Quest. I've tried using the following to calculate depth.
o.depth = -UnityObjectToViewPos(v.vertex).z *_ProjectionParams.w;
That works in the editor but not on device. I've also tried using CameraDepthTexture. This only works if I blit my shader in OnRenderImage, which kills performance. I asked about replacement shaders and custom post processing in this post (https://forums.oculusvr.com/developer/discussion/81234/replacement-shader#latest) and the advice here (and elsewhere) was don't on the Quest. So I'm trying to switch to an object based effect, but I need depth info from the camera, and I can't seem to get it to work on the Quest.  I'm pretty new to shaders so it's possible that I've missed something obvious.

N.B. I'm using the built in render pipeline in Unity 2019.2. If I am no longer using post processing, I could switch to the URP/LWRP. Is anyone using depth data in a custom shader in the URP/LWRP? Is it working on device?

2 Replies