Search Unity

Graphics.Blit stereo rendering Blit pixel shift. Bug?

Discussion in 'AR/VR (XR) Discussion' started by Fewes, Jan 15, 2019.

  1. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    I am making a cloud plugin for Unity that renders the result to a downscaled RenderTexture. This result is then upscaled using a nearest-depth filter. While authoring the plugin for single-pass stereo rendering, I've noticed a strange issue where the right eye sometimes is offset a little bit when using Graphics.Blit. This isn't noticeable for most use-cases perhaps, but the upscale filter is very sensitive and needs pixel-precise depth data to work.
    This offset is stopping the filter from working properly. I have tried doing some manual offsets to fix this, but have run into a wall since I cannot seem to get it to line up properly

    Here's an animated image showing the problem. Notice how the right eye drifts when the downsample scale is increased (although interestingly, 1/8 outputs the correct result).
    The image shows the result of the upscale filter. For brevity I've made the scene black and the clouds blue.

    stereo_blit_offset.gif

    I am suspecting this might be a bug, as I'm not really doing anything fancy other than using Graphics.Blit and the default texture coordinates (adjusted for single-pass stereo).
     
    Last edited: Jan 15, 2019
  2. Fewes

    Fewes

    Joined:
    Jul 1, 2014
    Posts:
    259
    In classic fashion I found the solution just after posting. The problem stems from the RenderTexture width being an odd number. So if your code looks like:
    Code (CSharp):
    1. int downsampledWidth  = width  / downsampleFactor;
    2. int downsampledHeight = height / downsampleFactor;
    Just make it:
    Code (CSharp):
    1. int downsampledWidth  = width  / downsampleFactor;
    2. int downsampledHeight = height / downsampleFactor;
    3. if (downsampledWidth % 2 != 0)
    4.     downsampledWidth++;
     
    JoeStrout likes this.