Help Fixing Warnings in this Shader?

Hey everyone. I don’t know anything about writing shaders. I used Strumpy Shader Editor to make this shader, and it’s giving me a bunch of warnings. I’m using Unity 4.0.0f7. This shader is meant to blend 3 different textures based on the vertex colors of the mesh. The shader works, but gives me warnings. Here’s the shader code.

Shader "VertexColorTextureBlend" {
	Properties {
		_Texture1("_Texture1", 2D) = "black" {}
		_Texture2("_Texture2", 2D) = "black" {}
		_Texture3("_Texture3", 2D) = "black" {}
	}	
	SubShader {
		Tags {
			"Queue"="Geometry"
			"IgnoreProjector"="False"
			"RenderType"="Opaque"
		}		
		Cull Back
		ZWrite On
		ZTest LEqual
		ColorMask RGBA
		Fog {}

		CGPROGRAM
		#pragma surface surf BlinnPhongEditor  vertex:vert
		#pragma target 2.0

		sampler2D _Texture1;
		sampler2D _Texture2;
		sampler2D _Texture3;

		struct EditorSurfaceOutput {
			half3 Albedo;
			half3 Normal;
			half3 Emission;
			half3 Gloss;
			half Specular;
			half Alpha;
			half4 Custom;
		};
			
		inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light) {
			half3 spec = light.a * s.Gloss;
			half4 c;
			c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
			c.a = s.Alpha;
			return c;
		}

		inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
			half3 h = normalize (lightDir + viewDir);
				
			half diff = max (0, dot ( lightDir, s.Normal ));
				
			float nh = max (0, dot (s.Normal, h));
			float spec = pow (nh, s.Specular*128.0);
				
			half4 res;
			res.rgb = _LightColor0.rgb * diff;
			res.w = spec * Luminance (_LightColor0.rgb);
			res *= atten * 2.0;

			return LightingBlinnPhongEditor_PrePass( s, res );
		}

		inline half4 LightingBlinnPhongEditor_DirLightmap (EditorSurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor) {
			UNITY_DIRBASIS
			half3 scalePerBasisVector;
				
			half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
				
			half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
			half3 h = normalize (lightDir + viewDir);
			
			float nh = max (0, dot (s.Normal, h));
			float spec = pow (nh, s.Specular * 128.0);
				
			// specColor used outside in the forward path, compiled out in prepass
			specColor = lm * _SpecColor.rgb * s.Gloss * spec;
				
			// spec from the alpha component is used to calculate specular
			// in the Lighting*_Prepass function, it's not used in forward
			return half4(lm, spec);
		}
			
		struct Input {
			float2 uv_Texture1;
			float4 color : COLOR;
			float2 uv_Texture2;
			float2 uv_Texture3;
		};

		void vert (inout appdata_full v, out Input o) {
			float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
			float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
			float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
			float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
		}			

		void surf (Input IN, inout EditorSurfaceOutput o) {
			o.Normal = float3(0.0,0.0,1.0);
			o.Alpha = 1.0;
			o.Albedo = 0.0;
			o.Emission = 0.0;
			o.Gloss = 0.0;
			o.Specular = 0.0;
			o.Custom = 0.0;
				
			float4 Sampled2D0=tex2D(_Texture1,IN.uv_Texture1.xy);
			float4 Split0=IN.color;
			float4 Lerp0=lerp(float4( 0,0,0,0),Sampled2D0,float4( Split0.x, Split0.x, Split0.x, Split0.x));
			float4 Sampled2D1=tex2D(_Texture2,IN.uv_Texture2.xy);
			float4 Lerp1=lerp(float4( 0,0,0,0),Sampled2D1,float4( Split0.y, Split0.y, Split0.y, Split0.y));
			float4 Add0=Lerp0 + Lerp1;
			float4 Sampled2D2=tex2D(_Texture3,IN.uv_Texture3.xy);
			float4 Lerp2=lerp(float4( 0,0,0,0),Sampled2D2,float4( Split0.z, Split0.z, Split0.z, Split0.z));
			float4 Add1=Add0 + Lerp2;
			float4 Master0_1_NoInput = float4(0,0,1,1);
			float4 Master0_2_NoInput = float4(0,0,0,0);
			float4 Master0_3_NoInput = float4(0,0,0,0);
			float4 Master0_4_NoInput = float4(0,0,0,0);
			float4 Master0_5_NoInput = float4(1,1,1,1);
			float4 Master0_7_NoInput = float4(0,0,0,0);
			float4 Master0_6_NoInput = float4(1,1,1,1);
			o.Albedo = Add1;

			o.Normal = normalize(o.Normal);
		}
		ENDCG
	}
	Fallback "Diffuse"
}

