- Home /
I create a cutout shader do not cut shadow!!!
Hello, guys. I created a cutout shader use for my game character, but the shadow do not cutout. look this:
Properties{
_AT ("Alphatest_Cutoff", Range(0, 1)) = 0.5}
SubShader{
Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
Cull off
ZWrite On
ZTest LEqwal
Color$$anonymous$$ask RGBA
CGPROGRA$$anonymous$$
#pragma surface surf BlinnPhongEditor vertex:vert Alphatest:_AT
#pragma exclude_renderers gles
#pragma target 3.0
Fallback"Transparent/Cutout/Diffuse"
The left object in photo is used transparent/cutout/bump specular.It is right.
There is no cutout happening in that cutout shader by the look of things, where is the surf function? The _AT function?
Thank you for your answer~~~ whtdoidoit I have Properties { _AT ("AlphaTest_Cutoff", Range(0, 1)) = 0.5 } If i change _AT to _Cutout, they are the same result.
Answer by Matou · Oct 24, 2014 at 02:18 PM
A bit late but maybe this can help:
As said above, you must add a fallback shader like
Fallback "Transparent/Cutout/Diffuse"
BUT you also have to rename your "_AT" parameter in "_Cutoff" (case-sensitive!) because the fallback shader uses a "_Cutoff" parameter to compute shadows. For the same reason, you may have to add a "_Color" parameter too. I think the shadow computation part uses the alpha component of the "_Color" parameter to weight the fragment alpha output.
If you don't define those parameters or you use the wrong names, the shadow computation won't work correctly.
It took me very long to understand that. And I never saw this written anywhere in Unity doc... I had to make lots of experiment to finally get it...
Peace :)
you could also copy the shadow pass from another shader if you don't feel like exposing _Color or _Cutoff. "Legacy Shaders/Transparent/Cutout/VertexLit" for example, where you can see the actual computation and why those parameters are needed:
float4 frag( v2f i ) : SV_Target
{
fixed4 texcol = tex2D( _$$anonymous$$ainTex, i.uv );
clip( texcol.a * _Color.a - _Cutoff );
SHADOW_CASTER_FRAG$$anonymous$$ENT(i)
}
Answer by cod · Sep 11, 2013 at 10:30 AM
try to put at the end of the shader
Fallback "Transparent/Cutout/Diffuse"
If I am right this should let your shader cast the right shadow, as it takes the shadow casting codes from it
I hope this helps and let me know if it works :)
Thank you $$anonymous$$r.cod. I only a little Chinglish. Hah ha. 1st: I have used this"Fallback"Transparent/Cutout/Diffuse"", it is no use for this shader. 2nd: I also used Tags{"Light$$anonymous$$ode"="ShadowCaster"}, the shadow will be ok, but the material appears black, it is looks like no light.
Answer by freddyhuu · Sep 12, 2013 at 06:58 AM
When i use projector shadow , it is all right. But it is no best way.