Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Cameras target texture(output texture) gets morphed when rotating camera in VR

Discussion in 'VR' started by matejaizverieas, Aug 14, 2021.

  1. matejaizverieas

    matejaizverieas

    Joined:
    Jan 3, 2019
    Posts:
    5
    Hello, I've been following brackys portal video, only I'm trying to do it in VR on the quest 2.



    The issue I have is when I'm turning my head the portal texture get morphed as seen in the video



    I've noticed that removing this shader, made in shader graph, there is no more morphing, so I assume that the fault is in this shader: upload_2021-8-14_2-16-33.png
     
  2. NevinAF

    NevinAF

    Joined:
    May 12, 2021
    Posts:
    36
    (I've created portals before but I've gone at it a little more complex, so to the best of my knowledge: )

    Try adding a Tracked Pose Driver to the second camera (this will make the second camera render for vr).
    Haven't seen all the tutorial, but it might be useful to instead use Camera.CopyFrom to get the other scene cameras to render the exact same as the VR camera.

    If this does not work, take a look at Single Pass Stereo rendering (Double-Wide rendering): https://docs.unity3d.com/Manual/SinglePassStereoRendering.html
    In VR (Single Pass), the render texture is actually twice as wide as a normal render texture (left and right eye). There is a section in this link (Adding Single Pass Stereo rendering support to Shaders) that guides through how to convert normal UV to double-wide UVs when sampling in shaders, but I'm not sure if this is still a problem when rendering with shader graph
     
    Last edited: Aug 15, 2021
  3. matejaizverieas

    matejaizverieas

    Joined:
    Jan 3, 2019
    Posts:
    5
    Thanks for the reply. I tried adding the Tracked Pose Driver, but it didn't change anything. So I tried editing the shader script from Brakeys video by following your provided link, but without any change to the texture morphing. I'm still very new to the shader thing, so I'm not sure I did it correctly, but here's the shader code

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. Shader "Unlit/ScreenCutoutShader"
    4. {
    5.     Properties
    6.     {
    7.         _MainTex ("Texture", 2D) = "white" {}
    8.     }
    9.     SubShader
    10.     {
    11.         Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
    12.         Lighting Off
    13.         Cull Back
    14.         ZWrite On
    15.         ZTest Less
    16.      
    17.         Fog{ Mode Off }
    18.  
    19.         Pass
    20.         {
    21.             CGPROGRAM
    22.             #pragma vertex vert
    23.             #pragma fragment frag
    24.          
    25.             #include "UnityCG.cginc"
    26.  
    27.             struct appdata
    28.             {
    29.                 float4 vertex : POSITION;
    30.                 float2 uv : TEXCOORD0;
    31.             };
    32.  
    33.             struct v2f
    34.             {
    35.                 //float2 uv : TEXCOORD0;
    36.                 float4 vertex : SV_POSITION;
    37.                 float4 screenPos : TEXCOORD1;
    38.             };
    39.  
    40.             v2f vert (appdata v)
    41.             {
    42.                 v2f o;
    43.                 o.vertex = UnityObjectToClipPos(v.vertex);
    44.                 o.screenPos = ComputeScreenPos(o.vertex);
    45.                 return o;
    46.             }
    47.  
    48.          
    49.             sampler2D _MainTex;
    50.             half4 _MainTex_ST;
    51.  
    52.             fixed4 frag(v2f i) : SV_Target
    53.             {
    54.                 i.screenPos /= i.screenPos.w;
    55.          
    56.                 fixed4 col = tex2D(_MainTex, UnityStereoScreenSpaceUVAdjust(float2(i.screenPos.x, i.screenPos.y), _MainTex_ST));
    57.              
    58.  
    59.                 return col;
    60.             }
    61.             ENDCG
    62.         }
    63.     }
    64. }
    65.  
    .
    I also have another script that creates and adds a texture to the material :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PortalTextureSetup : MonoBehaviour
    6. {
    7.     public Camera cameraB;
    8.     public Material cameraMatB;
    9.  
    10.     void Start()
    11.     {
    12.  
    13.         if(cameraB.targetTexture != null)
    14.         {
    15.             cameraB.targetTexture.Release();
    16.         }
    17.  
    18.         cameraB.targetTexture = new RenderTexture(Screen.width, Screen.height, 24);
    19.         cameraMatB.mainTexture = cameraB.targetTexture;
    20.      
    21.     }
    22.  
    23.  
    24. }
    25.  
    Also from what I understand, the current Oculus integration version that I'm using has Singel Pass Stereo Rendering under a different name called Multiview.
     
    Last edited: Aug 16, 2021
  4. Sheynes

    Sheynes

    Joined:
    Mar 27, 2017
    Posts:
    66
  5. Sheynes

    Sheynes

    Joined:
    Mar 27, 2017
    Posts:
    66