cancel
Showing results for 
Search instead for 
Did you mean: 

Depth in shader (Unity)

doubledan
Explorer
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 2

Anonymous
Not applicable
Grabbing depth and opaque textures are definitely broken in URP/LWRP. I thought that problem was unique to the scriptable render pipeline, but it doesn't come as a huge surprise that it's broken globally.

There are several threads in the Unity forums where these issues are being discussed. Unity and Oculus are working on the issues, but haven't shared a timeline. You should definitely search the Unity forums to make sure there are no workarounds and submit a bug if you have time.

https://forum.unity.com/threads/grabpass-and-_grabtexture-do-not-work-on-android-devices.99328/#post...
https://forum.unity.com/threads/fixed-foveated-rendering-on-oculus-quest-not-working.686662/
https://forum.unity.com/threads/case-1183936-android-vr-postprocessing-bug-collection.744287/

doubledan
Explorer
Thanks for responding again and that for the information. I'll check out those threads and submit a bug.