Masked material no shadows from directional light

I created for my player mesh a masked material which fades away if the camera is close to it.

However I noticed that my mesh is only casting shadows from point or spotlights:

I checked every lightning settings on my skeletal meshes but to no avail. Increasing the shadow resolution of the directional light or far shadows, cascaded shadow maps didn’t help either.

The odd thing is, I have masked cloud particles in the sky, which do cast masked shadows from the sun:

Hi ,

What is your Directional Lights mobility? If it’s set to Stationary (default) make sure that the Dynamic Shadow Distance StationaryLight value is anything above 0 (default).

Let me know.

Tim

Hi Tim,

my sun light is set to ‘moveable’. It is a directional light component of my time of day manager. I tried your suggestion but that didn’t help. Can you reproduce this issue? For my masked material I used this simple setup:

For the life of me I can’t find the project where I had set this up before, and the colleague that helped me with the material is out until next week. However, I do have a second method that would produce better results than what that would have anyway.

So with DitheredTemporalAA there is a way to do it from what I recall that would require a sine node at a high enough rate that it was able to shadow, but for your needs you could easily get away with just using a second skeletal mesh and setting it to not be visible. Then under the lighting tab you can set hidden shadow to true. Since the second mesh will not be visibly rendered you can use a lower poly version if you need, since you would only care about the shadows being cast.

1 Like

Yes that would be a possible workaround, thank you. However it would be great to avoid this presetup as I intended to use this shader for many different objects.

I noticed something new:

I set in the Camera Depth Fade node the pin For Vertex Shader to true. This actually made it possible to have shadows from a directional light source, but under strange condition:

The shadow vanishes if my camera is facing towards the sun (-LightDir). As I rotate the camera more towards the light direction, the shadows reapper. Please notice the semi shadows of the dog in the second picture as the camera is almost orthogonal to the light direction.

I have absolutly no clue why this happens. I guess it could be a bug.

Edit: For now I have replaced the camera depth node with a simple distance from the object position to the camera position. This method works fine. But I still find the mentioned behaivour with the depth node strange.

Thanks for your help Tim!

Found a fix to this, mate?

I used the workaround mentioned in my last comment with bold font, which worked good enough for me.

1 Like

There is a bug when using pixel depth node which prevents from casting shadows (camera depth node internally uses the pixel depth node). Please have a look here: Opacity Mask Shadow with Pixel Depth Problem - Rendering - Epic Developer Community Forums

I managed to fix this by using the following node setup:

1 Like

The bug also includes use of the Noise node. A workaround for that one I’ve found is to use an online tool to generate a noise map and use it as a texture. Alternatively, I’ve found that some of the noise modes (functions) don’t cause this bug (so far i’ve only found “value- computational” to work).

This comment here helped me with my light baking issues. However, Now i am having shadows baked for objects that are meant to invisible. Anyone else have this problem?