Seams appearing in Terrain after deformation

Hello guys,

I am working on an evolution project that deforms the terrain each generation and tries to adapt it to a creature. For example I’m trying to move a sphere through random mutation of the terrain to a certain spot. After a few mutations seams between patches appear as in this screenshot:

The basic rundown of the program is:
Attach the individual, evaluate the fitness, detach everything(terrain and creature) and then attach the next individual.

After all individuals are done I select a few individuals(clone them) and mutate them with the following code which is from TerrainTestModifyHeight with a bit of randomness.

public static TerrainQuad mutateTerrain(TerrainQuad terrain, int max, float strength) {
float p = FastMath.nextRandomFloat();
if (p > strength) {
float locx = (FastMath.nextRandomFloat() * 64 * 2) - 64f;
float locz = (FastMath.nextRandomFloat() * 64 * 2) - 64f;
float radius = FastMath.nextRandomFloat() * 32 + 8;
float str = FastMath.nextRandomFloat() * (4.5f * 2) - 4.5f;
adjustHeight(new Vector3f(locx, 0, locz), radius, str, terrain);
return terrain;

private static void adjustHeight(Vector3f loc, float radius, float height, TerrainQuad terrain) {
    // offset it by radius because in the loop we iterate through 2 radii
    int radiusStepsX = (int) (radius / terrain.getLocalScale().x);
    int radiusStepsZ = (int) (radius / terrain.getLocalScale().z);

    float xStepAmount = terrain.getLocalScale().x;
    float zStepAmount = terrain.getLocalScale().z;
    List<Vector2f> locs = new ArrayList<>();
    List<Float> heights = new ArrayList<>();

    for (int z = -radiusStepsZ; z < radiusStepsZ; z++) {
        for (int x = -radiusStepsX; x < radiusStepsX; x++) {

            float locX = loc.x + (x * xStepAmount);
            float locZ = loc.z + (z * zStepAmount);

            if (isInRadius(locX - loc.x, locZ - loc.z, radius)) {
                // see if it is in the radius of the tool
                float h = calculateHeight(radius, height, locX - loc.x, locZ - loc.z);
                locs.add(new Vector2f(locX, locZ));
    terrain.adjustHeight(locs, heights);


I’m wondering if I can somehow avoid those seams or maybe there is a good way to fix them after(smooth step after mutation). I have not noticed this behaviour when the terrain is attached. So maybe the cloning process causes issues? For that purpose I use deepClone on the terrain to replicate the terrain for a new cloned individual.

I hope this description helps. If not let me know and I’ll try to provide some kind of test case. Any help is appreciated!

make sure the borders are the same height, i think that the terrain requires this.

After a lot of smoothing attempts and trying to fix the seams on my own I actually found the error somewhere else in my code.
While I’m trying to clone individuals I used this code.
TerrainQuad newTerrain = (TerrainQuad)terrain.deepClone();
But I should’ve used:
TerrainQuad newTerrain = new TerrainQuad(“my terrain”, 65, terrain.getTerrainSize(), terrain.getHeightMap().clone());
This fixed the seams from appearing. I have really no clue why this is the case but they don’t appear anymore. I’m really not happy with that knowledge though :-x …