Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Getting Depth Textures to work in VR (Single-pass & Multi-pass)

Discussion in 'AR/VR (XR) Discussion' started by fantasticdev, Jan 11, 2017.

  1. fantasticdev


    May 8, 2013
    NOTE: I have also posted this question in the Shaders forum here but have had no responses and I'm not sure which forum is best suited to getting feedback, hence this reposting.

    I'm in the (increasingly drawn out) process of adding VR support to my asset Fantastic Glass.

    I have the grab pass working, (most) inconsistencies caused by Single-pass dealt with, and everything is being synchronised to avoid any ghosting.

    The only issue I seem to be left with is getting depth values in my shader from depth textures rendered in other cameras.

    The depth textures when received by the material appear to be per-eye and include part of the dividing black border - they aren't requested in any special way; this is just how Unity renders / passes them along:

    Here is an example in VR of the depth issue causing an offset edge in the distortion:

    Here's an example with VR support disabled:

    Here's another screen showing that each eye receives a different offset in VR and even shows the border in Single-Pass:

    Here's an example in VR with the distortion effects disabled (red albedo for visibility as the sphere is unlit to make the edges clearer):

    Grab pass and normal (e.g. _MainTex) UVs are working fine. However, if I try to use a similar UV / Unity's various new stereo functions with the depth textures, the results are even worse than in these examples.

    Here's an example in VR of fogging and extinction showing the same edge - their intensity is derived only from the front, back, and other (non-glass) depth values:

    Does anyone have any experience in getting something like this to work or have an idea of what I should be doing to get the right values?

    I can't find an explanation of how Unity recommends integrating their VR support and would massively appreciate any help :)
  2. eastes


    Sep 1, 2012
    I'm still struggling to find a solution to this. I'm going to have to do without distortion effects for now.
  3. z_space


    Jul 17, 2016
    Did you ever solve this?
  4. Mutimir


    Dec 6, 2018