Hi, I am trying to compile a simple surface shader and I am getting this error: "Shader error in 'Custom/TestShader': redefinition of '_MainTex_ST' at line 52 (on d3d11)". Code below: Code (CSharp): Shader "Custom/TestShader" { Properties{ _MainTex("Texture", 2D) = "white" {} } SubShader{ Tags { "RenderType" = "Opaque" } CGPROGRAM #pragma target 3.0 #pragma surface surf Standard #include "UnityStandardInput.cginc" //sampler2D _MainTex; struct Input { float2 uv_MainTex; }; void surf(Input IN, inout SurfaceOutputStandard o) { o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb; } ENDCG } } I know I could declare the variable _MainTex but I really need to use "UnityStandardInput.cginc" (this is a simplified shader of a bigger one I am working atm). Is there a workaround for that or this is how it should behave? Thanks for your time
What do you need UnityStandardInput.cginc for? The two aren’t really compatible because Surface Shaders automatically add the _ST variables for texture UVs defined in the Input struct, and the UnityStandardInput.cginc also has it, hence the error. There are some solutions I can think of though. Brute force Copy whatever code you need from the cginc into your shader. Custom UVs Don’t use “uv_MainTex”, instead use a custom named value like “tex_MainTex” or “Fred”, really anything that doesn’t start with “uv_” as that’s what causes the surface shader to add the _ST uniform. Then you have to set that value with a vertex function. Code (csharp): #pragma surface ... vertex:vert struct Input { float2 Fred; }; void vert (inout appdata_full v, out Input o) { UNITY_INITIALIZE_OUTPUT(Input,o); o.Fred = TRANSFORM_TEX(v.texcoord, _MainTex); } #undef I don’t know if this one will work, but you might be able to use #undef _MainTex_ST either before or after the #include to make it work. It’s not really how #undef is intended to be used, but it’s worth a try.