Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Explie · May 30, 2016 at 05:17 AM · textureterrainterraintexturesplatmapsplatmaps

Weird results after Procedural Terrain Splatmapping

Hi all,

I am currently working on assigning different textures to a terrain based on their height value. I use the awesome work from https://alastaira.wordpress.com/2013/11/14/procedural-terrain-splatmapping/ as a reference for this. This works quit well at this point but it does not seem to be consistent.

alt text

In the above image the left hand side of the pillar like terrain (red circle) has the correct textures assigned but the right hand side is way off and I can't find why.

Below is the code handling the texture assignment:

 Dictionary<HeatmapLayers, float> heatmapColorThreshold = new Dictionary<HeatmapLayers, float>();
 heatmapColorThreshold.Add(HeatmapLayers.DarkBlue, 0.165f);
 heatmapColorThreshold.Add(HeatmapLayers.LightBlue, 0.33f);
 heatmapColorThreshold.Add(HeatmapLayers.Green, 0.495f);
 heatmapColorThreshold.Add(HeatmapLayers.Yellow, 0.66f);
 heatmapColorThreshold.Add(HeatmapLayers.Orange, 0.825f);
 heatmapColorThreshold.Add(HeatmapLayers.Red, 1f);
 
 
 //init Terrain
 GameObject terrainObj = new GameObject("TerrainObj");
 TerrainData terrainData = new TerrainData();
 terrainData.size = new Vector3(0.5f,2f,0.5f);
 terrainData.heightmapResolution = 128;
 terrainData.baseMapResolution = 128;
 terrainData.SetDetailResolution(32, 16);
 
 /**
 add terrain collider and so on
 big loop setting the heights
 adding textures to terrain
 **/
 
 //set alphamap to same size as terrainHeightsMap, makes fiddling with the heights easier
 terrainData.alphamapResolution = 128;
 
 float[,,] splatmapData = new float[terrainData.alphamapWidth, terrainData.alphamapHeight, terrainData.alphamapLayers];

 //iterate through alphamap
 for (int y = 0; y < terrainData.alphamapHeight; y++) {
     for (int x = 0; x < terrainData.alphamapWidth; x++) {

             //get height from terrain height data which was filled earlier
         float height = terrainHeightsArray[x, y];

         float[] splatWeights = new float[terrainData.alphamapLayers];

             //if height > orange threshold make it red
         if (height > heatmapColorThreshold[HeatmapLayers.Orange]) {
             splatWeights[5] = 1f;              
             //if height > yellow threshold make it orange and so on
             } else if (height > heatmapColorThreshold[HeatmapLayers.Yellow]) {
             splatWeights[4] = 1f;                
         } else if (height > heatmapColorThreshold[HeatmapLayers.Green]) {
             splatWeights[3] = 1f;                   
         } else if (height > heatmapColorThreshold[HeatmapLayers.LightBlue]) {
             splatWeights[2] = 1f;
         } else if (height > heatmapColorThreshold[HeatmapLayers.DarkBlue]) {
             splatWeights[1] = 1f;
         } else {
             splatWeights[0] = 1f;
         }
 
         // Sum of all textures weights must add to 1, so calculate normalization factor from sum of weights
         float z = splatWeights.Sum();
 
         // Loop through each terrain texture
         for (int i = 0; i < terrainData.alphamapLayers; i++) {
 
             // Normalize so that sum of all texture weights = 1
             splatWeights[i] /= z;
 
             // Assign this point to the splatmap array
             splatmapData[x, y, i] = splatWeights[i];
         }
     }
 }
 
 // Finally assign the new splatmap to the terrainData:
 terrainData.SetAlphamaps(0, 0, splatmapData);

I am very thankful for any kind of advice helping me finding my error.

splatmapping.png (297.1 kB)
Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

Terrain Layers cannot be populated at the same time as the splats 3 Answers

Texture color difference between terrain tiles,Texture seam between terrain tile group 0 Answers

Handling large format textures (7.1Gb .TIFF) in unity 0 Answers

Fast way to texture a 10km map? 1 Answer

How to modify a Terrain at runtime and get back to original Terrain on exit? 2 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