Mask fog to only be vissible above surface

I am creating a fog of war material, using a volumetric fog material in a cube. In order for the actuall fog of war to work, the mesh needs to lay on the map. But if the fog is for the first floor for example, you dont want to see the fog on the outside of the building in the air, thats problem number 1. Number 2 is, i want the fog to “lay” on the ground, so it also works on stairs.

I think the best way to solve this would be to only show the fog 1 meter above a surface. I’m thinking of the distance to nearest surface node, but I didn’t figure out yet, how I can filter it that way, that it only shows the fog above a mesh, not next to it or someting.
Any idea how to fix this? Would be a great help :slight_smile:


This is currently my masking