# Masked material no shadows from directional light

**URL:** <https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603>\
**Category:** Rendering\
**Tags:** Shadows, unreal-engine, masked, directional-light, question\
**Created:** [December 28, 2015, 11:29pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603 "2015-12-28T23:29:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_416b781b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_416b781b](https://forums.unrealengine.com/u/anonymous_user_416b781b)\
**Post date:** [December 28, 2015, 11:29pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/1 "2015-12-28T23:29:52Z")

</div>

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:

 ![72105-maskedshadows.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/0/ed00cb8435906861decbcf28026f6ce2b8d88dcb.jpeg)

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:

 ![72106-maskedclouds.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/1/b/91bed2c4479772eaebae67dea5df81785a05bc6f.jpeg)

---

<div class="post-metadata">

**Author:** ![Tim\_Hobson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tim\_Hobson](https://forums.unrealengine.com/u/Tim_Hobson)\
**Post date:** [December 30, 2015, 5:22pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/2 "2015-12-30T17:22:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_416b781b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_416b781b](https://forums.unrealengine.com/u/anonymous_user_416b781b)\
**Post date:** [December 30, 2015, 5:49pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/3 "2015-12-30T17:49:05Z")

</div>

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:

 ![72337-tempaamasked.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/7/c7767e86d9e64229924b5b0d0044da1b6d9b2331.jpeg)

---

<div class="post-metadata">

**Author:** ![Tim\_Hobson](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Tim\_Hobson](https://forums.unrealengine.com/u/Tim_Hobson)\
**Post date:** [December 30, 2015, 8:16pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/4 "2015-12-30T20:16:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_416b781b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_416b781b](https://forums.unrealengine.com/u/anonymous_user_416b781b)\
**Post date:** [December 31, 2015, 7:53am UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/5 "2015-12-31T07:53:56Z")

</div>

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:

 ![72395-maskedshadowbug.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/1/c/c1c70fb2368769809c3817bd770354309ff1f249.jpeg)

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!

---

<div class="post-metadata">

**Author:** ![FilipeTessaro](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/filipetessaro/32/1194666_2.png) [@FilipeTessaro](https://forums.unrealengine.com/u/FilipeTessaro)\
**Post date:** [March 16, 2016, 6:35pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/6 "2016-03-16T18:35:40Z")

</div>

Found a fix to this, mate?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_416b781b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_416b781b](https://forums.unrealengine.com/u/anonymous_user_416b781b)\
**Post date:** [March 16, 2016, 8:04pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/7 "2016-03-16T20:04:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_416b781b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_416b781b](https://forums.unrealengine.com/u/anonymous_user_416b781b)\
**Post date:** [October 6, 2016, 11:07pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/8 "2016-10-06T23:07:32Z")

</div>

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](https://answers.unrealengine.com/questions/451958/opacity-mask-shadow-with-pixel-depth-problem-1.html)

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

 ![109934-maskedshadowfix.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/1/1914bb3c003e13fec039de9645807882ad880596.jpeg)

---

<div class="post-metadata">

**Author:** ![PC-hris](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PC-hris](https://forums.unrealengine.com/u/PC-hris)\
**Post date:** [March 8, 2019, 10:02am UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/9 "2019-03-08T10:02:49Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fcff2774](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fcff2774](https://forums.unrealengine.com/u/anonymous_user_fcff2774)\
**Post date:** [March 18, 2019, 2:34pm UTC](https://forums.unrealengine.com/t/masked-material-no-shadows-from-directional-light/342603/10 "2019-03-18T14:34:13Z")

</div>

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?
