Custom shadow for baked lighting?

By default, the opacity mask for static shadows only works if texSample is directly connected to it. If you try to use ShadowPassSwitch or a custom function, light baking ignores it. Are there any ways to fix this? Any option works for dynamic shadows.

Not entirely sure I understand what you’re trying to accomplish but there is a lightmass replace node in the material editor