Dynamic Shadow Problems when using Distance Field Shader Functions

Glomby
Fri, 25 Sep 2020 15:02:38 +0000
Rendering

I have a lot of grass foliage in my game but since it is an RTS game the grass has to be removeable during runtime when the player starts building stuff on top.

Just removing the instanced static mesh components works but has really big impacts on performance (I have a very large landscape) so I wanted to just do it within the shader.

It is actually really easy to do using mesh distance field inputs in the grass shader but now my dynamic shadows (which I definitly need) don’t work properly.

The first (and I think best approach) is using the “DistanceToNearestSurface” Node. The problem however is even though the grass gets removed in an adjustable radius, dynamic shadow rendering won’t work at all.

The second approach ist to use the “DistanceFieldGradient” Node. i can still get the grass removed and I still get shadows rendered but shadows of the foliage that have been removed are also rendered. So I now get these dark shadowed areas even so nothing is there to cast those shadows which looks even weirder than on the screenshots.

This image shows a before and after for each method and the shader functions used. The output of this function goes straight into the opacity mask slot. This is a normal foliage shader with Material Domain set to surface, Blend Mode to Masked and Shading Model to Two Sided Foliage.

If you know a better solution to achieve this effect I would gladly use this instead. I just need to be able to remove foliage under and slightly around buildings during runtime.

4 posts - 3 participants