Hello everyone. I’ve run into an issue with a Custom Sprite Lit shader that i have no idea how to solve, and I’m posting out of desperation.
My goal is to use the 2D Lighting System with one lightmap for regular lights, and a second lightmap for a “Fog of War” effect, where enemy sprites outside of these light sources are invisible, and enemies inside are visible.
The reason i’m not just using a sprite mask for this is that I want enemies to also be hidden by the shadows projected by Shadowcasters, so i need to use the light simulation. In summary:
Lightmap 1: the base color of sprites is multiplied by the color of this lightmap
Lightmap 2: the alpha of sprites is lowered the less intense this lightmap is
I have achieved the desired effect by writing a Custom Sprite Lit Shader Graph, but there’s an issue with normal maps that i can’t wrap my head around. Here’s a screenshot of the shader:
I hope everything is readable.
And here’s a screenshot of the shader in action:
Every sprite in this scene is using a material with the above shader. The 3 blocks in the middle have “UsesFogOfWar” set to true.
The 2 regular lights (blue and orange) are correctly illuminating the floor tiles and the wall on the right (2 Tilemaps), and interacting with normal maps.
There’s also an invisible Fog of War light that is exposing the 2 blocks inside its area.
Unfortunately, it appears that the normal maps of the floor are bleeding trough the blocks, and also the normal map of the blocks is not being hidden outside the Fog of War light.
Bizarrely, if i set “UsesFogOfWar” to false on the material of the 3 blocks, the normal map bleeding stops:
Of course, the Fog of War effect stops as well, and all 3 blocks become fully visible.
So the issues are:
- Why is the normal map of the blocks visible OUTSIDE the Fog of War light?
I am hard setting the alpha to 0, so i don’t see how any colors should be visible at all, unless Unity is doing some secret normal map calculations after my shader executes, and adding the extra color on top at the end.
I can’t even manipulate the alpha of the normal map depending on the Fog of War lightmap, because the Normal block in the Fragment only takes RGB, it has no alpha. There’s no way to fade the normal map out, or change its “strength”. The “Normal Strength” node would only make it more neutral, which would still leave it visible when lights are directly above. - Why are the normal maps of the floor showing up ABOVE the blocks? and ONLY when UsesFogOfWar is true? It feels like i’m doing something that is screwing with Unity’s ability to surmise the correct draw order.
I’ve played around with Alpha Clipping, which in theory should help me hide pixels outside the FOW light and solve problem 1, but it also appears to completely disable all normal maps on the object, for some reason.
I’m open to any and all suggestions, and I apologize if I missed something simple. I’m a beginner and I have no idea what I’m doing.
I’m using Unity 6.3.0f1.
Thanks








