# Mesh distance fields for better shadows

**URL:** <https://forum.babylonjs.com/t/mesh-distance-fields-for-better-shadows/13656>\
**Category:** Feature requests\
**Tags:** lighting\
**Created:** [August 25, 2020, 8:03am UTC](https://forum.babylonjs.com/t/mesh-distance-fields-for-better-shadows/13656 "2020-08-25T08:03:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shaileshiyer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shaileshiyer/32/2125_2.png) [@shaileshiyer](https://forum.babylonjs.com/u/shaileshiyer)\
**Post date:** [August 25, 2020, 8:03am UTC](https://forum.babylonjs.com/t/mesh-distance-fields-for-better-shadows/13656/1 "2020-08-25T08:03:50Z")

</div>

I have been going through unreal engines documentation and what they did on fortnite for getting some smooth shadows. they use mesh distance fields in which they create a 3d texture of every mesh at different scales and then use that to approximate the shadows being cast. In comparision to traditional ray based shadow casting it has about 20-25 perfomance gains at the cost of using additional memory. can we do this on webgl or are there some serious issues with trying to implement this in babylonjs.  
link to unreal engines [mesh distance field](https://docs.unrealengine.com/en-US/Engine/Rendering/LightingAndShadows/MeshDistanceFields/index.html#:~:text=An%20overview%20of%20Mesh%20Destance,use%20when%20developing%20your%20games.&text=Unreal%20Engine%204%20(UE4)%20leverages,Mesh%20Actors%20in%20your%20games.)

[Mesh Distance Fields](https://docs.unrealengine.com/en-US/Engine/Rendering/LightingAndShadows/MeshDistanceFields/index.html#:~:text=An%20overview%20of%20Mesh%20Destance,use%20when%20developing%20your%20games.&text=Unreal%20Engine%204%20(UE4)%20leverages,Mesh%20Actors%20in%20your%20games)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 25, 2020, 9:43am UTC](https://forum.babylonjs.com/t/mesh-distance-fields-for-better-shadows/13656/2 "2020-08-25T09:43:28Z")

</div>

I guess it should be possible to implement this, as it seems it uses 3D textures that are available in WebGL 2. Now, I’m not sure there’s enough information in the Unreal doc to properly implement the technic…

---

<div class="post-metadata">

**Author:** ![shaileshiyer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shaileshiyer/32/2125_2.png) [@shaileshiyer](https://forum.babylonjs.com/u/shaileshiyer)\
**Post date:** [August 25, 2020, 10:04am UTC](https://forum.babylonjs.com/t/mesh-distance-fields-for-better-shadows/13656/3 "2020-08-25T10:04:52Z")

</div>

Theres an chapter in gpu gems on signed distance fields. which is the real basis for mesh distance fields in unreal engine.

> **[Chapter 34. Signed Distance Fields Using Single-Pass GPU Scan Conversion of...](https://developer.nvidia.com/gpugems/gpugems3/part-v-physics-simulation/chapter-34-signed-distance-fields-using-single-pass-gpu)**
>
> Chapter 34. Signed Distance Fields Using Single-Pass GPU Scan Conversion of Tetrahedra Kenny Erleben University of Copenhagen Henrik Dohlmann 3Dfacto R&D 34.1 Introduction In this chapter we address the practicalities in computing a signed...

  
Theres also a link in the references in unreal engines documentation that links to a website on raymarching SDFs  
[https://iquilezles.org/www/articles/raymarchingdf/raymarchingdf.htm](https://iquilezles.org/www/articles/raymarchingdf/raymarchingdf.htm)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [August 25, 2020, 10:19am UTC](https://forum.babylonjs.com/t/mesh-distance-fields-for-better-shadows/13656/5 "2020-08-25T10:19:02Z")

</div>

That could do it, PR are always welcome 😉!
