Search Unity

Question URP Scriptable Render Feature Blit with Custom Shader not working in VR (Mutliview)

Discussion in 'VR' started by DanWeston, Apr 13, 2021.

  1. DanWeston

    DanWeston

    Joined:
    Sep 9, 2014
    Posts:
    32
    Cross posting this as I really need it solved - original post here

    I am working in Unity 2019.4.11f1 and have written a Scriptable Render Feature for my project which is using Universal RP 7.3.1.

    The process works completely fine on PC in Editor but has proven troublesome on Oculus Quest 2.

    For VR I am using the Oculus XR Plugin 1.4.3.

    In my post process I am using a Command Buffer to Blit one texture into another using a custom Shader/Material.

    My textures for VR are being set up in a standard way using

    Code (CSharp):
    1. var texID = Shader.PropertyToID("_textureID");
    2. var renderTextureDescriptor = XRSettings.eyeTextureDesc;            
    3. commandBuffer.GetTemporaryRT(texID , renderTextureDescriptor, FilterMode.Bilinear);
    Performing a ping/pong process I am simply doing

    Code (CSharp):
    1. commandBuffer.Blit(ping, pong, customMaterial, 0);
    2. commandBuffer.Blit(pong, ping, customMaterial, 1);
    Using Render Doc and debugging a frame on my Quest I can see my Blit process is not setting any of the textures for the material. The textures are being set to default/white instead. https://imgur.com/a/MHw5Ht9

    I've tried explicitly setting these textures using CommandBuffer.SetGlobalTexture

    Code (CSharp):
    1. commandBuffer.SetGlobalTexture ("_MainTex", ping);
    But nothing seems to work.

    Completely out of ideas on this one, anyone come across this before? I'm not sure what needs to be done to get my textures linked to my Shader.
     
  2. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    85
    Hello there!

    In XR single pass, eye textures and screenspace textures are configured to be texture2dArray type. I think it is likely that in the shader, those textures are still declared as texture2d which causes the binding to fail. Unity then binds UnityWhite as default.

    Could you check your shaders and see if it is missing TEXTURE2D_X macro?

    Thanks
    Thomas
     
  3. DanWeston

    DanWeston

    Joined:
    Sep 9, 2014
    Posts:
    32
    Hi Thomas,

    That makes sense, thank you for your response!

    I've not actually ported the shader from a CGPROGRAM to a HLSLPROGRAM. Looking at examples for the TEXTURE2D_X macro the shader will need to be ported to support it correct?

    I'll give that a go now!

    Thanks,
    Dan
     
  4. DanWeston

    DanWeston

    Joined:
    Sep 9, 2014
    Posts:
    32
    Hi Thomas,

    I just ported over my Shaders to HLSL and set up my Texture/Samplers like so.

    Code (CSharp):
    1. TEXTURE2D_X (_MainTex);
    2. SAMPLER(sampler_MainTex);
    3. CBUFFER_START(UnityPerMaterial)
    4.   float4 _MainTex_ST;
    5. CBUFFER_END
    This is all working as expected in Editor but when I build to my Quest it doesn't work.

    Looking at a RenderDoc capture it appears to be the same issue, my _MainTex is defaulted to UnityWhite.

    This is the same even if I use

    Code (CSharp):
    1. commandBuffer.SetGlobalTexture ("_MainTex", _RenderTexID);