Search Issue Tracker

Won't Fix

Votes

1

Found in

2019.4

2020.3

2021.2

2021.2.7f1

2022.1

Issue ID

1396587

Regression

No

[XR SDK] Shader Grabpass returns results in plain grey color when Single Pass rendering mode is applied

Shader System

-

Reproduction steps:
1. Open the attached project ("1396587R.zip")
2. Open the SampleScene scene
3. Open XR Plug-in Management settings
4. Enable Mock HMD Loader
5. Set Mock HMD Render mode to Single Pass Instanced
6. Enter Play mode

Expected result: Cube and Sphere game objects has greyscale applied Plane is in full color
Actual result: Cube, Sphere and Plane are in plain grey color (see "Unity_qY9ITugdfR.mp4" video)

Reproducible with: 2019.4.35f1, 2020.3.27f1, 2021.1.28f1, 2021.2.9f1, 2022.1.0b4, 2022.2.0a2

Tested:
- Oculus Rift with OpenXR 1.3.1, MockHMD 1.3.0-preview.1, Oculus 1.11.2 Plug-in providers

  1. Resolution Note (2022.2.X):

    The reason the grab pass doesn't seem to be working in "Single Pass Instanced" mode is that the output texture switches from Texture2D to Texture2DArray so it fails to match texture dimensions.
    To work around this, you can use a macro to switch the texture type and relevant sampling calls. Attached is a modified version of the shader that works in both modes.

Comments (1)

  1. ainisciurlys

    Apr 11, 2022 06:51

    Here's the "GrabPassFail.shader" shader mentioned in the resolution notes:

    Shader "Test/GrayScal" {
    Properties{
    }
    Category{
    Tags{ "Queue" = "Transparent-50" "IgnoreProjector" = "True" "RenderType" = "Opaque" "PreviewType" = "Plane"}

    SubShader{

    GrabPass
    {
    "_BackgroundTexture"
    }

    // This should render the plane, cube and sphere again using _BackgroundTexture
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag

    #include "UnityCG.cginc"

    #if STEREO_INSTANCING_ON
    UNITY_DECLARE_TEX2DARRAY(_BackgroundTexture);
    #else
    UNITY_DECLARE_TEX2D(_BackgroundTexture);
    #endif

    struct appdata_t {
    float4 vertex : POSITION;
    UNITY_VERTEX_INPUT_INSTANCE_ID
    };

    struct v2f {
    float4 vertex : SV_POSITION;
    float4 grabPos : TEXCOORD2;
    UNITY_VERTEX_OUTPUT_STEREO
    };

    v2f vert(appdata_t v)
    {
    v2f o;
    UNITY_SETUP_INSTANCE_ID(v);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.grabPos = ComputeGrabScreenPos(o.vertex);

    return o;
    }

    float4 frag(v2f i) : SV_Target
    {
    UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
    float2 proj = i.grabPos.xy / i.grabPos.w;

    #if STEREO_INSTANCING_ON
    float3 proj3 = float3(proj, unity_StereoEyeIndex);
    half4 bgcolor = UNITY_SAMPLE_TEX2DARRAY(_BackgroundTexture, proj3);
    #else
    half4 bgcolor = UNITY_SAMPLE_TEX2D(_BackgroundTexture, proj);
    #endif

    float grayValue = dot(bgcolor.rgb, float3(0.3, 0.59, 0.11));
    return float4(grayValue, grayValue, grayValue, 1);
    }
    ENDCG
    }
    }
    }
    }

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.