Hello,
I’m new to Unity’s shader system and my knowledge about writing shaders might be at beginner+ level. So I’m currently adjusting the standard code of a freshly created shader file to fit my needs. Unfortunately it causes the following compiler error:
Shader error in ‘Custom/GroundShader’:
redefinition of ‘_MainTex_ST’ at line
83 (on d3d11)Compiling Vertex program with
DIRECTIONAL SHADOWS_OFF LIGHTMAP_OFF
DIRLIGHTMAP_OFF DYNAMICLIGHTMAP_OF
It is caused by line 37. The Code works, when replacing the assignment in line 37 with the commented part behind it or when doing so in the line above.
For short, those are line 36 and 37:
float4 res = (c1 + c2 + c3 + c4) / sum; // float4 res = c1;
o.Albedo = res.xyz; //IN.color.xyz;
The Code is the following:
Shader "Custom/GroundShader" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float2 uv2_MainTex;
float2 uv3_MainTex;
float2 uv4_MainTex;
float4 color : COLOR;
};
half _Glossiness;
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
float4 c1 = tex2D (_MainTex, IN.uv_MainTex) * IN.color.r;
float4 c2 = tex2D (_MainTex, IN.uv2_MainTex) * IN.color.g;
float4 c3 = tex2D (_MainTex, IN.uv3_MainTex) * IN.color.b;
float4 c4 = tex2D (_MainTex, IN.uv4_MainTex) * IN.color.a;
float sum = IN.color.r + IN.color.g + IN.color.b + IN.color.a;
float4 res = (c1 + c2 + c3 + c4) / sum; // float4 res = c1;
o.Albedo = res.xyz; //IN.color.xyz;
o.Metallic = 0;
o.Smoothness = _Glossiness;
o.Alpha = 1;
}
ENDCG
}
FallBack "Diffuse"
}
I noticed that this could be the same issue as here: Is it possible to re-use a texture within a shader on separate uv channels?
But the answer is still lacking definite information and I thought it might be good for others to include the error message, so it is found via searching.