And these are the warnings I’m getting…

Shader warning in ‘VertexColorTextureBlend’: Program ‘vert_surf’, implicit truncation of vector type (compiling for d3d11) at line 17

Shader warning in ‘VertexColorTextureBlend’: Program ‘vert_surf’, implicit truncation of vector type (compiling for d3d11_9x) at line 17

Shader warning in ‘VertexColorTextureBlend’: Program ‘vert_surf’, ‘vert’: output parameter ‘o’ not completely initialized (compiling for d3d11) at line 87

Shader warning in ‘VertexColorTextureBlend’: Program ‘vert_surf’, ‘vert’: output parameter ‘o’ not completely initialized (compiling for d3d11_9x) at line 87

Can anyone tell me how to fix this? I would really appreciate some help

Well I looked at the Unity docs for a little bit, and I’m starting to understand shaders now. I shortened it down to this. The errors are gone. And it’s probably faster too :slight_smile:

Shader "VertexColorTextureBlend" {
	Properties {
		_Texture1("_Texture1", 2D) = "black" {}
		_Texture2("_Texture2", 2D) = "black" {}
		_Texture3("_Texture3", 2D) = "black" {}
	}	
	SubShader {		
		CGPROGRAM
		#pragma surface surf Lambert
		#pragma target 2.0

		sampler2D _Texture1;
		sampler2D _Texture2;
		sampler2D _Texture3;
			
		struct Input {
			float2 uv_Texture1;
			float2 uv_Texture2;
			float2 uv_Texture3;
			float4 color : COLOR;
		};			

		void surf (Input IN, inout SurfaceOutput o) {				
			float4 red = lerp(float4(0, 0, 0, 0), tex2D(_Texture1, IN.uv_Texture1.xy), float4(IN.color.x, IN.color.x, IN.color.x, IN.color.x));
			float4 green = lerp(float4(0, 0, 0, 0), tex2D(_Texture2, IN.uv_Texture2.xy), float4(IN.color.y, IN.color.y, IN.color.y, IN.color.y));
			float4 blue = lerp(float4(0, 0, 0, 0), tex2D(_Texture3, IN.uv_Texture3.xy), float4(IN.color.z, IN.color.z, IN.color.z, IN.color.z));
			o.Albedo = red + green + blue;
		}
		ENDCG
	}
	Fallback "Diffuse"
}

Is there any further optimizing I can do? Since this is for Android, it needs to be fast as possible

Try replacing:

void surf (Input IN, inout SurfaceOutput o) {          
         float4 red = lerp(float4(0, 0, 0, 0), tex2D(_Texture1, IN.uv_Texture1.xy), float4(IN.color.x, IN.color.x, IN.color.x, IN.color.x));
         float4 green = lerp(float4(0, 0, 0, 0), tex2D(_Texture2, IN.uv_Texture2.xy), float4(IN.color.y, IN.color.y, IN.color.y, IN.color.y));
         float4 blue = lerp(float4(0, 0, 0, 0), tex2D(_Texture3, IN.uv_Texture3.xy), float4(IN.color.z, IN.color.z, IN.color.z, IN.color.z));
         o.Albedo = red + green + blue;
       }

with:

void surf (Input IN, inout SurfaceOutput o) {
         fixed4 c;
         c = tex2D(_Texture1, IN.uv_Texture1.xy) * IN.color.x;
         c += tex2D(_Texture2, IN.uv_Texture2.xy) * IN.color.y;
         c += tex2D(_Texture3, IN.uv_Texture3.xy) * IN.color.z;
         o.Albedo = c;
       }

though I cant say it’s super fast now :slight_smile: