# Smoothing out a mesh

**URL:** <https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664>\
**Category:** Help & Support\
**Created:** [July 19, 2022, 6:03pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664 "2022-07-19T18:03:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [July 19, 2022, 6:03pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664/1 "2022-07-19T18:03:39Z")

</div>

Hi there, I’m building a mesh/terrain generator and well I have a few questions  
Source project: [PlayCanvas 3D HTML5 Game Engine](https://playcanvas.com/project/821512/overview/mesh-generation)

 ![Screen](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/2/d/2d80caec4efb439227c4b0cefea9b5de59edb039.png)

I’m not sure how to smooth out terrains between two different meshes/planes, how can this be achieved? Is there any function or example this beeing done? Thanks

Another question: Would it be possible (after mesh generation) to generate different zones by mesh height and apply different textures to meshes, like sand grass etc

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [July 19, 2022, 6:21pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664/2 "2022-07-19T18:21:15Z")

</div>

Hi @Newbie_Coder,

Yes, it’s definitely possible though it requires a lot of manual work.

You will need to visit the terrain edges in your positions array and flatten/average them so both terrains match. At the same moment you will need to calculate the normals to take into account the triangles of the other terrain, to avoid getting lighting artifacts.

This thread is quite useful on that subject: [Tiled terrain and normals - #6 by Leonidas](https://forum.playcanvas.com/t/tiled-terrain-and-normals/3715/6)

For generating different zone heights that’s possible. You could calculate the terrain UV coordinates to match a specific texture, I don’t have an example in mind for that.

Another way is to use a height based shader to do the same thing and mix between the various textures used. Here is a Three.js example that you can study for learning:

[![](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/1/d/1de66394cd753deeff4fbc69c2e0635719c5df22.jpeg "22b How to color terrain from heightmap three.js") ](https://www.youtube.com/watch?v=G0hWjD0n46c)

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [July 19, 2022, 6:47pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664/3 "2022-07-19T18:47:30Z")

</div>

Thanks for your informative reply, lots of work ahead, would it be any easier to smooth out single planes corners instead? Will look for examples

This is what I’m aiming for (looks) [PlayCanvas 3D HTML5 Game Engine](https://playcanvas.com/project/384292/overview/procedurally-generated-world)  
Saldy it is outdated

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [July 19, 2022, 8:09pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664/4 "2022-07-19T20:09:22Z")

</div>

When you say smooth out single planes corners, what do you mean exactly?

Smooth out the normals for lighting? Or reduce the height on the corners so it looks more like an island at the center?

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [July 19, 2022, 8:14pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664/5 "2022-07-19T20:14:32Z")

</div>

More like an island look, I’m totally lost with mesh stuff, a good start would be to select corners of the mesh 😄

The idea is to flatten all corners, thus colliding planes would look seamless (I hope) as I am not planing to generate hills

Just an idea: What if heightmap (with transition to black corners) could be applied during generation? Probably not as the engine would still have to proccess whole map 🤔

---

<div class="post-metadata">

**Author:** ![Newbie\_Coder](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/newbie_coder/32/21065_2.png) [@Newbie\_Coder](https://forum.playcanvas.com/u/Newbie_Coder)\
**Post date:** [July 20, 2022, 8:47pm UTC](https://forum.playcanvas.com/t/smoothing-out-a-mesh/26664/6 "2022-07-20T20:47:34Z")

</div>

I’m done with terrain generation, (back to heightmaps) what’s left is coloring, I’ve found some usefull link over here [Around custom shaders](https://forum.playcanvas.com/t/around-custom-shaders/14685)  
Could this work? What are the steps to reproduce shader on PlayCanvas, the glsl has to be rewritten?
