# DistanceToNearestSurfacec Exclude Mesh from results without disabling Distance Fields for it?

**URL:** <https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348>\
**Category:** Rendering\
**Tags:** UE-5, distance-fields, unreal-engine, Rendering, shader, question\
**Created:** [January 11, 2023, 9:25pm UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348 "2023-01-11T21:25:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nonlin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonlin](https://forums.unrealengine.com/u/Nonlin)\
**Post date:** [January 11, 2023, 9:25pm UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348/1 "2023-01-11T21:25:14Z")

</div>

Essentially I want to use a material on a mesh that make use of DistanceToNearestSurface but in order for it to work the results of the DistanceToNearestSurface needs to exclude its self.

The issue there is, I want this mesh with this material to get the distance fields from other meshes with the same material but if I have to disable affects distance field on the mesh then I can’t do this.

How can I keep my cake and eat it too?

I though about maybe doing a conditional check where if the DistanceField result is of a certain distance, ignore that and then when it exceeds it use the result but this didn’t seem to work as i thought it would.

---

<div class="post-metadata">

**Author:** ![BananableOffense](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BananableOffense](https://forums.unrealengine.com/u/BananableOffense)\
**Post date:** [January 11, 2023, 10:37pm UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348/2 "2023-01-11T22:37:20Z")

</div>

As far as I know the distance field has no way to distinguish whether the nearest surface is itself or something else. But you can sample the distance field from a different position. It’s common to offset the sample point (often along the vertex normal) from the mesh.

---

<div class="post-metadata">

**Author:** ![Nonlin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nonlin](https://forums.unrealengine.com/u/Nonlin)\
**Post date:** [January 12, 2023, 3:28am UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348/3 "2023-01-12T03:28:18Z")

</div>

Yeah I just did this and it seems to work for me for now. Thanks.

---

<div class="post-metadata">

**Author:** ![ObjOri](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/objori/32/591466_2.png) [@ObjOri](https://forums.unrealengine.com/u/ObjOri)\
**Post date:** [May 3, 2024, 12:25pm UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348/4 "2024-05-03T12:25:06Z")

</div>

I know this was a while ago, but how did you change the offset and resample?

---

<div class="post-metadata">

**Author:** ![Supermatta321](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Supermatta321](https://forums.unrealengine.com/u/Supermatta321)\
**Post date:** [June 14, 2024, 11:16am UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348/5 "2024-06-14T11:16:10Z")

</div>

How did you solve it?

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [July 27, 2024, 8:03am UTC](https://forums.unrealengine.com/t/distancetonearestsurfacec-exclude-mesh-from-results-without-disabling-distance-fields-for-it/747348/6 "2024-07-27T08:03:11Z")

</div>

The node gives you the chance to sample from a different point

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/c/b/fcbaa695822ff04cda5aa38f8db7c72dc583318f.png)

So you can start further out than the edge of your mesh, by doing

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/3/af39dce4819e4492c8e67269fb91248f0bcb8db3.png)
