- Home /
Simple Cg shader not compiling
I'm starting with cg shaders so I want to implement a simple one.
Heres my code:
Shader "Custom/MyShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
struct Input {
float2 uv_MainTex : TEXCOORD0;
float4 transp : COLOR;
};
void surf (Input aInput, inout SurfaceOutput o) {
float4 c = tex2D(_MainTex, aInput.uv_MainTex) * aInput.transp;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
If I delete " * aInput.transp" from the first line in surf, it compiles. I don't know why I can't multiply those values. Aren't they both float4?
The errors I get in the console are > Shader error in 'Custom/$$anonymous$$yShader': Program 'frag_surf', expression left of ."color" is not a struct or array at line 87 > Shader error in 'Custom/$$anonymous$$yShader': Program 'vert_surf', expression left of ."color" is not a struct or array at line 87
Is that what you get?
Answer by GrahamReeves · Apr 10, 2014 at 02:29 PM
I think there is a bug in the surface-shader compiler. (I'm using unity 4.5)
If you rename transp to color, it compiles without any trouble. (providing you're getting the error I was)
Your answer
![](https://koobas.hobune.stream/wayback/20220613142253im_/https://answers.unity.com/themes/thub/images/avi.jpg)