Created
January 20, 2018 00:39
-
-
Save positlabs/105858d67343ef6720502cf1ad038ff9 to your computer and use it in GitHub Desktop.
Unity shader for rendering shadows onto a transparent surface. Useful for augmented reality.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "ShadowShader" { | |
Properties{ | |
_Color("Main Color", Color) = (1,1,1,1) | |
_MainTex("Base (RGB)", 2D) = "white" {} | |
_Cutoff("Cutout", Range(0,1)) = 1.0 | |
} | |
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 = UnityObjectToClipPos(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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment