# How to use RayMarching node?

**URL:** <https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665>\
**Category:** Questions\
**Created:** [May 10, 2023, 7:07pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665 "2023-05-10T19:07:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/simon/32/45590_2.png) [@simon](https://forum.babylonjs.com/u/simon)\
**Post date:** [May 10, 2023, 7:07pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/1 "2023-05-10T19:07:32Z")

</div>

Hello!

I have simple question: How does work RayMarching node in NME? Some demos/advices or something which can help start to use RayMarching node in materials?

---

<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:** [May 10, 2023, 7:30pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/2 "2023-05-10T19:30:52Z")

</div>

This playground should help you get started:

> **[Babylon.js Playground](https://playground.babylonjs.com/#M3QR7E%2334)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

Note, however, that you’ll need [this PR](https://github.com/BabylonJS/Babylon.js/pull/13836) deployed (or to use a version other than 6.2.0), because the PG uses the `Triplanar` block multiple times.

Babylon.js does not provide a ray marching node per se, as it would be difficult to meet all the needs with a single implementation, but we have updated existing nodes / added new nodes to be able to implement ray marching in the NME, as demonstrated in the PG above. The `RayMarching` block that you will find in the node material is a basic implementation that uses a custom block and can be extended as needed (export the material to a .json file to see how it was implemented).

---

<div class="post-metadata">

**Author:** ![simon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/simon/32/45590_2.png) [@simon](https://forum.babylonjs.com/u/simon)\
**Post date:** [May 10, 2023, 7:40pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/3 "2023-05-10T19:40:43Z")

</div>

Thank you!

I saw this PG on 5.71.1. But using and possibilities still is not clear for me) So i think i shall go a bit deeper and make some tests for better understanding

---

<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:** [May 11, 2023, 8:35am UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/4 "2023-05-11T08:35:22Z")

</div>

There’s not much going on, other than the ray marching node itself.

The changes we made in the existing nodes generated code only in the fragment shader and removed all code generated in the vertex shader: look for the `Generate only fragment code` switch on the `PBRMetallicRoughness` and `Reflection` blocks.

We also added the `FragDepth` block to allow explicit setting of fragment depth, and the `ShadowMap` block to generate the shadow map from the ray marching outputs.

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [May 11, 2023, 12:46pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/5 "2023-05-11T12:46:19Z")

</div>

I made some very simple variations on the node the last time we were bug bashing, if you’d like to check it out:  
[Babylon.js Node Material Editor (babylonjs.com)](https://nme.babylonjs.com/#74XJAY#1)  
[Babylon.js Node Material Editor (babylonjs.com)](https://nme.babylonjs.com/#74XJAY#2)  
[Babylon.js Node Material Editor (babylonjs.com)](https://nme.babylonjs.com/#74XJAY#3)

---

<div class="post-metadata">

**Author:** ![simon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/simon/32/45590_2.png) [@simon](https://forum.babylonjs.com/u/simon)\
**Post date:** [May 11, 2023, 12:49pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/6 "2023-05-11T12:49:40Z")

</div>

@carolhmj @Evgeni_Popov

But why ray marching node in default setup looks like box and sphere which is merging sometimes?

---

<div class="post-metadata">

**Author:** ![simon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/simon/32/45590_2.png) [@simon](https://forum.babylonjs.com/u/simon)\
**Post date:** [May 11, 2023, 12:57pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/7 "2023-05-11T12:57:02Z")

</div>

I made some distortions)

> **[Babylon.js Node Material Editor](https://nme.babylonjs.com/#74XJAY%239)**
>
> Babylon.js Node material editor - shader-based materials editor for Babylon.js

---

<div class="post-metadata">

**Author:** ![carolhmj](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/carolhmj/32/25918_2.png) [@carolhmj](https://forum.babylonjs.com/u/carolhmj)\
**Post date:** [May 11, 2023, 2:25pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/8 "2023-05-11T14:25:57Z")

</div>

That’s right, there are no custom SDF nodes, I don’t think this is in the roadmap, right @Evgeni_Popov ?

---

<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:** [May 11, 2023, 3:52pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/9 "2023-05-11T15:52:22Z")

</div>

No, it’s not on the roadmap, we don’t plan to provide a full featured ray marching node nor SDF nodes.

---

<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:** [October 22, 2023, 3:31pm UTC](https://forum.babylonjs.com/t/how-to-use-raymarching-node/40665/10 "2023-10-22T15:31:00Z")

</div>

We still don’t plan to provide a full featured ray marching node in Babylon, but we do have some new doc on how to implement ray marching in the NME:

> **[Node Material Editor Custom Blocks | Babylon.js Documentation](https://doc.babylonjs.com/toolsAndResources/nme/customBlocks#using-custom-blocks-for-ray-marching)**
>
> Learn all about how to create custom blocks in the super handy Node Material Editor.
