# Custom color buffer in node material

**URL:** <https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778>\
**Category:** Questions\
**Tags:** material, nodematerial, custom-node-material\
**Created:** [November 18, 2023, 6:35pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778 "2023-11-18T18:35:40Z")\
**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:** [November 18, 2023, 6:35pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/1 "2023-11-18T18:35:40Z")

</div>

Hi!

@Evgeni_Popov  
Could you help me?

I have a problem with custom block. I want to provide custom buffer to my node material.

I used your PG: [https://playground.babylonjs.com/#ZTTZJ3#1](https://playground.babylonjs.com/#ZTTZJ3#1)  
And in my PG: [https://playground.babylonjs.com/#PLZXVJ#1](https://playground.babylonjs.com/#PLZXVJ#1) it also works.

But when I try to attach my custom block to another port of color merger i got an error

 ![issue](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/3/0/3035ac461f0dc300c556b11586e004dd3b250123.png)

Unfortunatelly i dont understand whats happend because i dont find detailed documentation about the way of creation custom block which you used in your example. Never the less I looked at doc about creation of the custom blocks from json file ([Node Material Editor Custom Blocks | Babylon.js Documentation](https://doc.babylonjs.com/toolsAndResources/nme/customBlocks)). But I dont understand how i can define attribute (my custom buffer) and provide them on output of the node using way this way ([Node Material Editor Custom Blocks | Babylon.js Documentation](https://doc.babylonjs.com/toolsAndResources/nme/customBlocks))

Please help me if you can

---

<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:** [November 19, 2023, 2:54pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/2 "2023-11-19T14:54:03Z")

</div>

When i try to connect my custom block to any another port line “undefined” is added to vertex shader before attribute vec2 myTest;

---

<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:** [November 19, 2023, 3:12pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/3 "2023-11-19T15:12:25Z")

</div>

Interesting thing that if i reconnect out port of my block manually (using ‘connectTo’ function, not nme) it works fine

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

---

<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:** [November 20, 2023, 1:25pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/4 "2023-11-20T13:25:42Z")

</div>

In fact, when in the NME, the default setting is to generate the comments along with the functions that have been injected in the code through the `_emitFunction` method. The comment is the 3rd parameter of `_emitFunction`, but in my example I did not set a comment, so it is `undefined` my default. You can fix the problem by setting a dummy comment:

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

---

<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:** [November 20, 2023, 1:38pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/5 "2023-11-20T13:38:07Z")

</div>

You are rock 🤘  
Thank you very much!!!

---

<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:** [November 20, 2023, 6:15pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/6 "2023-11-20T18:15:45Z")

</div>

One more question. Could I add such as custom block to NodeMaterial editor? I know how to do that with blocks parsed from .json but in this case I don’t know if it is possible

---

<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:** [November 20, 2023, 7:12pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/7 "2023-11-20T19:12:12Z")

</div>

No, that won’t be possible because you can’t create a new attribute with the `CustomBlock` feature of the NME.

---

<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:** [November 20, 2023, 8:09pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/8 "2023-11-20T20:09:53Z")

</div>

Thank you!

---

<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:** [November 29, 2023, 7:11pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/9 "2023-11-29T19:11:11Z")

</div>

Hello again @Evgeni_Popov !

I dont think that it is right to open another topic because my new question is very close to this topic. It is about providing of texture to node material by instance. I already read topic about changing texture per instance using uv offset but it will not work for me. Maybe there is the way to provide small texture (\<512x512 px) using buffer? Like we did it with floats or vectors

---

<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:** [November 29, 2023, 8:31pm UTC](https://forum.babylonjs.com/t/custom-color-buffer-in-node-material/45778/10 "2023-11-29T20:31:13Z")

</div>

Unfortunately it’s not possible. We can’t bind textures on a per-instance basis. You will have to use a big texture and pass a (u,v,width,height) vec4 to each instance, so that they can each target a different part of the texture.
