Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Producing odd double-image using Blit with Steam VR Camera

Discussion in 'AR/VR (XR) Discussion' started by Klaviam, Apr 25, 2020.

  1. Klaviam

    Klaviam

    Joined:
    Apr 28, 2018
    Posts:
    1
    Hi. I'm attempting to render an underwater shader over the top of the eyes of Steam VR camera. The effect actually works and renders properly, however the stereoscopic image is doubled in both eyes, thereby removing any depth. Take a look at the images to see what I mean. The first image is a non-VR camera using the same script and material. The 2nd is using Steam VR's camera. FYI, I'm using Unity 2019.2.17f1 and SteamVR v2.5. I've also set Single Pass for the Stereo Rendering Mode. I'm not too well versed with the VR rendering pipeline, so I'd appreciate greatly for any help.

    This is the script for adding a material to the camera render. It's attached to the game object with the camera component:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.XR;
    4. using Valve.VR;
    5.  
    6. [ExecuteInEditMode]
    7. [RequireComponent(typeof(Camera))]
    8. public class CameraOverlay : MonoBehaviour
    9. {
    10.     public Material effectMaterial;
    11.  
    12.     void OnRenderImage(RenderTexture src, RenderTexture dst)
    13.     {
    14.         Graphics.Blit(src, dst, effectMaterial);
    15.     }
    16.  
    17.     /*private void OnRenderImage(RenderTexture source, RenderTexture destination)
    18.     {
    19.         RenderTextureDescriptor desc;
    20.         if (XRSettings.enabled)
    21.             desc = XRSettings.eyeTextureDesc;
    22.         else
    23.             desc = new RenderTextureDescriptor(Screen.width, Screen.height); // Not XR
    24.  
    25.         RenderTexture rt = RenderTexture.GetTemporary(desc);
    26.         Graphics.Blit(source, rt, effectMaterial, 0);
    27.         Graphics.Blit(rt, destination, effectMaterial, 1);
    28.         RenderTexture.ReleaseTemporary(rt);
    29.     }*/
    30. }
    This is the script for the underwater shader:
    Code (CSharp):
    1. Shader "Hidden/BlackOverlayShader"
    2. {
    3.    Properties
    4.    {
    5.        _MainTex("Texture", 2D) = "white" {}
    6.        _DisplaceTex("Displacement Texture", 2D) = "white" {}
    7.        _Magnitude("Magnitude", Range(0,0.1)) = 1
    8.    }
    9.    SubShader
    10.    {
    11.        // No culling or depth
    12.        Cull Off ZWrite Off ZTest Always
    13.  
    14.        Pass
    15.        {
    16.            CGPROGRAM
    17.            #pragma vertex vert
    18.            #pragma fragment frag
    19.  
    20.            #include "UnityCG.cginc"
    21.  
    22.            struct appdata
    23.            {
    24.                float4 vertex : POSITION;
    25.                float2 uv : TEXCOORD0;
    26.            };
    27.  
    28.            struct v2f
    29.            {
    30.                float2 uv : TEXCOORD0;
    31.                float4 vertex : SV_POSITION;
    32.            };
    33.  
    34.            v2f vert(appdata v)
    35.            {
    36.                v2f o;
    37.                o.vertex = UnityObjectToClipPos(v.vertex);
    38.                o.uv = v.uv;
    39.                return o;
    40.            }
    41.  
    42.            sampler2D _MainTex;
    43.            half4 _MainTex_ST;
    44.            sampler2D _DisplaceTex;
    45.            float _Magnitude;
    46.  
    47.            float4 frag(v2f i) : SV_Target
    48.            {
    49.                float2 disp = tex2D(_DisplaceTex, i.uv).xy;
    50.                disp = ((disp * 2) - 1) * _Magnitude;
    51.  
    52.                float4 col = tex2D(_MainTex, i.uv + disp);
    53.                return col;
    54.            }
    55.            ENDCG
    56.        }
    57.    }
    58. }
     

    Attached Files:

    • 1.JPG
      1.JPG
      File size:
      166.9 KB
      Views:
      352
    • 2.JPG
      2.JPG
      File size:
      81.7 KB
      Views:
      358
    Last edited: Apr 25, 2020
    kevinbrandt likes this.