UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

graphics

[URP] Fix Solid Baked Shadows on Transparent Custom Shaders

Solution

lightingshadersurprendering

Unity 2021.x - Unity 6.3.x

Published 28 days ago

Issue

Lightmapping in Unity often fails to recognize alpha clipping in custom shaders, resulting in solid rectangular shadows. This occurs because the Progressive Lightmapper specifically samples a property named _MainTex to determine transparency, ignoring custom shader logic or alternative property names like _BaseMap.

Explanation

The Unity lightmapper requires the property name _MainTex to evaluate alpha for baked shadows. If your shader uses a different property name, the baker defaults to opaque behavior.

  1. Map your transparency mask to the alpha channel of your primary texture.
  2. In your shader code or Shader Graph, ensure the primary texture property reference is named exactly _MainTex.
  3. Assign this texture to the Base Map slot on the Material inspector.
  4. Enable Alpha Clipping on the Material and adjust the threshold.
  5. Re-bake your lighting using the Lighting window.

Additional Tips

  • The _MainTex naming convention is a legacy requirement for the Progressive Lightmapper and Enlighten systems.
  • Ensure the texture import settings have Alpha Source set to Input Texture Alpha to be correctly read by the baker.
  • If using Shader Graph, check the Override Property Declaration in the Graph Inspector to ensure the internal reference is exactly _MainTex.

TL;DR

Shadow clipping issues in baked lighting are resolved by mapping the transparency mask to the _MainTex property, which the lightmapper uses for alpha evaluation.


Related Posts Haven't quite found a solution to your problem? We think these posts might help you.

Content inspired by a Unity discussion post.