2
\$\begingroup\$

I am programmatically generating terrain using unity's terrain object and assigning height maps to it via the terrainData, the problem is that there are seams even when using the GroupingId(which is used for auto connect). I even tried creating a terrain object in the editor with neighbours, and modified their terrain data via script, seams still there.

I have also tried SetConnectivityDirty after applying terrainData.

Most people who have reported this seemed(lol) to have issues with their normals at the edges, I cant see that being the issue here, but if it is, how do i approach solving it given I am using unity terrains.

If there is no good answer I will have to resort to custom meshes and lose all the nice terrain tool functionality.

enter image description here

Edit: Here is how I'm setting heights.

var terrain = GameObject.Find("test").GetComponent<Terrain>();
var terrainData = terrain.terrainData;
var noiseMap = Tool_Generators.GenerateNoiseMap(chunkSize, seed, scale, octaves, persistance, lacunarity, 0f, 0f);
terrainData.SetHeights(0, 0, noiseMap);

Then the actual noise generation is just a 2D array of heights, i have been using a simplified version with only 1 pass for testing.

  public static float[,] GenerateNoiseMap(int chunkSize, int seed, float scale, int octaves, float persistance, float lacunarity, float offsetX, float offsetY)
  {
    float[,] noiseMap = new float[chunkSize, chunkSize];

    for (int y = 0; y < chunkSize; y++)
    {
        for (int x = 0; x < chunkSize; x++)
        {
            float noiseHeight = 0;

            float sampleX = (x + offsetX) / scale;
            float sampleY = (y + offsetY) / scale;

            noiseHeight = Mathf.PerlinNoise(sampleX, sampleY);
            noiseMap[y, x] = noiseHeight;
        }
    }

    return noiseMap;
  }
\$\endgroup\$
  • \$\begingroup\$ Can you show us how you're creating/assigning your height maps? \$\endgroup\$ – DMGregory Sep 12 '19 at 17:14
  • \$\begingroup\$ what type of image are you using? for best result with height map you have to use RAW format \$\endgroup\$ – virtouso Sep 12 '19 at 17:41
  • \$\begingroup\$ as per the edit, i am creating the height map through code. \$\endgroup\$ – cranial3 Sep 13 '19 at 6:44
  • \$\begingroup\$ It seems that the issue lies somewhere in the fact that the edge folds over slightly, see reddit.com/r/Unity3D/comments/d3w6sb/seamless_terrain for screenshots. \$\endgroup\$ – cranial3 Sep 13 '19 at 21:51
1
\$\begingroup\$

This question is quite old but here's an answer in case someone else is looking for a solution.

You have to stitch terrains together by matching heightmap values on the edges. Below is a code that stithces a terrain with it's left or bottom neightbor. Code assumes that terrain tiles have same size and resolution.

To stitch with top neighbor, you just switch parameters to StitchToBottom(top, terrain) and with right StitchToLeft(right, terrain).

    public void StitchToLeft(Terrain terrain, Terrain leftNeighbor)
    {
        TerrainData data = terrain.terrainData;
        int resolution = data.heightmapResolution;

        // Take the last x-column of neighbors heightmap array
        // 1 pixel wide (single x value), resolution pixels tall (all y values)
        float[,] edgeValues = leftNeighbor.terrainData.GetHeights(resolution - 1, 0, 1, resolution);

        // Stitch with other terrain by setting same heightmap values on the edge
        data.SetHeights(0, 0, edgeValues);
    }

    public void StitchToBottom(Terrain terrain, Terrain bottomNeighbor)
    {
        TerrainData data = terrain.terrainData;
        int resolution = data.heightmapResolution;

        // Take the top y-column of neighbors heightmap array
        // resolution pixels wide (all x values), 1 pixel tall (single y value)
        float[,] edgeValues = bottomNeighbor.terrainData.GetHeights(0, resolution - 1, resolution, 1);

        // Stitch with other terrain by setting same heightmap values on the edge
        data.SetHeights(0, 0, edgeValues);
    }

enter image description here

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.