- Home /
CGProgram Shader Broken in Unity 4?
Am learning how to make custom shaders in Unity 4.3.4. free version. I've been following the tutorials by Unity Cookie and they are fairly simple and straightforward. My code is exactly the same as his (for the part I'm at in the video - 8:00), except I changed "v" to "input" and "o" to "output." In his video, it shows the shader working just fine, but I keep getting bizarre and unexplainable errors. I've checked this code over several times, even using Reimport and still nothing.
Some of the errors I keep getting are:
Material doesn't have a color property '_Color'
Shader error in 'Marushia Dark/Beginner/ 2 - Lambert': Shader program had errors at line 9
Shader error in 'Marushia Dark/Beginner/ 2 - Lambert': Program 'frag', struct "vertexInput" previously defined at (23) at line 27
Shader error in 'Marushia Dark/Beginner/ 2 - Lambert': Program 'vert', syntax error, unexpected '(' at token "(" at line 31
In a previous version, with the exact same code, I didn't get all these errors, but I did get an error at Line 8, which is the CGProgram line. I've heard that it should be placed outside the Pass, but this makes no sense to me, since I have other working shaders that put it INSIDE the Pass.
Again, not sure what the problem is. I've formatted it almost the exact same way as another shader that IS working, so I'm not understanding these errors.
Shader "Marushia Dark/Beginner/ 2 - Lambert" {
Properties {
_Color ("Base", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert //Line 9
#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 vertexInput{
float4 vertex : SV_POSITION;
float4 col : COLOR;
}; // Line 27
// Vertex Function
vertexOutput vert(vertexInput input){ // Line 31
vertexOutput output;
output.col = float4(input.normal, 1.0);
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
return output;
}
// Fragment Function - This part still not finished, but should at least work.
float4 frag(vertexOutput i) : COLOR
{
return i.col;
}
ENDCG
}
}
// Fallbacks
// FallBack "Diffuse"
}
Thank you. This seems to have helped ... for now. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613150124im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Parse error: Syntax Error in compiled shader, Unity 4.3.1 [free] 1 Answer
Shaders #pragma exclude 1 Answer
Shaders: Constant register limit exceeded - what does it mean? 2 Answers
Additional blending when using properties rather than hard-coded values for colors 0 Answers
Apply shader to a sprite. 3 Answers