This is because, in Unity, surface shaders are “expanded” into vertex/fragment shaders. When this happens the necessary lightmapping variables are defined “for you”. Because of this, either you get an error for not defining them when you try to access them (during the expansion step) or you get an error for redefining them (during the final shader compile step).

2. Unity’s unity_LightmapST is misnamed

Another detail is that you must use the correct variables that Unity sets aside for passing in lightmap data:

sampler2D unity_Lightmap;
float4 unity_LightmapST;

That second variable holds the lightmaps atlas data. Its name is important because its named incorrectly. Normally variables post-fixed with

_ST will be populated by Unity with the associated shader property’s atlas. The lightmap atlas, however, leaves out the underscore. This is problematic since one of the useful transformation functions (