unity-game-engineshaderaugmented-realityhololensmrtk

Object is only visible to the left eye


I have a Unity project using MRTK.

After I changed the MRTK/Standard shader with the following shader, it only renders the object to the left eye.

How can I render the object to both eyes?

Shader "HoloUS/BrightnessContrast"
{
    Properties
    {
        _MainTex("Texture", 2D) = "white" {}
        _Width("Width", Float) = 1
        _Center("Center", Float) = 0.5
    }
    
    SubShader
    {
        Tags { "RenderType" = "Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            
            #pragma vertex vert
            #pragma fragment frag
            
            #include "UnityCG.cginc"

            struct VInp
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct VOut
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            float4 _MainTex_ST;
            float _Center;
            float _Width;

            VOut vert(VInp inp)
            {
                VOut o;
                o.vertex = UnityObjectToClipPos(inp.vertex);
                o.uv = TRANSFORM_TEX(inp.uv, _MainTex);
                return o;
            }

            fixed4 frag(VOut inp) : SV_Target
            {
                float min = _Center - _Width / 2;
                return tex2D(_MainTex, inp.uv) * _Width + min;
            }
            
            ENDCG
        }
    }
}

Solution

  • If you are using single pass vr, there are few changes in shader declaration, in order to recognise stereo texture input in single pass.

    //add this in struct appdata
    UNITY_VERTEX_INPUT_INSTANCE_ID
    
    //add this in struct v2f
    UNITY_VERTEX_OUTPUT_STEREO
    
    //replace sampler2D
    UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
    
    //add these inside v2f vert()
    UNITY_SETUP_INSTANCE_ID(v);
    UNITY_INITIALIZE_OUTPUT(v2f, o);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    

    Additional link: Single Pass Instanced rendering