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
0
Question by YtnomSnrub · Nov 03, 2014 at 02:34 PM · proceduralheightmapprocedural-terrainlibnoise

Procedural Heightmap Jagged

I'm trying to create a procedural heightmap using LibNoise for Unity. It works brilliantly for creating images and textures, however when I apply the heightmap to a Terrain I get something like this:alt text

I'm not entirely sure why this is, but it doesn't seem to be to do with the texture since it displays at full resolution when I apply the texture to a Plane.

When using TerrainToolkit, however, the terrain appears smooth, meaning that it also shouldn't be a problem with the terrain settings.

My code for heightmap generation and allocation is as follows:

 public void GenerateTerrainMountains () {
         RidgedMultifractal mountainTerrain = new RidgedMultifractal();
         mountainTerrain.Seed = (int) System.DateTime.Now.Ticks;
         mountainTerrain.OctaveCount = 4;
         mountainTerrain.Frequency = 1;
         mountainTerrain.Quality = QualityMode.High;
 
         ModuleBase mountainModule = mountainTerrain;
 
         TerrainData terrainData = terrain.terrainData;
 
         float[,] heightMapData = terrainData.GetHeights (0, 0, terrainData.heightmapWidth, terrainData.heightmapHeight);
 
         heightMap = new Noise2D (terrainData.heightmapWidth, terrainData.heightmapHeight, mountainModule);
         heightMap.GeneratePlanar (0, 1, 0, 1);
         Texture2D heightMapTexture = heightMap.GetTexture ();
         heightMapTexture.Apply ();
 
         previewPlane.renderer.material.mainTexture = heightMapTexture;
 
         Color[] colours = heightMapTexture.GetPixels ();
 
         // Read all detail layers into a 3D int array
         int index = 0;
         for (int heightX = 0; heightX < terrainData.heightmapWidth; heightX ++) {
             for (int heightY = 0; heightY < terrainData.heightmapHeight; heightY ++) {
                 float heightMapOffset = colours [index].grayscale;
                 heightMapData [heightX, heightY] = heightMapOffset;
                 index ++;
             }
         }
         
         // Write all detail data to terrain data
         terrainData.SetHeights (0, 0, heightMapData);
     }

If you need any more information I will be glad to provide it. Thanks in advance :)

untitled.jpg (126.5 kB)
Comment
Add comment · Show 1
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 jrc03c · Jun 25, 2015 at 06:16 PM 0
Share

I know this was asked a while ago, but did you ever figure it out? I'm having the same problem right now. :(

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by SkyDwarfProductions · Nov 06, 2018 at 11:57 AM

Hey @AngryPanther ! I have found a solution for you. The problem you are having is because you are assigning the verts height value off a texture. The jagged terrain effect you have has happened because your height map is a lower resolution then your actual mesh.

The height map texture uses pixels as I'm sure you know the pixels have a flat value so when more than one vert gets applied to the same pixel they will have the same value creating the jagged effect or I guess low resolution effect.

The solution I found is rather to use a 2D float array and assign the heights that way. You can do this my using the heightmap.GetData function instead of get texture.

Getting the heightmap data into a 2D float array would look something like this:

void GetTexture () { // DataH looks like this -----> float[,] DataH; .Its a 2D float array DataH = heightmap.GetData( false , 0 , 0, false); // <------- 2D FLOAT ARRAY solution by getting the data strait and not through a texture texture = heightmap.GetTexture (GradientPresets.Grayscale); // <------ TEXTURE solution that creates some problems }

Applying it to your mesh would look something like this:

for (int x = 0;x <= grid_size ;x+= Lod_Factor) { for (int y = 0;y <= grid_size ;y+= Lod_Factor) { //Hieghts[v] = texture.GetPixel (x, y).grayscale; <--- problematic at high frequancy Hieghts[v] = DataH [x,y]; // <--- preferd option verts [v] = new Vector3 ((x * quad_size) - middle , Hieghts [v] , (y * quad_size) - middle); UVS [v] = new Vector2 ((x * quad_size) - middle, (y * quad_size) - middle); v++; } } I know this is probably a little late but I hope it helps.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Procedural terrain bigger than I set it, heightmap slightly off 0 Answers

How to seamlessly tile terrains 0 Answers

Basics of procedural map generation 0 Answers

Merging, Transitioning, or Blending from one texture to the other based upon Height Maps 0 Answers

For loop not starting from zero 0 Answers


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