Custom render target shows different result between left eye and right eye

I’m trying to add a simple custom renderer feature in urp, get the camera color target, and mix it in a forward lit shader.It works if using _CameraOpaqueTexture in shader, but if using my custom render target _GrabBlurTexture, the result is different between eyes, it seems that the uv is not auto scale and offset when Blit the render target.
Platform: Unity 2022.3.20f1, Apple VisionOS XR plugin 1.0.3, XCode 15.2
My renderer feature and render pass:

public class FrostedGlassRenderFeature : ScriptableRendererFeature
{
    [System.Serializable]
    public class Settings
    {
        public RenderPassEvent renderEvent = RenderPassEvent.BeforeRenderingTransparents;
        public Material blurMat;
    }
    public Settings settings = new Settings();

    FrostedGlassRenderPass m_ScriptablePass;
    public override void Create()
    {  
        m_ScriptablePass = new FrostedGlassRenderPass(settings);
    }

    public override void SetupRenderPasses(ScriptableRenderer renderer,
                                        in RenderingData renderingData)
    {
        if (renderingData.cameraData.cameraType == CameraType.Game)
        {
            m_ScriptablePass.ConfigureInput(ScriptableRenderPassInput.Color);
            //m_ScriptablePass.SetTarget(renderer, renderer.cameraColorTargetHandle);
        }
    }
    public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData)
    {

        m_ScriptablePass.ConfigureInput(ScriptableRenderPassInput.Color);
        if (renderingData.cameraData.cameraType == CameraType.Game)
        {
            renderer.EnqueuePass(m_ScriptablePass);
        }
    }
}

public class FrostedGlassRenderPass : ScriptableRenderPass
{
    CommandBuffer cmd;
    string m_ProfilerTag;//cmd name
    Material m_blurMat;
    RTHandle source;
    RTHandle rth_tempTex;
    RenderTextureDescriptor m_Desc;

    public FrostedGlassRenderPass(FrostedGlassRenderFeature.Settings param)
    {
        m_ProfilerTag = "FrostedGalss";
        this.renderPassEvent = param.renderEvent;
        m_blurMat = param.blurMat;
    }
    public void SetTarget(ScriptableRenderer renderer, RTHandle colorHandle)
    {
        rth_tempTex = colorHandle;
    }

    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    {
        var renderer = renderingData.cameraData.renderer;
        source = renderer.cameraColorTargetHandle;
        RenderTextureDescriptor opaqueDesc = renderingData.cameraData.cameraTargetDescriptor;
        opaqueDesc.depthBufferBits = 0;
        //opaqueDesc.msaaSamples = 1;
        opaqueDesc.vrUsage = VRTextureUsage.DeviceSpecific;
        m_Desc = opaqueDesc;
     
        RenderingUtils.ReAllocateIfNeeded(ref rth_tempTex, opaqueDesc, FilterMode.Bilinear, TextureWrapMode.Clamp, name: "_TempTex");   
    }
   
    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get();
        using (new ProfilingScope(cmd, new ProfilingSampler(m_ProfilerTag)))
        {
            Blitter.BlitCameraTexture(cmd, source, rth_tempTex,m_blurMat, 0);
            cmd.SetGlobalTexture("_GrabBlurTexture", (RenderTargetIdentifier)rth_tempTex);
        }
        //---------------------------------------------
        context.ExecuteCommandBuffer(cmd);
        cmd.Clear();
        CommandBufferPool.Release(cmd);
    }
    
    public override void OnCameraCleanup(CommandBuffer cmd) { }
    public override void FrameCleanup(CommandBuffer cmd) { }
    public void Dispose()
    {
        rth_tempTex?.Release();
        rth_Blur01?.Release();
        rth_Blur02?.Release();
    }
}

Blit Shader:

Shader "FX/SeparableGlassBlur_v2" {
    // Properties {}
    Subshader {
        Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }
        Pass {
            Name "CopyColor"
            ZTest Always 
            Cull Off 
            ZWrite Off
            HLSLPROGRAM
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            // Blit.hlsl 提供 vertex shader (Vert), input structure (Attributes) and output strucutre (Varyings)
            #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
            #pragma vertex myVert
            #pragma fragment myFrag
            struct v2f {
                float4 positionCS : SV_POSITION;//POSITION;
                float2 texcoord : TEXCOORD0;
                UNITY_VERTEX_OUTPUT_STEREO //Insert to support Single-Pass Instanced VR
            };

            v2f myVert (Attributes input) {
                v2f output;
                   
                UNITY_SETUP_INSTANCE_ID(input);
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

            #if SHADER_API_GLES
                float4 pos = input.positionOS;
                float2 uv  = input.uv;
            #else
                float4 pos = GetFullScreenTriangleVertexPosition(input.vertexID);
                float2 uv  = GetFullScreenTriangleTexCoord(input.vertexID);
            #endif

                output.positionCS = pos;
                output.texcoord   = uv * _BlitScaleBias.xy + _BlitScaleBias.zw;
                return output;
            }
            half4 myFrag (v2f i) : SV_Target {//COLOR 
                UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);//Insert to support Single-Pass Instanced VR
                half4 color = float4 (0,0,0,0);
                color += SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_PointClamp, i.texcoord);
                return color;
            }
            ENDHLSL
        }
    }
}

