Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion for procedural generation #20

Open
Hideman85 opened this issue Sep 15, 2024 · 2 comments
Open

Discussion for procedural generation #20

Hideman85 opened this issue Sep 15, 2024 · 2 comments

Comments

@Hideman85
Copy link

Dear Nicholas McDonald,

I am currently looking for a simple way from a heightmap to generate river paths, and I came to your library. I am wondering how would you generate river path in a one go during the terrain generation phase of a world generation. So I'm looking to get a new map representing the path of the bed river with values from [-1.f, 0.f] as the depth/volume of the water. Would you mind exposing me a simple c++ example for doing so? Right now I'm a bit confuse with where I should start from.

Additionally, I'm wondering for better integration with existing c++ project, would you provide a CMakeLists.txt support to use as add_subdirectory()?

Thanks in advance for your help 🙏

@weigert
Copy link
Contributor

weigert commented Oct 1, 2024

Hi there, thanks for your question. Soillib doesn't technically do a "shallow water equations" simulation, meaning it doesn't explicitly model the "height" of the river - just the total discharge. Additionally, it doesn't actually compute "river paths" - just a field with discharge rates and directions, which can be visualized as rivers by just visualizing the amount of water.

I suppose that you already have a height-map? Is it a strict requirement that this runs in C++? I have ported the library mostly over to python in the most recent version, so it should be easier to just use in that sense.

The question is also whether you want to allow soillib to erode some of your terrain to make the paths more realistic, or if the shape of the height map should be perfectly fixed. That will change the approach.

A possible approach for you to take would be as follows:

  1. Use soillib to (slightly) erode your existing height map, leading to more realistic + meandering rivers
  2. Generate paths by simply "integrating" the paths from every point downstream using the simulated velocity map. This basically makes a river graph.
  3. Use some scaling law to convert the discharge into a height-width distribution. E.g. assume Height:Width ration = 1:2, then use the volumetric discharge to compute the "shape" backwards from that, everywhere along the path.

Would this work for you? This would be relatively easy to implement in python.

I will make an effort to add more examples soon that show how to use it for these use cases!

@Hideman85
Copy link
Author

Hi, thanks for your response and your interest in my current challenge 🙌

  1. Yes the heightmap can be eroded, I think it can bring value to the terrain generation initially generated from fractal simplex noises
  2. Yes c++ is a must, in the end I'm integrating this into a procedural world generation on my project. I also need to be HLSL compatible as my procedural generation works both threaded (OMP) on CPU for server side for instance and I'm using compute shaders for modern client side iGPU
    • On a side note, I think it is best to keep your lib in c++ then you can offer compatibility with bindings (Python, Java, Js, ...) if the core logic is optimized in c++ and even threaded it is great value to use it in any other language via bindings 😉

I think you're approach is looking good, I would add some consideration:

  • My terrain is generated by region and is theoretically "infinite", I'm adding this cause I've seen multiple algorithms where the "map borders" are like oceans and so rivers tend to converge to borders
  • My heightmap issued from noises is scaled on [-1.f, 1.f] (mostly common for noises) to save compute time it would be nice to work on that range and have a constant for the sea_level something for instance we could set to -0.25f right now
  • Also part of my generation process, I'm creating a temperature and humidity map to use them alongside elevation for biome selection. I'm thinking those heightmaps could be used as evaporation rate and dropfall rate 🤔

I dont know if this is something that could be made generic, I've seen quite some blogs/topics on river generation and it looks to be something not trivial (compare to mixing some noises 😅). In the end if your library support out of the box taking a heightmap (RO/RW as allow or not erosion) and produce a second heightmap representing the river beds with their heights could be awesome.

If you have already some implementation in mind and want to try a heightmap I have this one for instance (black = -1) here that is currently pretty smooth and could be a great example with erosion enabled 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants