- Home /
Material doesn't have a color property '_Color'
I have been following a tutorial on how to code shaders and I have run into an odd problem which the Tutorial poster does not have, even though I checked for typos about 10 times and m eyes are starting to hurt. Could anyone look at my code and check if they can find what i did wrong ?
Shader "Shaders/2 - Lambert" { //Shader Path
Properties { //Define any changeable properties here
_Color ("color", Color) = (1.0,1.0,1.0,1.0) //Color property
}
SubShader { //Main Shader
Pass {
Tags { "LighMode" = "ForwardBase" }
CGPROGRAM
//pragmas
#pragma vertex vert
#pragma fragment frag
//User defined variables
uniform float4 _Color;
//Unity defined variables
uniform float4 _LightColor0;
//Base input structs
struct vertexInput{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct vertexOutput{
float4 pos : SV_POSITION;
float4 col : COLOR;
};
//vertex function
vertexOutput vert(vertexInput v){
vertexOutput o;
float3 normalDirection = normalize( mul( float4( v.normal, 0.0 ), _World2Object ).xyz );
float3 lightDirection;
float atten = 1.0;
lightDirection = normalize( _WorldSpaceLightPos0.xyz );
float3 diffuseReflection = atten * _LightColor0.xyz * max( 0.0, dot(normalDirection, lightDirection) );
o.col = float4(diffuseReflection, 1.0);
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
//fragment function
float4 frag(vertexOutput i) : COLOR
{
return i.col;
}
ENDCG
}
}
//loads Diffuse in case the Shader doesn't get loaded
//Fallback "Diffuse"
}
Thanks in advance
Edit: exact error message: Material doesn't have a color property '_Color' UnityEditor.HostView:OnGUI()
Edit: for some reason getting another error message now: rc.right != m_GfxWindow->GetWidth() || rc.bottom != m_GfxWindow->GetHeight()
Please do not edit your question to include the solution. This site is designed around cataloging questions multiple users may have, and possible answers including the specific one that worked for you. The intent is to keep the same questions from being asked over and over, even if it's a solved problem for you. TL;DR: this is not your problem, it's the community's; so please leave your question in its near-original form for the benefit of others.
Further discussion re. this error message on the forums: http://forum.unity3d.com/threads/solved-material-doesnt-have-a-color-property-_color.31326/
Answer by nesis · Mar 06, 2014 at 01:50 PM
I think your "color" needs to be "_Color" on line 3? The _Color property name is used internally in the shader, whereas the bit in quotes is used for accessing that property via Material.GetColor("_Color") or Material.SetColor("_Color",someColor).
Answer by JohnWatson · Mar 06, 2014 at 03:15 PM
So I restarted my computer and both my error messages are gone but the lighting still doesn't update here's a link to the video I'm referencing off: 12:49
This area is reserved for answers. If you have something to add, edit your question. Don't submit it as an answer.
Answer by DaleJulian · Jan 14, 2015 at 06:11 AM
Tags { "LighMode" = "ForwardBase" }
Should be LightMode.
Answer by sri106 · Feb 15, 2015 at 04:53 PM
Actually material have not any colour property,but it has tendency to absorb or reflect the colour of light we can see the colour of the material which light is reflected by material.if a material is in white colour that means the all colour is reflecting by the material