How to sample a foveated rendering rendertexture?

I have a feature that it renders some effect to a screen-space rendertexture. However, I find that if I turn on foveated rendering, the RT looks like distorted and I cannot sample it by normal screen-space coordinate.

How can I sample the RT?

Which platform you are running the foveated rendering? Some platform may distort the RT and you may want to remapping the uv when sampling. We provided several remapping functions for uv conversion in core package that could be helpful:

One nuance is that for most of the blitting usecase, we do not need to remap uv. So each use case should be evaluated separately.

I am running my project on visionOS.
I am using cmd.DrawRenderers to draw things on a RT.
I have tried use the code below, but it does not work:

float3 uv = i.vs_TEXCOORD0.xyz / i.vs_TEXCOOD0.w;
uv = UnityStereoTransformScreenSpaceTex(uv.xy);
#if defined(SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
UNITY_BRANCH if (_FOVEATED_RENDERING_NON_UNIFORM_RASTER)
{
uv= RemapFoveatedRenderingNonUniformToLinear(uv);
}
#endif

I also found that cmd.SetFoveatedRenderingMode(FoveatedRenderingMode.Disable) does not work for cmd.DrawRenderers(I have tried it does work for Blitter.Blitcameratexture). It always draw a distorted image.

I found that the keyword “SUPPORTS_FOVEATED_RENDERING_NON_UNIFORM_RASTER” is not set to 1 on visionOS?

Oh my god. I’ve solve the problem. If I use SV_POSITION.xy / _ScaledScreenParams, the result is correct. If I use Unity built-in ComputeScreenPos, the result is wrong.

Now I am facing another problem. It seems like if I down-sample my RT, the result becomes incorrect. I am now using SV_POSITION.xy / _MY_RT_TexelSize.zw. The result is correct on Editor but incorrect on visionOS.

I feel that Unity really lacks some documentation for VR related rendering.