Search Unity

Bug Using "XR Management" package renders to one eye only

Discussion in 'VR' started by G33RT, Feb 6, 2020.

  1. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    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:
    85
    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.
     
    ceitel likes this.
  3. G33RT

    G33RT

    Joined:
    Dec 27, 2013
    Posts:
    52
    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:
    52
    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:
    85
    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:
    52
    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:
    404
    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/
     
    nasos_333 likes this.
  8. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    I try to check the VR status in Mock HMD and seems to always return MultiPass even if Single Pass Instance is selected, this probably creates issue as i only see image in left eye, right is full black with my image effect on

    Is this a known bug ?

    Thanks
     
  9. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    The only time this may happen is if the hardware can't support single pass instancing - on dx11 we need VPAndRTArrayIndexFromAnyShaderFeedingRasterizer (and equivalent on other graphics apis).

    If you are seeing this happen and you know you can run Single Pass Instance on your machine with providers other than Mock HMD, please file a bug and post it here.
     
  10. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,349
    Hi,

    I have a DELL with nvidia, bought 3 years ago, i suppose should support it but cant be sure.

    Is it possible that this is a such a highly advanced feature that only very last years cards support it ?

    Thanks
     
  11. EntertainmentEnterprise

    EntertainmentEnterprise

    Joined:
    Aug 22, 2018
    Posts:
    18
    Can anyone please share how exactly to update the shaders to SPI compatible? I'm having the shaders only rendering in the left eye issue. Even with the new XR Management stuff and the default XR rig, the lines from the controllers only render in the left eye. Please assist.
     
  12. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    Details are here: https://docs.unity3d.com/Manual/SinglePassInstancing.html
     
  13. alsharefeeee

    alsharefeeee

    Joined:
    Jul 6, 2013
    Posts:
    80
    Hi @ThomasZeng
    Same thing here, not using any custom shader just Unity UI!

    Using Unity 2020, WMR headset with XR Management and XR Interaction Toolkit, for some reason normal Unity UI renders in one eye only, the left eye.

    Tried to change the platform to Universal Windows Platform but that didn't change anything.
     
    Last edited: Oct 1, 2020
  14. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    Are you using a world-space canvas? Screen-space doesn't work for VR.
     
    alsharefeeee likes this.
  15. olavrv

    olavrv

    Joined:
    May 26, 2015
    Posts:
    515
    We are using world-space canvases, and this doesn't work after switching to xr plugin management plugin (2020.1.0f7 / HDRP 9.0.0 and 2020.2.0b4 / hdrp 10.0.0). Only renders in left eye. Bloom effect is not working correctly on left eye.

    Also, screen mirroring in builds doesn't work after switching to xr plugin management package.

    You can also see this in editor (that UI only renders to left eye)
     
    Last edited: Oct 2, 2020
  16. olavrv

    olavrv

    Joined:
    May 26, 2015
    Posts:
    515
  17. alsharefeeee

    alsharefeeee

    Joined:
    Jul 6, 2013
    Posts:
    80
    True, I am using World Space Canvas.
    Does this mean there is no way to use UI with VR in XR Management?
     
  18. lyneca_

    lyneca_

    Joined:
    Sep 6, 2020
    Posts:
    2
    olavrv likes this.
  19. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
    I spoke to the team and they wanted to know

    "What rendering mode are you using? As mentioned previously in the thread, we recommend upgrading your shaders to single pass instanced. Details on how to do that can be found here: https://docs.unity3d.com/Manual/SinglePassInstancing.html. If you are still running into issues, please file a bug and we will investigate."

    Also from the team

    "Although Shader Graph shaders can run in XR, Shader Graph doesn't currently support the XR utility feature to create SPI-compatible shader input textures. Unity will add this, as well as the ability to access eyeindex from Shader Graph, in a future release."
     
  20. EntertainmentEnterprise

    EntertainmentEnterprise

    Joined:
    Aug 22, 2018
    Posts:
    18
    This is awesome news and I believe it will solve all of our problems. For now I've switched to URP and everything seems better across the board. If I have any issues, we'll update the shaders manually until their is a fix from you guys. Thanks for the help.
     
  21. Innovine

    Innovine

    Joined:
    Aug 6, 2017
    Posts:
    522
    @Shaunyowns you recommend we upgrade to spi shaders, at the same time you say shadergraph doesn't support spi shaders for xr?? That is infuriating. When will this be resolved? Can you just fix this broken mess of an engine, please.
     
  22. Shaunyowns

    Shaunyowns

    Joined:
    Nov 4, 2019
    Posts:
    328
    Hey there! @Innovine

    Shader graph shaders are compatible with SPI by default. The only known restriction for now is that you can't access eye idx in shader graph and you can't use screen space textures other than camera color/depth (screen space texture needs to be texture2dArray in SPI and requires special care). If you encounter any issues, please file a bug so we can take a look.
     
  23. jorjantoniy

    jorjantoniy

    Joined:
    Sep 24, 2021
    Posts:
    4
    I NEED YOUR HELP: when I try to run my unity vr project, my personal SHADER in the object is visible in one eye, but not in the other, I did not use URP AND HDRP in my project. HOW CAN I FIX THIS? PLEASE HELP
     
  24. jorjantoniy

    jorjantoniy

    Joined:
    Sep 24, 2021
    Posts:
    4
    HELLO @ThomasZeng ! I NEED YOUR HELP: when I try to run my unity vr project, my personal SHADER in the object is visible in one eye, but not in the other, I did not use URP AND HDRP in my project. HOW CAN I FIX THIS? PLEASE HELP
     
  25. EnduvoJD

    EnduvoJD

    Joined:
    Aug 12, 2016
    Posts:
    53
    I'm having this issue in 2019.4 only in assetbundle scenes including only the standard shader.

    Would this be due to having built the scenes before switching to XR management and single-pass instanced?
     
    Last edited: Oct 20, 2023