Unity 5 unlit shadow cutout cast receive shaders

Unity unlit shaders with shadow and cutout – it can be useful:

Unlit shadow cast

Shader "UnlitShadows/UnlitShadowCast" {
Properties{ _MainTex("Base (RGB)", 2D) = "white" {} }
SubShader{ Pass{ SetTexture[_MainTex] } } FallBack "VertexLit" }

Unlit shadow cast cutout

Shader "UnlitShadows/UnlitShadowCastCutout" {
Properties{ _Color("Main Color", Color) = (1,1,1,1) _MainTex("Base (RGB)", 2D) = "white" {} _Cutoff("Cutout", Range(0,1)) = 0.5 }
SubShader{ Pass{ Alphatest Greater[_Cutoff] SetTexture[_MainTex] } } Fallback "Transparent/Cutout/VertexLit" }

Unlit shadow receive

Shader "UnlitShadows/UnlitShadowReceive" {
Properties{ _MainTex("Base (RGB)", 2D) = "white" {} }
SubShader{ Pass{ SetTexture[_MainTex] } Pass { Blend DstColor Zero Tags{ "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
struct v2f {
float4 pos : SV_POSITION; LIGHTING_COORDS(0,1) };
v2f vert(appdata_base v) {
v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o);
return o; }
fixed4 frag(v2f i) : COLOR{
float attenuation = LIGHT_ATTENUATION(i);
return attenuation;
} ENDCG } } Fallback "VertexLit" }

Unlit shadow receive cutout

Shader "UnlitShadows/UnlitShadowReceive" {
Properties{ _Color("Main Color", Color) = (1,1,1,1) _MainTex("Base (RGB)", 2D) = "white" {}	_Cutoff("Cutout", Range(0,1)) = 0.5 }
SubShader{ Pass{ Alphatest Greater[_Cutoff] SetTexture[_MainTex] }	Pass{ Blend DstColor Zero Tags{ "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#pragma multi_compile_fwdbase
#include "AutoLight.cginc"
struct v2f {
float4 pos : SV_POSITION; LIGHTING_COORDS(0,1) };
v2f vert(appdata_base v) {
v2f o; o.pos = mul(UNITY_MATRIX_MVP, v.vertex); TRANSFER_VERTEX_TO_FRAGMENT(o);
return o; }
fixed4 frag(v2f i) : COLOR{
float attenuation = LIGHT_ATTENUATION(i);
return attenuation;
} ENDCG } } Fallback "Transparent/Cutout/VertexLit" } 

2 Comments

  1. Chaos

    Hi,
    I use this in android, there are some shadows cast incorrect, is this not support android and ios?

    Reply
    1. admin Post author

      It works both, you can make small changes by your own to fix current issues.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *