Search code examples
unity-game-enginehlsl

unity3d odd shader bug


I've been able to update shader code (hlsl) in realtime with no issues until recently. Now whenever I hot-edit shader code the UV's bug out and I end up with an infinite mirror for every plane where my shader is attached. I've stripped my shader down to the barebones and this is still happening. I've gone as far as reverting my codebase back to a working version with no avail.

Why / how could this be happening?

  • hard setting color values works, leading me to believe it's a material / texture issue but I am not using sharedMaterial anywhere.

Windows 11 Unity version: 2021.3.8f1

barebones shader:

Shader "Custom/MapTile" {

    SubShader{

        Pass {
            HLSLPROGRAM

            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            sampler2D _MainTex;

            struct test_appdata {
                float4 pos : POSITION;
                float2 uv : TEXCOORD0;
                float4 normal : NORMAL;
            };

            struct test_v2f {
                float4 pos : SV_POSITION;
                half2 uv : TEXCOORD0;
            };

            test_v2f vert(test_appdata v) {
                test_v2f o;
                o.pos = UnityObjectToClipPos(v.pos);
                o.uv = v.uv;
                return o;
            }
            float4 frag(test_v2f i) : COLOR {
                return tex2D(_MainTex, i.uv);
            }

            ENDHLSL
        }
    }
    FallBack "VertexLit"
}

map before shader edit map after shader edit


Solution

  • It's odd that this script has even been working - the property def for _MainTex was missing

    Properties {
        _MainTex("Main Texture", 2D) = "black" {}
    }