Grabpass still not working on Android

CORRECTION: GRABPASS DOES NOT WORK ON A SUPER POWERFUL PC EITHER.

Hi

this has been reported numerous times and “fixed” and then broken again in different Unity versions.

grabpass in single pass rendering will return a gray texture. If you search the forum you’ll find ton of posts different years with its issue tracker and “fixed” and broken again on unity updates. This basically breaks every single water effect just to name a few.

just as an example this thread

It doesn’t have to be on Android. This problem is also present if you render it on a PC using VR single pass rendering.

Even if it worked, performance would be horrible on any Android system I’m aware of. Consider using a framebuffer fetch instead.

1 Like

Performance is fine. And I’m correcting the title, Grabpass doesn’t even work on PC using single pass rendering. I’ve just tested with my Oculus Rift and an nvidia 3080. I think performance there shouldn’t be the problem.

Ran into the same issue on PC. Reported the bug, can be found on the issue tracker here Unity Issue Tracker - [XR SDK] Shader Grabpass returns results in plain grey color when Single Pass rendering mode is applied . It was accepted as a bug a couple of days after i submitted a test project to reproduce it. Make sure to get those bug reports in when you have problems, maybe this would already be fixed.

My ticket was closed as a won’t fix, because it seems it can be made to work (at least on pc, you’d have to test on Android). Here’s the modified version (Unity sent back to me) of my test shader. The original problem seems to be that the grab pass texture needs to be declared as a tex2D array in the shader using it rather than a tex2d, along with adjustments to to the sampling coordinates.

I have to schedule in time to swap my command buffer based workaround out with a grabpass based version to test it. But I figure it might be useful to someone else before i get to that, it’s low priority for me. The test shader is simple grayscale shader.

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

        SubShader{

            GrabPass
            {
                "_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
            }
        }
    }
}
2 Likes