- Home /
'discard' keyword cg error
Hey all,
I'm trying to implement alpha testing in one of my shaders but am getting a strange error. When using the 'discard' keyword in the fragment shader to alpha test I get this error on compilation -
GLSL vertex shader: ERROR: 0:325: 'discard' : supported in fragment shaders only at line 24
I am definitely using the 'discard' keyword in the fragment shader and not in the vertex shader so this makes no sense to me.
Full shader source follows, thank you for any help in advance.
SubShader {
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 100
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//Global
sampler2D _backgroundLighting;
float4x4 _ProjConst;
float4 _ambientColor;
float4 _shadowColor;
//Properties
sampler2D _MainTex;
struct v2f {
float4 pos: SV_POSITION;
float2 uv : TEXCOORD0;
float4 uv2 : TEXCOORD1;
};
float4 _MainTex_ST;
v2f vert (appdata_base v) {
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
//Screen space uv
o.uv2 = mul(_ProjConst, o.pos);
return o;
}
half4 frag (v2f i) : COLOR {
half4 c = tex2D(_MainTex, i.uv);
half4 l = tex2D(_backgroundLighting, i.uv2.xy);
half4 shad = c * _shadowColor;
if(c.w < 0.5) {
discard;
}
return half4((lerp(shad, c, l.w) + _ambientColor).xyz, c.w);
}
ENDCG
}
}
Comment
Best Answer
Answer by caseyc · Jul 02, 2012 at 06:35 PM
It seems that this problem is fixed as of the new 3.5.3 update, once again great service from the unity dev team.
Your answer
![](https://koobas.hobune.stream/wayback/20220613073509im_/https://answers.unity.com/themes/thub/images/avi.jpg)