I’m not having much luck getting the documentation’s vertex shader examples to compile:
For example, the UV 1 shader produced the following errors:
- GLSL vertex shader: ERROR: 0:33: " : boolean expression expected at line 5
- Shader program had errors at line 6
- Program ‘frag’, scalar Boolean expression expected at line 28
- Parse error: syntax error at line 58
Do the shaders perhaps need to be rewritten for Unity 3?
the 1st shader on that page compiles OK.
can you post the code which produces errors?
Actually, the issue seems only to occur with UV1 and UV2 shaders (the other errors were my fault):
Shader "!Debug/UV 1" {
SubShader {
Pass {
Fog { Mode Off }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// vertex input: position, UV
struct appdata {
float4 vertex;
float4 texcoord;
};
struct v2f {
float4 pos : POSITION;
float4 uv : TEXCOORD0;
};
v2f vert (appdata v) {
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
o.uv = float4( v.texcoord.xy, 0, 0 );
return o;
}
half4 frag( v2f i ) : COLOR {
half4 c = frac( i.uv );
if( saturate(i.uv) != i.uv )
c.b = 0.5;
return c;
}
ENDCG
}
}
}
ok, now I am also interested in knowing why this doesn’t compile
Strange… I’m very new to Cg - is vector comparison an uncommon thing to do in a shader, or have I just hit a weird edge case?
I’ve stripped the shader down to the simplest test case:
Shader "!Debug/VectorComparison" {
SubShader {
Pass {
CGPROGRAM
#pragma exclude_renderers gles
#pragma fragment frag
half4 frag() : COLOR {
if( half4(1,0,0,0) == half4(1,0,0,0) )
return 1;
return 0;
}
ENDCG
}
}
}
Maybe a bit late, but CG won’t do vector comparison.
You can work around by just do:
float3 myFloat1 = float3(1.0f, 0.0f, 0.0f);
flaot3 myFloat2 = float3(1.0f, 0.0f, 0.0f);
if (myFloat1.r == myFloat2.r && myFloat1.g == myFloat2.g && myFloat1.b == myFloat2.b) {
// This should work
}
1 Like