- Home /
Shadow sprite rotation regardless of the light source
Hello. Help make a shadow that appears regardless of the sprite rotation relative to the light source. The problem is that when the light source and the sprite to be in line for the Z-coordinate - the shadow of flat. I hope that it can be implemented shader. Below is a shader code and a screenshot. Thanks
Shader "Sprites/Diffuse-Shadow"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1,1,1,1)
_BumpMap("Normalmap", 2D) = "bump" {}
[MaterialToggle] PixelSnap("Pixel snap", Float) = 0
_Cutoff("Alpha Cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "TransparentCutOut"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
}
Cull Off
Lighting On
ZWrite Off
CGPROGRAM
#pragma surface surf Lambert alpha vertex:vert addshadow nofog keepalpha alphatest:_Cutoff
#pragma multi_compile _ PIXELSNAP_ON
sampler2D _MainTex;
sampler2D _BumpMap;
fixed4 _Color;
struct Input
{
float2 uv_MainTex;
float2 uv_BumpMap;
fixed4 color;
};
void vert(inout appdata_full v, out Input o)
{
#if defined(PIXELSNAP_ON)
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 = v.color * _Color;
}
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb * c.a;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
Well, Sprites are flat as you know. So this becomes tricky, I don't know the math you need to accomplish the effect in a shader. But an alternative solution might be is to create invisible 3D shadow caster objects that are part of the Sprite. Or have 3D characters that are rendered to look flat.
Your answer
Follow this Question
Related Questions
Toon shader light culling shadow issue 0 Answers
Any way to get rid of squares (artifacts) in a semi transparent shadow of a fade shader? 0 Answers
How to add shadows to surface shader? 1 Answer
Meta pass and Precomputed Realtime GI 0 Answers
How To Replicate the Untitled Goose Game Art Style? 0 Answers