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 Jojo B · Feb 16, 2014 at 04:12 AM · terrainwatergeneration

hydro erosion problems

hey so ime making some random terrain and ime trying to do hydro erosion on it but i just cant seem to get it working how i want. so would anyone be kind enough to look through this code and see if they know where the problem is. not sure if its my method or just the variable quantities

public float[,] Water; //amount of water

 public Vector2[,] Velocity;        //velocity of water

 public float[,] Sed;            //sediment contained within water
 
 public int ErosionIts = 100;     //iterations of the erosion algorythem
 public float Rain = 5f;        //amount of rain
 public float ErosionRate = 0.001f;    //rate at wich rock is tuned to sediment
 public float EvapRate = 0.1f;    //rate at wich water evapirates
 
 public void Erode (){
     for (int i = 0; i < ErosionIts; i++){
         
         Water = new float[MapSize,MapSize];
         Velocity = new Vector2[MapSize,MapSize];
         Sed = new float[MapSize,MapSize];
         
         for (int x = 0; x < MapSize; x++){
             for (int y = 0; y < MapSize; y++){
                 Water [x,y] += Random.value*Rain;//add rain to each square
                 
                 Velocity[x,y] = new Vector2(0,0);//reset value
                 
                 
                 //find the largest drop and asighn it as a velocity in the given directtion
                 float RelativeHeight = 0;
                 
                 if (x < MapSize-1){
                     RelativeHeight = HeightMap[x,y]+Water[x,y]-HeightMap[x+1,y]-Water[x+1,y];
                     if (RelativeHeight > Velocity[x,y].magnitude){
                         if (RelativeHeight > 0){
                             Velocity[x,y] = new Vector2(RelativeHeight, 0);
                         }
                     }
                 }
                 
                 if (x > 0){
                     RelativeHeight = HeightMap[x,y]+Water[x,y]-HeightMap[x-1,y]-Water[x-1,y];
                     if (RelativeHeight > Velocity[x,y].magnitude){
                         if (RelativeHeight > 0){
                             Velocity[x,y] = new Vector2(-RelativeHeight, 0);
                         }
                     }
                 }
                 
                 if (y < MapSize-1){
                     RelativeHeight = HeightMap[x,y]+Water[x,y]-HeightMap[x,y+1]-Water[x,y+1];
                     if(RelativeHeight > Velocity[x,y].magnitude){
                         if (RelativeHeight > 0){
                             Velocity[x,y] = new Vector2(0, RelativeHeight);
                         }
                     }
                 }
                 
                 if (y > 0){
                     RelativeHeight = HeightMap[x,y]+Water[x,y]-HeightMap[x,y-1]-Water[x,y-1];
                     if (RelativeHeight > Velocity[x,y].magnitude){
                         if (RelativeHeight > 0){
                             Velocity[x,y] = new Vector2(0, -RelativeHeight);
                         }
                     }
                 }
                     
                 //erode or deposit soil based upon velocity and amount of watter 
                 float PreviusSed = Sed[x,y];
                 Sed[x,y] = Velocity[x,y].magnitude * Water[x,y] * ErosionRate;
                 HeightMap[x,y] -= Sed[x,y] - PreviusSed;
                 
                 //move the water and its contained sediment
                 float w1 = Water[x,y];        //initial water level of this tile
                 float w2;                    //initial water level of target tile
                 float w3;                    //final water level of this tile
                 float w4;                    //final water level of target tile
                 
                 float s1 = Sed[x,y];        //initial sediment level of this tile
                 float s2;                    //initial sediment level of target tile
                 float s3;                    //final sediment level of this tile
                 float s4;                    //final sediment level of target tile
                 
                 float h1 = HeightMap[x,y];    //height of this tile
                 float h2;                    //height of target tile
                 
                 //calcuate and apply final levels 
                 if ((x < MapSize-1) && (Velocity[x,y].x > 0)){
                     w2 = Water[x+1,y];
                     s2 = Sed[x+1,y];
                     h2 = HeightMap[x+1,y];
                     
                     w3 = (w1+w2+h2-h1)/2;
                     w4 = w1+w2-w3;
                     s3 = ((s1*(w1-w3))/w1)+s1;
                     s4 = s1+s2-s3;
                     
                     Water[x,y] = w3;
                     Sed[x,y] = s3;    
                     Water[x+1,y] = w4;
                     Sed[x+1,y] = s4;
                 }
                 if ((x > 0) && (Velocity[x,y].x < 0)){
                     w2 = Water[x-1,y];
                     s2 = Sed[x-1,y];
                     h2 = HeightMap[x-1,y];
                     
                     w3 = (w1+w2+h2-h1)/2;
                     w4 = w1+w2-w3;
                     s3 = ((s1*(w1-w3))/w1)+s1;
                     s4 = s1+s2-s3;
                     
                     Water[x,y] = w3;
                     Sed[x,y] = s3;                        
                     Water[x-1,y] = w4;
                     Sed[x-1,y] = s4;
                 }
                 if ((y < MapSize-1) && (Velocity[x,y].y > 0)){
                     w2 = Water[x,y+1];
                     s2 = Sed[x,y+1];
                     h2 = HeightMap[x,y+1];
                     
                     w3 = (w1+w2+h2-h1)/2;
                     w4 = w1+w2-w3;
                     s3 = ((s1*(w1-w3))/w1)+s1;
                     s4 = s1+s2-s3;
                     
                     Water[x,y] = w3;
                     Sed[x,y] = s3;                        
                     Water[x,y+1] = w4;
                     Sed[x,y+1] = s4;
                 }
                 if ((y > 0) && (Velocity[x,y].y < 0)){
                     w2 = Water[x,y-1];
                     s2 = Sed[x,y-1];
                     h2 = HeightMap[x,y-1];
                     
                     w3 = (w1+w2+h2-h1)/2;
                     w4 = w1+w2-w3;
                     s3 = ((s1*(w1-w3))/w1)+s1;
                     s4 = s1+s2-s3;
                     
                     Water[x,y] = w3;
                     Sed[x,y] = s3;            
                     Water[x,y-1] = w4;
                     Sed[x,y-1] = s4;
                 }
                 
                 
                 Water[x,y] *= EvapRate;// evaperate some water
                 
                 
             }
         }
     }`

Thanks

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 AlucardJay · Feb 16, 2014 at 04:22 AM 0
Share

but i just cant seem to get it working how i want , look through this code and see if they know where the problem is , not sure if its my method or just the variable quantities

Need more information, cannot guess the problem. What is the desired result, and what is the current result?

avatar image Jojo B · Feb 16, 2014 at 12:55 PM 0
Share

k sory it was like 4 o clock and i wanted to get some sleep ok so basically its designed to erode at a height map and smoth out rough terrain as well as form rivers and such things howether its actuly making the terrain alot more jagid so its doing the opiset of what its ment to i guess its probably the deposition and moment of sediment. left is with water erosion(meant to be smooth) right is without it alt text

untitled.png (39.5 kB)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Dmitry Soldatenkov · Feb 26, 2016 at 08:15 PM

http://forum.unity3d.com/threads/terrain-water-erosion.388374/ This asset contains all the source code for erosion you want.

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

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why does my water display itself above my trees? 1 Answer

Rivers on procedurally terrain 0 Answers

Problem with Terrain.SampleHeight 0 Answers

Turn-Based Strategy Terrain Generation 1 Answer

Google Earth, Sketchup, Global Mapper - best way to generate terrain 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