Hey all, been experimenting with some realtime lighting using a single directional light, and am running into a weird issue that I can’t figure out.
Basically, I’m taking a directional light and rotating it to act as the sun, and using some 3D meshes to cast shadows (the mesh for each “tile” is a separate mesh, so they’re not all attached). However, I’m doing a couple extra things to make the effect appear how I want
→ I’m rendering the actual game through a main camera, and am using a separate camera to render the 3D “lighting” scene separately (and rendering that to a random unused render texture so that it isn’t shown on screen)
—> The video below shows the main camera, while the picture attached shows the view from the 2nd 3D only camera with the “lighting scene”
→ I’m also using a command buffer on the directional light to pass the AfterScreenspaceMask to a different render texture that I set as the mesh on a meshRenderer that follows the main game camera
m_ShadowmapCopy = new RenderTexture(Screen.width, Screen.height, 0);
tempRenderTex = new RenderTexture(Screen.width, Screen.height, 0);
this.GetComponent<Camera>().targetTexture = tempRenderTex;
RenderTargetIdentifier shadowmap = BuiltinRenderTextureType.CurrentActive;
cb = new CommandBuffer();
// Change shadow sampling mode for m_Light's shadowmap.
cb.SetShadowSamplingMode(shadowmap, ShadowSamplingMode.RawDepth);
// The shadowmap values can now be sampled normally - copy it to a different render texture.
cb.Blit(shadowmap, new RenderTargetIdentifier(m_ShadowmapCopy));
// Execute after the shadowmap has been filled.
lightHur.AddCommandBuffer(LightEvent.AfterScreenspaceMask, cb);
→ This meshRenderer has a shader that basically clips anything from this texture that isn’t shadow, and softens the alpha of the shadow so that things can still be seen behind it
float4 frag(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
clip((col.a * -1) + 0.999);
//col.a = clamp((col.a - 1) * -1 * _AlphaOfShadow, 0, 0.7);
col.a = _AlphaOfShadow;
return (col * _Color);
}
However, at certain angles of the meshes, and how the light hits them, there is this weird shadow line flickering appearing that I can’t fix by adjusting things like bias/normal bias/quality, etc. that you can see in the video below
Any help would be much appreciated! I have also tried adjusting the scale of the meshes to see if making them slightly bigger would cover the tiny seams between them, and also tried changing the shadow casting mode to 2-sided, but neither of those help

