Strange Shadow Behavior

Recently I switched to the compute shader build of Monogame and am having some struggles with converting some of my shaders.

I have a shadow shader that is working, but also seems to have some inverse behavior that doesn’t make sense to me. I am creating the shadowmap with my terrain only, and then drawing the shadows from that shadowmap. When I draw them to the terrain, it works exactly as expected. When I draw them to the secondary sphere that I’m using as water, it works half as expected, but then appears to invert the shadow calculation from the opposite direction of the light as well, so it will cast a shadow from that perspective unless there is something blocking the shadow, like raised terrain.

Here is the code for the water shader:

Here is the code for generating the shadowmap:

The image I’ve included shows what I’m referring to. The green lines show the correct shadow being cast to the water sphere correctly, but the red outlines and arrows show shadows being cast from the opposite direction and being blocked by some terrain. If I were to raise terrain behind any of those shadows, it will also remove those shadows, but there shouldn’t be any there in the first place. I’m not sure what would cause this as it didn’t happen with sm3 and there is very little difference in the shader from sm3. I would just compile it to sm3 but trying to get everything working with newer shader models.

If anyone has ran into this or has some suggestions for me, I would be happy to hear. Thanks!

Was able to fix this by drawing the water sphere to the shadowmap as well.

1 Like