- Home /
Shader with texture with alpha and casting shadows
Hi.
I want a shader that renders a texture with alpha into something in which alpha is transparent and doesn't cast shadows and opaque part of the texture are indeed opaque and cast shadows. I managed to get this next shader but it seems that the whole texture is opaque to the engine.
Shader "Custom/alphawithshadow"{
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {
"Queue"="Transparent"
"IgnoreProjector"="True"
"RenderType"="Transparent"
}
LOD 200 Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM #pragma surface surf Lambert addshadow
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
The result is:
Though the texture is transparent on some part:
I am not good with shader coding. I just started learning it.
Answer by fffMalzbier · Mar 11, 2015 at 01:26 PM
Alpha blended shader do not cast Shadows shadows. If you want shadows you have to use cutout in your shader.
You may be interested in looking into the build in cutout shader for reference They can be downloaded here: https://unity3d.com/get-unity/download/archive
Can't we get a shader which takes half opaque alpha value and transform it into a half opaque shadow? I will use Alpha cutout for the moment then.
Your answer
Follow this Question
Related Questions
Fade-In/Out shadows for a specific object 0 Answers
Adding shadows to transparent shader? 0 Answers
Toon Shader with Shadows AND Alpha? (Unity 2.6) 1 Answer
Shadows with Alpha, fade out shadow. 2 Answers