Search Unity

Portal Shader becomes cross-eyed when using VR

Discussion in 'AR/VR (XR) Discussion' started by AlanG97, Apr 4, 2019.

  1. AlanG97

    AlanG97

    Joined:
    Feb 25, 2015
    Posts:
    5
    Hi all,
    Im having a problem getting this shader working with VR, anyone know how i can fix it?

    I am trying to make a Portal effect, used Brackeys tutorial as a start off point. I originally was using a first person character then decided that it would be pretty cool in VR. However, Once i added the OVR player controller it makes the portal look as if you are crosseyed? Anyone know how i can fix this?

    This is the shader just now:

    Code (CSharp):
    1. Shader "Unlit/ScreenCutoutShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
    10.         Lighting Off
    11.         Cull Back
    12.         ZWrite On
    13.         ZTest Less
    14.         LOD 200
    15.        
    16.         Fog{ Mode Off }
    17.  
    18.         Pass
    19.         {
    20.             CGPROGRAM
    21.             #pragma vertex vert
    22.             #pragma fragment frag
    23.            
    24.             #include "UnityCG.cginc"
    25.  
    26.             struct appdata
    27.             {
    28.                 float4 vertex : POSITION;
    29.                 float2 uv : TEXCOORD0;
    30.             };
    31.  
    32.             struct v2f
    33.             {
    34.                 //float2 uv : TEXCOORD0;
    35.                 float4 vertex : SV_POSITION;
    36.                 float4 screenPos : TEXCOORD1;
    37.             };
    38.  
    39.             v2f vert (appdata v)
    40.             {
    41.                 v2f o;
    42.                 o.vertex = UnityObjectToClipPos(v.vertex);
    43.                 o.screenPos = ComputeScreenPos(o.vertex);
    44.                 return o;
    45.             }
    46.            
    47.             sampler2D _MainTex;
    48.  
    49.             fixed4 frag (v2f i) : SV_Target
    50.             {
    51.                 i.screenPos /= i.screenPos.w;
    52.                 fixed4 col = tex2D(_MainTex, float2(i.screenPos.x, i.screenPos.y));
    53.                
    54.                 return col;
    55.             }
    56.             ENDCG
    57.         }
    58.     }
    59. }
     
  2. Untoldecay

    Untoldecay

    Joined:
    Apr 9, 2016
    Posts:
    24
    AlanG97 likes this.
  3. AlanG97

    AlanG97

    Joined:
    Feb 25, 2015
    Posts:
    5
    Hi @Untoldecay , I downloaded your portal project from the link you provided and when i ran it, it still had the cross eyed problem I am explaining. How have you got your VR settings set up? Are you using monoscopic or stereoscopic, single pass or multiPass, etc?
     
    Last edited: Apr 4, 2019
  4. Untoldecay

    Untoldecay

    Joined:
    Apr 9, 2016
    Posts:
    24
    Hey @AlanG97 I'm using MultiPass stereo rendering method and on the OVRcameraRig, I have enabled the "use one per eye" setting. In Other settings under Player settings my minimum level API si Android 5.0, and the target API level is set on the highest installed.

    I hope this will help.
     
    AlanG97 likes this.
  5. AlanG97

    AlanG97

    Joined:
    Feb 25, 2015
    Posts:
    5
    What VR headset are you using?
     
  6. Untoldecay

    Untoldecay

    Joined:
    Apr 9, 2016
    Posts:
    24
    Oculus GO.
    I mentioned it in the title of the post I shared to you.

    I hope my process will help you at least.
    Did you set 2 rendertextures overlapping with one camera per eye in your project?