Search Unity

Using "XR Management" package renders to one eye only

Discussion in 'Windows Mixed Reality' started by G33RT, Feb 6, 2020.

  1. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    31
    Hi,

    We've recently switched from built-in VR to the "XR Management" package on 2019.3 for standalone exe for WMR. We use the Standard shader and a custom shader in our scenes.

    Everything using the standard shader works fine in VR, but our custom shader renders only to the left eye. (We also tried URP, but same problem)

    Any idea's/leads? This is blocking us from moving away from the now deprecated built-in VR support.

    Thank you,

    Geert
     
    Last edited: Feb 6, 2020
  2. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    7
    Hey G33RT,
    I am guessing you were using multipass with WMR before in built-in VR? So multipass works for shaders without XR macro. Single pass instanced and multiview requires XR shader macros.

    With XR Management package, WMR forces singe pass instanced. So all custom shaders need to have proper XR macros in place. Could that be the issue you are running into?

    I would suggest convert shader to be SPI compatible if that is the case. SPI if far more performant than multipass.
     
  3. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    31
    Hi Thomas,

    Thanks for replying. I'm actually using single pass in built-in VR and that works fine. This is my shader actually (now using URP):

    Shader "Unlit/PointCloud"
    {
    Properties
    {
    _MainTex("Texture (RGB)", 2D) = "white" {}
    }
    SubShader
    {
    //Tags{ "RenderPipeline" = "LightweightPipeline" "ForceNoShadowCasting" = "True" "IgnoreProjector" = "True" }
    Tags{ "Queue" = "AlphaTest" "IgnoreProjector" = "True" "RenderType" = "TransparentCutout" "ForceNoShadowCasting" = "True" }
    Blend Off
    AlphaToMask On
    Cull Off
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma geometry geom
    #pragma fragment frag
    #include "UnityCG.cginc"
    sampler2D _MainTex;
    struct GS_INPUT
    {
    float4 vertex : POSITION;
    float4 color : COLOR;
    };
    struct FS_INPUT {
    float4 vertex : SV_POSITION;
    float4 color : COLOR;
    float2 texcoord : TEXCOORD0;
    };
    GS_INPUT vert(appdata_full v)
    {
    GS_INPUT o = (GS_INPUT)0;
    o.vertex = mul(unity_ObjectToWorld, v.vertex);
    o.color = v.color;
    return o;
    }
    [maxvertexcount(3)]
    void geom(point GS_INPUT tri[1], inout TriangleStream<FS_INPUT> triStream)
    {
    float size = tri[0].color.a * 1.6;
    if (size > 0)
    {
    half3 normal = mul(tri[0].vertex.xyz, unity_ObjectToWorld) - _WorldSpaceCameraPos;
    half3 tangent = normalize(cross(half3(0, 1, 0), normal));
    half3 up = normalize(cross(tangent, normal));
    float4 vertex = tri[0].vertex;
    half dist = distance(_WorldSpaceCameraPos, vertex);
    if (size < dist / 250.0)
    {
    size = dist / 250.0;
    }
    if (size > dist / 5.0)
    {
    size = dist / 5.0;
    }
    half3 upSize = up * size;
    half3 tangentSize = tangent * size / 1.1547;
    FS_INPUT pIn = (FS_INPUT)0;
    pIn.color = tri[0].color;
    pIn.vertex = mul(UNITY_MATRIX_VP, vertex + half4(-tangentSize - upSize / 2, 0));
    pIn.texcoord = half2(-0.366, 0);
    triStream.Append(pIn);
    pIn.vertex = mul(UNITY_MATRIX_VP, vertex + half4(upSize, 0));
    pIn.texcoord = half2(0.5, 1.5);
    triStream.Append(pIn);
    pIn.vertex = mul(UNITY_MATRIX_VP, vertex + half4(tangentSize - upSize / 2, 0));
    pIn.texcoord = half2(1.366, 0);
    triStream.Append(pIn);
    }
    }
    float4 frag(FS_INPUT i) : COLOR
    {
    float4 color = i.color;
    color.a = step(0.5, tex2D(_MainTex, i.texcoord).a);
    if (color.a < 0.5) {
    discard;
    }
    return color;
    }
    ENDCG
    }
    }
    }

    Geert
     
  4. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    31
    I've just built using "Single Pass Instanced" using built-in VR and yes, you are right. Only Left eye. But with "Single Pass" it works fine.

    Edit: so basically editing previous shader to be compatible with Single Pass Instanced rendering is the only thing keeping us from:

    * having improved performance
    * moving on to "XR Management" package and leaving deprecated built-in VR
    * finally kicking out SteamVR (!!!!)

    Can anyone help us modifying this shader? We have a dev job opening in a great company here too ;-)
     
    Last edited: Feb 7, 2020
  5. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    7
    Hey @G33RT,

    I am glad you were able to figure out the issue :)

    From the shader code you posted, another issue I noted is it is not compatible with URP shaders. All URP shaders should include URP common shader headers. So, unfortunately, those custom shaders require some upgrade work when switching to URP.

    And while upgrading, I would suggest to upgrade them to be SPI/MultiView compatible too (SPI and multi-view shares same XR macro, so you do this once and the shader is compatible with both).

    The benefits you get from this upgrade work is that SPI/MultiView is far more performant then multipass.
     
  6. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    31
    Hey, Thomas! I got everything working thanks to your remarks … and it looks great. Thanks!

    Another thing now: when no headset is connected I want to render onscreen in native resolution (as fallback). That was the default behavior of built-in VR and I need to keep that. That is not the behavior I observe with the latest "XR Managament" / WMR plugin. Any suggestions there on how to achieve this?
     
    JasonCostanza likes this.
  7. JasonCostanza

    JasonCostanza

    Unity Technologies

    Joined:
    May 23, 2017
    Posts:
    353
    You appear to be correct! That behavior is seemingly not working right, there are two lines going into our boot.config that should not be there when "Initialize on startup" is unchecked. We will have to get that worked on. I have a bug going in which you can follow, I set it public for you. As of posting this the link may appear dead for a bit while the system finishes populating the bug's issuetracker page.

    https://issuetracker.unity3d.com/product/unity/issues/guid/1219811/
     
unityunity