Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by zharramadar · Sep 08, 2010 at 07:36 PM · terrainseams

Yet Another Terrain Seams Question

Hello Everybody,

I've been playing around with Unity trying to create terrains at run-time. I've managed to make a terrain load from a socket connection providing heightmap information, and now I'm trying to make 2 terrains stitch together seamlessly.

I don't know if I took the best approach (correct me if I didn't), but I created 2 empty GameObjects in my scene named TerrainContainer1 and TerrainContainer2. In each of those, I added my script which will connect to my server, will request for the correct heightmap and will generate a terrain in run-time with the data the server sent to it. So far, it is doing pretty good. I placed a white pixel in each of both terrains' corners to check if I'm rendering everything and placed numbers in each corner to check if I'm joining the correct sides, and seems it does nicely.

Then, I read around that I should set the SetNeighbors so that each terrain points to each other to overcome LOD problems while doing seamless terrains. As when I play my "game" I don't have any terrain loaded, I created another empty GameObject and added a C# script to it with 2 static variables. In the update loop, I check if both terrains are already loaded, and if so, I set the neighbors only once (i placed a flag variable there so I don't setNeighbors every frame).

I also tried to set neighbors in every possible arrangement only to ensure that I'm setting them correctly, and placed some Debug.Log to see if the setNeighbor call happens AFTER the 2 terrains loading, and yes, it does.

Anyway, even doing all that, I still have a seam. Strangely enough, where my corner white pixels are, the terrain match nicely, but not in the rest of it.

To generate the heightmap, I made a 2050x1025 image in Photoshop, and cut 2 1025x1025 images from it, and saved as PNG non-interleaved, grayscale.

There is the image from when I run the app:

alt text

What I'm doing wrong? it is the fact each terrain resides within different GameObjects, so they can't setNeighbor each other? Any ideas? Did I take a nice approach in doing this, or my design is flawed?

Thanks in advance!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image e-bonneville · Sep 08, 2010 at 07:39 PM 0
Share

If by nice you mean complex, I think your approach is pretty darn good.

avatar image zharramadar · Sep 08, 2010 at 10:52 PM 0
Share

Thanks! I'm pretty used to corporative softwares, and I know some things work quite differently in the game world, that's why I asked. $$anonymous$$aybe, for example, putting the terrains all in one GameObject or all of them directly in the main node could be better, don't know. But if it is good as it is, I'm glad, and I shall continue this way then =D

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by spinaljack · Sep 08, 2010 at 10:22 PM

Have you tried changing the height maps from "repeat" to "clamp" wrap mode? That might be causing anomalies along the edges. Alternatively you can set a single sold height along all the edges to ensure a match on both sides and then you'll have to hide it somehow like with rocks and bushes or hills made to match the terrain.

Just some ideas as your system sounds pretty good, but just setting neighbours wont make the height the same on each terrain as you've seen.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zharramadar · Sep 08, 2010 at 10:50 PM 0
Share

Sorry, but I do not know which property in run-time I can set this heightmap mode. Which is the property I must set in the terrainData or Terrain class to do so?

avatar image zharramadar · Sep 08, 2010 at 11:05 PM 0
Share

Oh, forget it.... Seems it is my inability to understand heightmaps and photoshop properly =D Shame on me. I cannot make a 2050x1025 image and split them in two. Seems that one heightmap must share a pixel line with the other one in order to make them work together seamlessy. I just copied the bottom line of my top heightmap and placed it in the 1st line of my bottom heightmap and all the vertexes joined together magically =D... So, I need to make a 2048x1024 heightmap and always duplicate the bottom/left pixels to the next heightmap. Living and learning.

avatar image andrew-lukasik · Jan 29, 2019 at 01:37 PM 0
Share

YES, thank you! This is the correct answer. It can seems like it's maybe not when you look at wrong texture object or at wrong time in your pipeline tho.

avatar image
1

Answer by xabblll · Nov 08, 2013 at 01:44 AM

Changing wrap mode didn't helped me. So i wrote a script for fix it manually. It is pretty basic, but maybe it can help somebody. You can run it once, because all terrainData will saved automatically.

 public static void Fix(Terrain cur, Terrain right, Terrain bottom)
     {
 
 
         float[,] newHeights = new float[resolution, resolution];
         float[,] rightHeights = new float[resolution, resolution], bottomHeights = new float[resolution, resolution];
 
         if (right != null)
         {
             rightHeights = right.terrainData.GetHeights(0, 0, resolution, resolution);
         }
         if (bottom != null)
         {
             bottomHeights = bottom.terrainData.GetHeights(0, 0, resolution, resolution);
         }
 
         if (right != null || bottom != null)
         {
 
             newHeights = cur.terrainData.GetHeights(0, 0, resolution, resolution);
 
             for (int i = 0; i < resolution; i++)
             {
                 if (right != null)
                     newHeights[i, resolution - 1] = rightHeights[i, 0];
 
                 if (bottom != null)
                     newHeights[0, i] = bottomHeights[resolution - 1, i];
             }
             cur.terrainData.SetHeights(0, 0, newHeights);
         }
     }
 
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Terrain with lots of objects 1 Answer

Loading terrainData from Resources into existing Terrain object using UnityScript 1 Answer

Adding trees dynamically - part 2 (the mission) 1 Answer

Terrain Generation Problem 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges