Object is only visible to the left eye

Viewed 85

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
        }
    }
}
2 Answers

For shaders with Hololens and MRTK2, there is an upgrade path perhaps that needs to be clicked through: https://docs.microsoft.com/en-us/windows/mixed-reality/mrtk-unity/mrtk2/features/rendering/mrtk-standard-shader?q=shader&view=mrtkunity-2022-05

Also, Unity defines following on stereo rendering for HoloLens for shader script requirements: https://docs.unity3d.com/Manual/SinglePassStereoRenderingHoloLens.html

From version of Unity, could not tell the specific version and MRTK version using in sample above. If have further details, perhaps can assist further too with community.

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

Related