#  I have problem with Multi Material

**URL:** <https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194>\
**Category:** Questions\
**Tags:** material\
**Created:** [October 8, 2019, 3:02pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194 "2019-10-08T15:02:43Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 8, 2019, 3:02pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/1 "2019-10-08T15:02:43Z")

</div>

I created a terrain with noise and wanted to change the material to the height of “y”.  
I used BABYLON.MultiMaterial and the loop caught indices with “y” \<1.5 as “WaterMaterial” else “StandardMaterial”

I get the error as pic attach. Does anyone have suggestions for me or give me examples to handle this problem?

 ![Error%20Multi%20Material](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/0/071872d09076b103d67e1b5c98181c682f8ffb90.jpeg)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 8, 2019, 3:11pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/2 "2019-10-08T15:11:00Z")

</div>

We will need a repro in the Playground to be able to help

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 8, 2019, 3:40pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/3 "2019-10-08T15:40:28Z")

</div>

Thank you for the feedback this is my code  
[https://www.babylonjs-playground.com/#DSUF7F#2](https://www.babylonjs-playground.com/#DSUF7F#2)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 8, 2019, 3:43pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/4 "2019-10-08T15:43:45Z")

</div>

I see no error in the console. What should I look at?

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 8, 2019, 3:53pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/5 "2019-10-08T15:53:39Z")

</div>

> [@Deltakosh](#):
>
> Playground

I tried to fix the error in my code on Playground that no longer shows the error but the grid and multi-materials don’t show up, I don’t know where the problem is anymore.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 8, 2019, 4:00pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/6 "2019-10-08T16:00:53Z")

</div>

well the ground seems hidden in your pg:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/9/97bc2317ad3795bfe16d3a98f579d46f2e2f35fb.jpeg)

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 8, 2019, 4:04pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/7 "2019-10-08T16:04:47Z")

</div>

After removing the following two lines of code I get the same error at the beginning  
// matWater.addToRenderList(scene.getMeshByName(‘skyBox’));  
// matWater.addToRenderList(scene.getMeshByName(‘ground’));

[https://www.babylonjs-playground.com/#DSUF7F#4](https://www.babylonjs-playground.com/#DSUF7F#4)

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 8, 2019, 4:13pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/8 "2019-10-08T16:13:03Z")

</div>

You must have at least one mesh inside the render list of the water material or the texture will be incomplete.

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 8, 2019, 4:19pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/9 "2019-10-08T16:19:04Z")

</div>

So can I create many materials including water in a ground triangular grid?  
Can you give me an example? Thank you very much

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 8, 2019, 4:24pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/10 "2019-10-08T16:24:53Z")

</div>

Sorry but I do not understand what you need ☹  
Why not using separate meshes? like a plane for the water should be enough right?

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 8, 2019, 4:34pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/11 "2019-10-08T16:34:18Z")

</div>

I am trying to create an automatic, non-duplicated automatic map algorithm with the sea, rivers, lakes, mountains, … distributing plants according to the natural height. But the best way to create mountains is to change the height of the ground net, if connecting multiple ground with many overlapping materials will make it more difficult for me.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 8, 2019, 4:49pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/12 "2019-10-08T16:49:08Z")

</div>

Did you check what I did here for worldmonger?  
[https://www.babylonjs.com/scenes/worldmonger/](https://www.babylonjs.com/scenes/worldmonger/)

Code here:[Website/build/Scenes/WorldMonger at master · BabylonJS/Website · GitHub](https://github.com/BabylonJS/Website/tree/master/build/Scenes/WorldMonger)

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 9, 2019, 2:53am UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/13 "2019-10-09T02:53:48Z")

</div>

Great, this is what I’m looking for. What method did you use to create it? Can you share important points to consider when implementing it as well as the difficulties you encounter when making it?  
I have looked into your code but probably because I have just started learning babylon, there is a lot of reading that I don’t understand  
ex: how do you locate and increase the height and change the material?  
ex: this.\_effect = engine.createEffect("./Source\_Clone/water",  
[“position”, “normal”, “uv”],  
[“worldViewProjection”, “world”, “view”, “vLightPosition”, “vEyePosition”, “waterColor”, “vLevels”, “waveData”, “windMatrix”],  
[“reflectionSampler”, “refractionSampler”, “bumpSampler”],  
“”);

I have read Amit’s article from this page  
[http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/](http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/)  
It inspired me to make a game with a realistic map and never overlap without human intervention. But I had difficulty in doing Amit’s theory conversion because of babylon’s ground made of triangular mesh.  
Do you have any ideas to help me create Polygonal Map Generation or another way to create all of them with triangular mesh BABYLON?

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [October 9, 2019, 3:13pm UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/14 "2019-10-09T15:13:02Z")

</div>

I think the first step is probably to get the code and play with it. I create a Ground material which is a custom shader. Maybe you can read the shader code to better understand how it works

Other itneresting thing to consider:

- Node Material Editor to design your own shader easily: [How To use the Node Material - Babylon.js Documentation](https://doc.babylonjs.com/how_to/node_material)
- Terrain Material: [Terrain - Babylon.js Documentation](https://doc.babylonjs.com/extensions/terrain)
- Dynamic terrain: [How to Use Dynamic Terrain - Babylon.js Documentation](https://doc.babylonjs.com/extensions/dynamic_terrain)
- Mix material: [Mix - Babylon.js Documentation](https://doc.babylonjs.com/extensions/mix)

---

<div class="post-metadata">

**Author:** ![HUY\_HOANG](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/huy_hoang/32/4913_2.png) [@HUY\_HOANG](https://forum.babylonjs.com/u/HUY_HOANG)\
**Post date:** [October 10, 2019, 7:59am UTC](https://forum.babylonjs.com/t/i-have-problem-with-multi-material/6194/15 "2019-10-10T07:59:46Z")

</div>

Thank you so much for your suggestions. I will try, if I have any problems hope to continue to be of your help
