Giter Site home page Giter Site logo

weigert / simplehydrology Goto Github PK

View Code? Open in Web Editor NEW
596.0 12.0 40.0 35.17 MB

Procedural Hydrology / River / Lake Simulation

C++ 94.99% C 2.14% Makefile 0.15% GLSL 2.72%
erosion erosion-process hydrology-simulation hydrology procedural-generation procedural procedural-terrain terrain-generation terrain-rendering terrain

simplehydrology's Introduction

SimpleHydrology

C++ implementation of a particle based procedural hydrology system for terrain generation. This extends simple particle based hydraulic erosion to capture streams and pools.

Rendered using my homebrew TinyEngine.

Link to a blog post about this

Banner Image

Compiling

Use the makefile to compile the program.

make all

Dependencies

Erosion System:
- gcc
- glm

Renderer:
- TinyEngine (and sub dependencies)

Usage

./hydrology [SEED]

If no seed is specified, it will take a random one.

Controls

- Zoom and Rotate Camera: Scroll
- Arrow Keys: Move Camera Position
- WASD / C / V: Move Camera Anchor
- Toggle Pause: P (WARNING: PAUSED BY DEFAULT!!)
- Toggle Map View: M
- Toggle Hydrology Map View: ESC

Screenshots

Example Output 1

Example Output 2

Example Output 3

Example Output 4

Example Output 5

Reading

The main file is just to wrap the OpenGL code for drawing. At the very bottom, you can see the main game loop that calls the erosion and vegetation growth functions.

The part of the code described in the blog article is contained in the file water.h. Read this to find the implementation of the procedural hydrology.

The trees are implemented in vegetation.h.

All of the code is wrapped with the world class in world.h. The bottom of this file contains a bunch of stuff relevant for rendering, but not the erosion system.

The rest is shaders and rendering stuff.

Update October 2021

The rendering system has been updated to use vertex pooling to remove all remeshing cost.

Improvements have also been made to the flooding algorithm to increase the search plane at fixed, deterministic increments by iteratively looking for the lowest point on the boundary. Additionally, the region can be grown by only tracking the boundary.

For a next iteration on this system, see SoilMachine.

Update January 2023

The flooding system has been removed for now, because of buggyness and slowness. A better system has been proposed here.

Momentum and discharge maps are now explicit and interact physically with the water particles, giving river meandering behavior.

Parameters have been properly separated out.

Libnoise dependency has been removed.

Windows Ports

Windows ports for this program exist:

https://github.com/pawel-mazurkiewicz/SimpleHydrologyWindows

https://github.com/Roipo/SimpleHydrology

License

MIT License.

See my website for a more detailed copyright notice.

simplehydrology's People

Contributors

weigert avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

simplehydrology's Issues

Compilation error

g++ -std=c++17 SimpleHydrology.cpp TinyEngine/include/imgui/imgui.cpp TinyEngine/include/imgui/imgui_demo.cpp TinyEngine/include/imgui/imgui_draw.cpp TinyEngine/include/imgui/imgui_widgets.cpp TinyEngine/include/imgui/imgui_impl_opengl3.cpp TinyEngine/include/imgui/imgui_impl_sdl.cpp -Wfatal-errors -O3 -I/usr/local/include -L/usr/local/lib -lnoise -lX11 -lpthread -lSDL2 -lnoise -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lGL -lGLEW -lboost_serialization -lboost_system -lboost_filesystem -o hydrology
In file included from SimpleHydrology.cpp:3:
source/world.h:208:46: error: non-local lambda expression cannot have a capture-default
  208 | std::function<void(Model* m)> constructor = [&](Model* m){
      |                                              ^
compilation terminated due to -Wfatal-errors.
make: *** [makefile:11: all] Error 1

Is there anything I can do other than tweaking the source code?

How to export the stream map as a data array?

Thank you for sharing this excellent work!

I'm trying to build some 3D river channel models based on your work, so I need to know the river positions on the map. Is there any way to export a stream map like this as a data array? Also, do these streams have pixel-wise water depth data? If they do, how can I export the water depth data?
fig

Compatibility with a layer based procedural generation strategy

I'm interested in implementing a system similar to what's described in this blog post. Do you think the hydrology simulation model you describe here/in your blog post can be made compatible with this type of procedural generation?

The issue as I see it is you don't know which tile a particle could end on given a starting location without running the simulation, so you can't generate one tile without generating its neighbours (and so on ad infinitum.)

So might there be a way to make this system only dependent on "lower layers" of information?

build troubles

Hi there!

Sorry to bother you, I'm assuming this is more on me, since it's a short list of build instructions and I'm very experienced with C things.

I'm assuming with glm you meant https://github.com/g-truc/glm and I did successfully build your tinyengine. But when I try to run the make all for this project, I get this error:

g++-10 -std=c++20 -ggdb3 SimpleHydrology.cpp -Wfatal-errors -O2 -I/home/max/.local/include -L/home/max/.local/lib -lTinyEngine -lX11 -lpthread -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lGL -lGLEW -lboost_system -lboost_filesystem -o hydrology
make: g++-10: No such file or directory
make: *** [Makefile:8: all] Error 127

If it's a short make list, maybe it's an easy fix for me?

Cool project! Thanks for open sourcing!

If I can't make it work, I will figure out something else, but this is certainly a great inspiration.

Evaporation does not affect soil concentration

Note: this report is mostly based on the blog post. Might be that the code already does something that I missed

The way you have implemented evaporation applies it as a constant factor to the overall volume of your drop. Shouldn't it only affect the liquid parts, leaving the sediment unaffected while also updating the sediment concentration? Something like this:

float sedimentVolume = drop.volume * drop.sediment;

// Only evaporate liquid
float newLiquidValue = drop.volume - sedimentVolume * (1.0-dt*evapRate);
drop.volume = sedimentVolume + newLiquidVolume;

// Calculate new sediment percentage
drop.sediment = sedimentVolume / drop.volume;

Otherwise you'd effectively evaporate sediment.

Map resolution

Hello,

I browsed through the code but couldn't identify a point where the map resolution is defined, is there any ? How did you choose your simulation parameters ?

Thank you

Can't compile, "Buffer" not declared anywhere

I'm trying to compile the current master (01dde83), using the current master of TinyEngine cd43198, but I get this error:

SimpleHydrology.cpp:53:2: error: ‘Buffer’ was not declared in this scope
   53 |  Buffer modelbuf;
      |  ^~~~~~

I could find no reference to a "Buffer" in the code.

Clarification for updates on the flood algorithm

Hi,
Great work. I am curious what do you mean in the last update by "flooding is activated but the spill number is set to zero (effectively off - not fully satisfied with the water table computation system)"?
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.