- Home /
Transparent w/ Full Shadowcasting in Unity 5
Hey guys! I'm trying to get this shader that worked in 4.x to work in 5, but I'm not having much luck.
What it does is, it allows transparent objects to cast shadows from directional lights and etc. I use it for roofs of houses and such as my game is a top-down game with day/night cycles; when the player walks into a building there is a trigger that disables the mesh renderer on the actual roof and enables the renderer on a clone with this shader applied.
It worked fine in Unity 4.x, but in 5.x the alpha slider no longer works; the object does seem to cast shadows properly but it will not go transparent with alpha. I'm not great with shaders, I borrowed this one from the Unity forums a long time ago. It seems that Unity's shader structure has changed significantly with 5.x; anyone know how I can resolve it?
Thanks!
Shader "Transparent/Diffuse with Shadow" {
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"
}
Answer by Dover8 · Aug 27, 2015 at 09:31 AM
Came across the same issue, though my shader was slightly different to begin with. I'm also doing the opposite of you (casting shadows ONTO transparent objects), but I think this solution will work for you.
After your last line of the surface shader, try clipping values below a threshold, ie:
o.Alpha = c.a;
clip (o.Alpha - 0.01);
Hey Dover8,
I am looking for a transparent material that receives shadows. Have you been able to successfully do it? If so, would you share the shader code?