I have a shader that is applied to SpriteRenderers in Built-in pipeline Unity that renders shadows + normals for sprites. The light’s interaction with the sprites in edit mode works perfectly but it has a very strange interaction in playmode. In playmode, the light only minimally affects the tiles at a lower y value. (entire level is rotated 90 degrees, a bit confusing I know). This weird interaction only happens for tiles with normals.
Note the environment is built out of tilemaps (only for the purpose of generating GameObjects to put SpriteRenderers on, the tilemap itself does no rendering), so the whole thing is re-generated at runtime. But that doesn’t matter as the same happens when I pull the tiles out of the tilemap.
Here’s a direct comparison:
There is something with the rotation of the tile relative to the light that produces this effect, but I don’t know why. Here is what I mean with a 90 degree rotation.
And here’s the shader used for this:
Shader "Custom/SpriteShadowNormal" {
Properties{
_Color("Color", Color) = (1,1,1,1)
[PerRendererData]_MainTex("Sprite Texture", 2D) = "white" {}
_Cutoff("Shadow alpha cutoff", Range(0,1)) = 0.5
_NormalMap ("NormalMap", 2D) = "bump" {}
}
SubShader{
Tags
{
"Queue" = "Geometry"
"RenderType" = "TransparentCutout"
}
LOD 200
Cull Off
CGPROGRAM
// Lambert lighting model, and enable shadows on all light types
#pragma surface surf Lambert vertex:vert addshadow
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _MainTex;
sampler2D _NormalMap;
fixed4 _Color;
fixed _Cutoff;
struct appdata_t
{
float4 vertex : POSITION;
float4 tangent : TANGENT;
float3 normal : NORMAL;
float2 texcoord : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float2 texcoord3 : TEXCOORD3;
float4 color : COLOR;
};
struct Input
{
float2 uv_MainTex;
//float2 uv_NormalMap;
fixed4 color;
};
Input vert(inout appdata_t IN, out Input OUT)
{
OUT.uv_MainTex = IN.texcoord;
OUT.color = IN.color;
return OUT;
}
void surf(Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = UnpackNormal(tex2D (_NormalMap, IN.uv_MainTex));
clip(o.Alpha - _Cutoff);
}
ENDCG
}
FallBack "Diffuse"
}
Any ideas why this is happening? I just don’t get it.