For static lighting you can use the “lightmass replace” node.
For dynamic lighting you would have to construct some kind of dot product mask that makes a hole only when the view angle matches the sun angle, but without some code tweaks there would be no way to keep it from being see-through if the player camera actually got close to the sun angle so it will not be very robust. You could possibly fix that with an additional camera position mask to see if the camera is inside of a building. There are some material functions called boxmask there are like box spheremasks.
For a long time I could not solve this problem, so that meshes with an opaque mask cast a shadow.
And recently I found a very simple solution, you just need a “Shadow Pass Switch” node.
I am writing this for those who, like me, will face the same problem.