Created
September 16, 2014 18:18
-
-
Save empika/b3d7c9a8b3db9aa3ee9c to your computer and use it in GitHub Desktop.
Normal mapped transparent sprites with shadows
This file contains hidden or 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 "JM/Sprite Bumped Shadows" { | |
Properties { | |
_Color ("Main Color", Color) = (1,1,1,1) | |
[PerRendererData] _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {} | |
_BumpMap ("Normalmap", 2D) = "bump" {} | |
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5 | |
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 | |
} | |
SubShader { | |
Tags { | |
"Queue"="Transparent" | |
"IgnoreProjector"="True" | |
"RenderType"="TransparentCutout" | |
"CanUseSpriteAtlas"="True" | |
"PreviewType"="Plane" | |
} | |
LOD 300 | |
Lighting On | |
Cull off | |
ZWrite Off | |
Fog { Mode Off } | |
CGPROGRAM | |
#pragma surface surf Lambert vertex:vert alpha fullforwardshadows alphatest:_Cutoff | |
#pragma multi_compile DUMMY PIXELSNAP_ON | |
sampler2D _MainTex; | |
sampler2D _BumpMap; | |
fixed4 _Color; | |
struct Input { | |
float2 uv_MainTex; | |
float2 uv_BumpMap; | |
fixed4 color; | |
float3 nrmls; | |
}; | |
void vert (inout appdata_full v, out Input o) | |
{ | |
#if defined(PIXELSNAP_ON) && !defined(SHADER_API_FLASH) | |
v.vertex = UnityPixelSnap (v.vertex); | |
#endif | |
v.normal = float3(0,0,-1); | |
v.tangent = float4(1, 0, 0, 1); | |
UNITY_INITIALIZE_OUTPUT(Input, o); | |
o.color = _Color; | |
o.nrmls = v.normal; | |
} | |
void surf (Input IN, inout SurfaceOutput o) { | |
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color; | |
o.Albedo = c.rgb; | |
o.Alpha = c.a; | |
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap)); | |
} | |
ENDCG | |
} | |
FallBack "Transparent/Cutout/Diffuse" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment