Hey,
i am trying to implement a portal effect in vr with a rendertexture and a screenpos shader. The screenpos that is calculated seems to be off somehow. The attached image shows the issue quite well.
My setup: Main camera rendering to both eyes. Separate Camera follows the main camera and renders both eyes into a separate render texture.
RenderTextureDescriptor d = UnityEngine.XR.XRSettings.eyeTextureDesc;
t = new RenderTexture(d);
targetMaterial.SetTexture("_MainTex", t);
GetComponent<Camera>().targetTexture = t;
GetComponent<Camera>().fieldOfView = Camera.main.fieldOfView;
GetComponent<Camera>().aspect = Camera.main.aspect;
Shader code:
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.scrPos = ComputeScreenPos(o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
float2 uv2 = (i.scrPos.xy / i.scrPos.w);
uv2.y = 1 - uv2.y;
fixed4 col = tex2D(_MainTex, uv2);
return col;
}
I am using Multi-Pass VR rendering by the way. The render texture used by a sphere that is rendered with the shader directly in front of the main camera. I tested this setup without VR and it works fine.
Thank you, greetings
Florian