# Custom script in node material editor

**URL:** <https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038>\
**Category:** Feature requests\
**Tags:** material, node-material\
**Created:** [July 9, 2022, 11:07pm UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038 "2022-07-09T23:07:44Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [July 9, 2022, 11:07pm UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/1 "2022-07-09T23:07:44Z")

</div>

will be possible in the future to add custom scripts / function in node material editor ?

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [July 10, 2022, 12:13am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/2 "2022-07-10T00:13:07Z")

</div>

I think you’re talking about custom blocks? Here’s the documentation for them, I have a few simple blocks that I could post too for more examples if that’s what you’re after. 🙂

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

---

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [July 10, 2022, 12:32am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/3 "2022-07-10T00:32:00Z")

</div>

This is exactly what i need !!! Thanks sm!!

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [July 10, 2022, 12:50am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/4 "2022-07-10T00:50:59Z")

</div>

Right on, here’s some more custom blocks you can check out too for more examples. 🙂 🍻

> **[GitHub - BlakeOne/NME-Custom-Blocks: Custom blocks for Babylon.js's Node...](https://github.com/BlakeOne/NME-Custom-Blocks)**
>
> Custom blocks for Babylon.js's Node Material Editor (NME) - GitHub - BlakeOne/NME-Custom-Blocks: Custom blocks for Babylon.js's Node Material Editor (NME)

---

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [July 11, 2022, 1:16am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/5 "2022-07-11T01:16:34Z")

</div>

can we reference a sampler2d or create a block for it?

---

<div class="post-metadata">

**Author:** ![Blake](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/blake/32/21509_2.png) [@Blake](https://forum.babylonjs.com/u/Blake)\
**Post date:** [July 11, 2022, 1:44am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/6 "2022-07-11T01:44:03Z")

</div>

You can use the Texture block for that. 🙂

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

---

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [July 11, 2022, 3:11am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/7 "2022-07-11T03:11:32Z")

</div>

hmm not exactly what i needed, noticed in some posts that creating a sampler2d block is not yet implemented, so i had to do a hacky way to reference the sampler2d i needed

Thanks!

---

<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:** [July 11, 2022, 8:08am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/8 "2022-07-11T08:08:45Z")

</div>

`ImageSourceBlock` should be what you are after.

It can be connected to multiple `Texture` blocks by their `source` input.

---

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [July 11, 2022, 4:53pm UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/9 "2022-07-11T16:53:57Z")

</div>

Yes that’s what i ended up using 🙂

Thanks sm!

---

<div class="post-metadata">

**Author:** ![ShaneL](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/shanel/32/26441_2.png) [@ShaneL](https://forum.babylonjs.com/u/ShaneL)\
**Post date:** [August 22, 2022, 6:00pm UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/10 "2022-08-22T18:00:09Z")

</div>

Out of curiosity, can you share what you did/how you got it working? Were you able to pass the output from ImageSourceBlock into a custom block?

---

<div class="post-metadata">

**Author:** ![waverider404](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/waverider404/32/17464_2.png) [@waverider404](https://forum.babylonjs.com/u/waverider404)\
**Post date:** [August 31, 2022, 4:32am UTC](https://forum.babylonjs.com/t/custom-script-in-node-material-editor/32038/11 "2022-08-31T04:32:14Z")

</div>

Hello sorry for the late response, so basically you have to create an image source, and in the custom block json create a vec4 with whatever name your texture2d channel is, just make sure that you add “Sampler” to the name inside the texture2D function. Lets say your vec4 texture2d channel is noiseimage, in the texture2D function, re-write noiseimageSampler.

Connect your imageSourceBlock named(noiseimage, can be any name) to a textureBlock, now connect the rgba output to the input node in the custom json block which you already referenced in the custom block json.

Let me know if you have any questions.

Cheers
