# DistanceToNearestSurface material node disables shadows from masked materials.

**URL:** <https://forums.unrealengine.com/t/distancetonearestsurface-material-node-disables-shadows-from-masked-materials/442410>\
**Category:** Rendering\
**Tags:** Shadows, unreal-engine, masked, question\
**Created:** [January 30, 2019, 9:06pm UTC](https://forums.unrealengine.com/t/distancetonearestsurface-material-node-disables-shadows-from-masked-materials/442410 "2019-01-30T21:06:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shanyu](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/shanyu/32/1067934_2.png) [@Shanyu](https://forums.unrealengine.com/u/Shanyu)\
**Post date:** [January 30, 2019, 9:06pm UTC](https://forums.unrealengine.com/t/distancetonearestsurface-material-node-disables-shadows-from-masked-materials/442410/1 "2019-01-30T21:06:17Z")

</div>

To eliminate interferences I created a new empty project just with starter content.

I turned on Mesh Distance Fields in the Project Settings.

I created a masked material and used a starter content noise texture for the opacity mask and color.

 ![267042-df-shadow2.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/6/95688954bf34ae57dd9f01bf34fb5f5847bec1b7.jpeg)

I duplicated that material and as soon as i add the DistanceToNearestSurface material node to the opacity mask the shadows cast from objects with that material are gone.

 ![267043-df-shadow3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/f/f/4ffab0ca7cc8a40c29ca714ae2f4b2286b1c24b5.jpeg)

 ![267044-df-shadow1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/0/a2027d018e49fc11e19a3ff7a7ddca3883bb15a3.jpeg)

You can tell from the surface that the opacity mask is working as intended but the shadows are gone.

What am I doing wrong?

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![down\_limit](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@down\_limit](https://forums.unrealengine.com/u/down_limit)\
**Post date:** [September 13, 2019, 10:38am UTC](https://forums.unrealengine.com/t/distancetonearestsurface-material-node-disables-shadows-from-masked-materials/442410/2 "2019-09-13T10:38:30Z")

</div>

UPD

Omg. I have similar trouble. But in another direction. I had FULL shading.

![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/9/c/89cc3c2ab5852e62ec5c0403eb7ce531adbedfbc.png)

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/f/58f3efdbf5f3c18ec99e658857bb256070622817.png)

The reason for the issue is “DistanceToNearestSurface” node? I was told that there is a possibility that the rendering order, in this case, does not work correctly

But I can’t refuse it or replace it with some other node. Different variations of the “Lighting” settings of the object did not give a satisfactory result.

Maybe someone has encountered such a problem too and knows a possible solution?

@Shanyu, may you ping me please if developers or other experts will prompt a solution

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [September 14, 2019, 6:44am UTC](https://forums.unrealengine.com/t/distancetonearestsurface-material-node-disables-shadows-from-masked-materials/442410/3 "2019-09-14T06:44:41Z")

</div>

Due to the nature of what Global Distance Field is, it is sort of expected.

You can use shadow pass separator material expression(or a custom node workaround explained here: [link text](https://forums.unrealengine.com/development-discussion/rendering/106533-possible-bug-shadows-disappearing-when-using-fresnel-function-in-masked-material))  
to deal with it.

---

<div class="post-metadata">

**Author:** ![down\_limit](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@down\_limit](https://forums.unrealengine.com/u/down_limit)\
**Post date:** [September 15, 2019, 7:32pm UTC](https://forums.unrealengine.com/t/distancetonearestsurface-material-node-disables-shadows-from-masked-materials/442410/4 "2019-09-15T19:32:06Z")

</div>

Thank you very much for the comment, it’s a very useful trick for future tasks. But it does not fix the issue

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/5/c/c5c2dac05779424e0b89ae9b7986a7721bdbbfd9.png)

I begin to despair and think that solutions cannot be found and the use of distance disappears. although this is a very interesting shader feature