Forward Lit Shader:

Shader "FX/Glass/Stained BumpDistort (no grab) v2" {
    Properties {
        _BumpAmt  ("Distortion", Range (0,256)) = 125
        _TintAmt ("Tint Amount", Range(0,1)) = 0.1
        _MainTex ("Tint Color (RGB)", 2D) = "white" {}
        _BumpMap ("Normalmap", 2D) = "bump" {}
    }
    SubShader{
        Tags {  "RenderPipeline"="UniversalPipeline" "Queue"="Transparent" "RenderType"="Opaque" }
        Pass {
            Name "BASE"
            Tags { "LightMode"="UniversalForward" }
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma multi_compile_fog
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            struct appdata_t {
                float4 vertex : POSITION;
                float2 texcoord: TEXCOORD0;
                UNITY_VERTEX_INPUT_INSTANCE_ID //Insert to support Single-Pass Instanced VR 
            };
            struct v2f {
                float4 vertex : SV_POSITION;
                float2 uvbump : TEXCOORD1;
                float2 uvmain : TEXCOORD2;
                float fogFactor : TEXCOORD3;
                UNITY_VERTEX_OUTPUT_STEREO //Insert to support Single-Pass Instanced VR 
            };
            float _BumpAmt;
            half _TintAmt;
            float4 _BumpMap_ST;
            float4 _MainTex_ST;
            TEXTURE2D_X(_CameraOpaqueTexture);
            SAMPLER(sampler_CameraOpaqueTexture);
            float4 _CameraOpaqueTexture_TexelSize;
            v2f vert (appdata_t v){
                v2f o;
                UNITY_SETUP_INSTANCE_ID(v); //Insert to support Single-Pass Instanced VR 
                UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); //Insert to support Single-Pass Instanced VR 
                o.vertex = TransformObjectToHClip(v.vertex.xyz);
                o.uvbump = TRANSFORM_TEX( v.texcoord, _BumpMap );
                o.uvmain = TRANSFORM_TEX( v.texcoord, _MainTex );
                o.fogFactor = ComputeFogFactor(o.vertex.z);
                return o;
            }
            sampler2D _BumpMap;
            sampler2D _MainTex;
            float4 _GrabBlurTexture_TexelSize;
            
            TEXTURE2D_X(_GrabBlurTexture);// sampler2D _GrabBlurTexture; //Insert to support Single-Pass Instanced VR 
            SAMPLER(sampler_GrabBlurTexture);//Insert to support Single-Pass Instanced VR 
            half4 frag (v2f i) : SV_Target{
                UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);//Insert to support Single-Pass Instanced VR 
                // calculate perturbed coordinates
                // we could optimize this by just reading the x & y without reconstructing the Z
                half2 bump = UnpackNormal(tex2D( _BumpMap, i.uvbump )).rg;
                float2 offset = bump * _BumpAmt * _GrabBlurTexture_TexelSize.xy;
                float2 screenUV = (i.vertex.xy / _ScaledScreenParams.xy);
                #if UNITY_UV_STARTS_AT_TOP
                screenUV.y *= -_ProjectionParams.x;
                #endif
                screenUV  = offset * i.vertex.z + screenUV;
                half4 col = SAMPLE_TEXTURE2D_X(_GrabBlurTexture, sampler_GrabBlurTexture, screenUV);                             
                // it would work if using _CameraOpaqueTexture
                //half4 col = SAMPLE_TEXTURE2D_X (_CameraOpaqueTexture, sampler_CameraOpaqueTexture, screenUV);
                half4 tint = tex2D(_MainTex, i.uvmain);
                col = lerp (col, tint, _TintAmt);
                col.rgb = MixFog(col.rgb, i.fogFactor);
                return col;
            }
            ENDHLSL
        }
    }
}

If using _CameraOpaqueTexture:


If using _GrabBlurTexture(only right eye in screenshot, show different result in device):

I also tried unity_StereoScaleOffset, but it’s float4(0,0,0,0) in Xcode frame capture.

The problem is solved, just add cmd.SetFoveatedRenderingMode(FoveatedRenderingMode.Disabled); to disable foveated rendering

Foveated rendering is going to be important for performance.

I have a bug open that is related to this (IN-68795) that I know @mtschoen was having someone look into it.

I don’t think this means foveated rendering is disabled entirely–it just disables it for this pass. I believe this solution is correct, and you wouldn’t actually get any performance benefits from using foveated rendering on an intermediate texture like this.

Correct, not in this specific situation.
But it may be useful with other shaders, and the offset between the left and right eye is about the same offset as the bug with soft particles and others.

Yep! I was thinking the same thing. We’re still not quite sure of the root cause of the bug, but if disabling foveation is a valid workaround, that will help us narrow it down.

I faced the same problem. I had a pass to render something to a custom RT. However, from XCode, I could see that my RT got stretched. Turning off foveated rendering solved the problem. Is there any progress?

Thank you.