Problem with rendering aligned GroundMeshes using TerrainMaterial

Hi guys,

edit: here is a playground I made showing the problem if you want to skip the long description: summary: I’m 95% sure it’s a problem with the texture I prepared.

I’ve been stuck on this problem all day. Here’s a screenshot of the problem, followed by an explanation … it’s a little complex but will try to keep it clear and minimal.

I’ve prepared a mix texture and heightmap, and sliced them into smaller pieces, and generated a number of grounds from heightmap using MeshBuilder.CreateGroundFromHeightMap. I then use TerrainMaterial, with rock, beach, and grass layers for each ground material using the corresponding sliced mix texture.

terrainMaterial.diffuseTexture1 = new Texture(landscapeRockUrl, scene);
terrainMaterial.diffuseTexture2 = new Texture(landscapeBeachUrl, scene);
terrainMaterial.diffuseTexture3 = new Texture(landscapeGrassUrl, scene);

I then position the generated ground meshes so they are aligned. Though the mix textures and heightmaps are aligned, this line is appearing at the edge of each mesh (see above image). What I have learned:

  • The problem seems to be with the mixTextures I’ve prepared. here are 2 example mix textures that I am using, these textures meet on the vertical axis, the beach layer is green, the grass is blue, and the mountains are red:

  • The line which appears on the edge takes the color of the beach layer. If I swap the textures:

terrainMaterial.diffuseTexture1 = new Texture(landscapeBeachUrl, scene);
terrainMaterial.diffuseTexture2 = new Texture(landscapeRockUrl, scene); // just swapping the layers
terrainMaterial.diffuseTexture3 = new Texture(landscapeGrassUrl, scene);

in this case, the line takes the color of the mountain layer

  • when I swap around the colors of the mixmap, replace the green with blue and vice versa, and swap the layers accordingly, the problem persists and confusingly still takes the color of the beach layer eventhough the colours are swapped. For example, here is the first mixtexture with the colors swapped:

terrainMaterial.diffuseTexture1 = new Texture(landscapeRockUrl, scene);
terrainMaterial.diffuseTexture3 = new Texture(landscapeBeachUrl, scene); // swapped
terrainMaterial.diffuseTexture2 = new Texture(landscapeGrassUrl, scene);
  • if I use … then the overlap lines disappear. This is really confusing me, and leads me to believe something is wrong with the textures I prepared (see uploads) … is it a render setting I’m missing?

  • it’s not dependent on the mesh placement, because still appears on the edge of each mesh when they’re separated. In fact here, we can see it’s just a very thin amount of ‘beach layer’ interfering with the grass layer … it’s not a clean line …

If anyone can offer any clarity as to why this is happening, I would much appreciate it, as I’ve really hit a dead-end with my current understanding of the problem, and it’s taken all day with preparing images etc.etc. to debug. I’m 95% sure it’s a problem with the texture I’m uploading, and the export settings. I’m using GIMP by the way, and these images are compressed with GIMP exported as 8bpc rgb.
Screenshot 2021-12-07 at 17.26.04

Sorry that was so long …

Adding @julien-moreau

Shot in the dark:

  • try setting the clamping mode on the textures (if not already the case)
  • try different sampling mode for the textures

You can do this directly with the inspector, so it should be easy to test.

What could help is a live link (not necessarily in the Playground) that demonstrates the problem.

yes: Babylon.js Playground

and yes, setting the clamping mode on the textures worked. Thanks for the quick response @Evgeni_Popov


Also, thanks for the help guys. Although not new to js / software development / graphics, I am new to Babylon, and I can say it’s been a joy to learn, and a really big part of that is getting very quick and expert assistance on the forum.


Thanks @Evgeni_Popov you rox !! <3