There are very few posts discussing about multiple terrains neighboring each other (e.g. a very old post).
Problem
Now I am trying to make two terrains adjacent to each other.
I found there are very small glitches (narrow gaps) at the boundary.
For example:
and
I don’t think it’s a simple shift due to wrong coordinates.
If set camera to FILL_WIREFRAME mode
camera->SetFillMode(FILL_WIREFRAME);
I also noticed the mesh seems not continuous.
Code
My sample code:
Node* terrain_node_center = scene_->CreateChild("TerrainCenter");
Terrain* terrain_center = terrain_node_center->CreateComponent<Terrain>();
const float size = 204.8;
Node* terrain_node_east = scene_->CreateChild("TerrainEast");
terrain_node_east->SetPosition(Vector3(size, 0, 0));
Terrain* terrain_east = terrain_node_east->CreateComponent<Terrain>();
Node* terrain_node_west = scene_->CreateChild("TerrainWest");
terrain_node_west->SetPosition(Vector3(-size, 0, 0));
Terrain* terrain_west = terrain_node_west->CreateComponent<Terrain>();
Node* terrain_node_north = scene_->CreateChild("TerrainNorth");
terrain_node_north->SetPosition(Vector3(0, 0, size));
Terrain* terrain_north = terrain_node_north->CreateComponent<Terrain>();
Node* terrain_node_south = scene_->CreateChild("TerrainSouth");
terrain_node_south->SetPosition(Vector3(0, 0, -size));
Terrain* terrain_south = terrain_node_south->CreateComponent<Terrain>();
std::vector<Terrain*> terrains{terrain_center, terrain_east, terrain_west, terrain_north, terrain_south};
for (auto* terrain : terrains) {
terrain->SetSpacing(Vector3(0.1, 0.2, 0.1));
terrain->SetSmoothing(true);
// terrain->SetMaterial(cache->GetResource<Material>("Materials/Terrain.xml"));
terrain->SetCastShadows(true);
terrain->SetOccluder(true);
}
terrain_center->SetHeightMap(cache->GetResource<Image>("Textures/TestTerrainCenter.png"));
terrain_east->SetHeightMap(cache->GetResource<Image>("Textures/TestTerrainEast.png"));
terrain_west->SetHeightMap(cache->GetResource<Image>("Textures/TestTerrainWest.png"));
terrain_north->SetHeightMap(cache->GetResource<Image>("Textures/TestTerrainNorth.png"));
terrain_south->SetHeightMap(cache->GetResource<Image>("Textures/TestTerrainSouth.png"));
// I tried both setting and not setting neighbor, no difference.
terrain_center->SetEastNeighbor(terrain_east);
terrain_east->SetWestNeighbor(terrain_center);
terrain_center->SetNorthNeighbor(terrain_north);
terrain_north->SetSouthNeighbor(terrain_center);
Heightmap
My heightmap is 2049*2049 (2^n + 1).
I also made sure the edge pixels of two images are the same (e.g. 2049 pixel for 2048 size).
Also attached example heightmaps:
TestTerrainCenter.png
TestTerrainNorth.png