private void erode(float smoothness) {
        for (int x = 1; x < width - 1; x++) {
            for (int z = 1; z < depth - 1; z++) {
                float d_max = 0.0f;
                int[] match = {0, 0};

                for (int u = -1; u <= 1; u++) {
                    for (int v = -1; v <= 1; v++) {
                        if (MathTools.abs(u) + MathTools.abs(v) > 0) {
                            float d_i = map[x + z * depth] - map[(x + u) + (z + v) * depth];
                            if (d_i > d_max) {
                                d_max = d_i;
                                match[0] = u;
                                match[1] = v;
                            }
                        }
                    }
                }

                if (0 < d_max && d_max <= (smoothness / (float) width)) {
                    float d_h = 0.5f * d_max;
                    map[x + z * depth] -= d_h;
                    map[(x + match[0]) + (z + match[1]) * depth] += d_h;
                }
            }
        }
    }