This week(s) in Mirage #4

12.07.2019 @ Various(Addon, Blender, BlenderMarket, Development, Mirage, Python)

These last two weeks have been pret­ty busy, both in work/life and Mirage. On the mirage side, I port­ed the last mod­i­fi­er: flu­vial ero­sion. I spent the first week writ­ing the ini­tial imple­men­ta­tion and this week mak­ing it actu­al­ly work.

Many moons ago I wrote a pure Python imple­men­ta­tion of the vir­tu­al pipes hydraulic ero­sion algo­rithm. It was crazy slow. Even 10 iter­a­tions took many min­utes to com­plete. So I end­ed up adapt­ing Michel Anders’ (varken­varken) imple­men­ta­tion which uses numpy. Huge kudos to michael. This algo­rithm is already quite com­plex, but imple­ment­ing it in numpy is some wiz­ard-lev­el cod­ing 🙂

While this ero­sion code was quite good and I man­aged to refac­tor and tweak it for Mirage I still want­ed to rewrite it in Rust. The Rust code is less restric­tive, and eas­i­er to man­tain and change. With par­al­leliza­tion and the use of GPUs in the future it will even­tu­al­ly per­form bet­ter than the old one.

Michael based his code on this paper (with changes). I also added some changes of my own on top of that. This time around I’ve imple­ment­ed the algo­rithm in (almost) the same way as the paper to keep it sim­ple. And in the vein of keep­ing it sim­ple, I’ve decid­ed to call this mod­i­fi­er Water Erosion.

Check out the result of my first erod­ed ter­rain:

Stripey!

Turns out I was mess­ing up the axis in a few places in the ero­sion step. Luckily it was a sim­ple fix. Another prob­lem was get­ting the vari­ables right. These algo­rithms are del­i­cate when it comes to num­bers. Go too high on some­thing and you can get all kinds of prob­lems. Here’s what hap­pens if you add too much water with­out mov­ing the sed­i­ment prop­er­ly.

It is a cool effect though

After some more hours of debug­ging and play­ing with vari­ables I final­ly got the good stuff:

This takes about 50 iter­a­tions to be vis­i­ble and about 100 to look good. It runs fair­ly well for non-opti­mized code. I’m not plan­ning on doing any opti­miza­tions for this ver­sion, but I will make it run in par­al­lel for the next one. I also want to play some more with the vari­ables to see if I can get some­thing that looks close to this with less iter­a­tions. It will like­ly look rougher though, since water needs time (iter­a­tions) to move around the ter­rain.

Next up

Next week I’m going to keep hack­ing on the water ero­sion mod­i­fi­er. I still need to com­plete the UI and plug it into the engine. The one thing that both­ers me is the set­tings. There are 6 set­tings but they only make sense if you know the equa­tions and how it’s imple­ment­ed. I want to merge these into some­thing more intu­itive.

Further on I want to add oth­er source(s) of water. Right now the only source is rain falling ranom­ly on the ter­rain every iter­a­tion. I want to add a way to add springs which would then flow down­wards and cre­ate rivers. In the future we will also have full intrac­tive con­trol over this ero­sion with some­thing like a “rain brush” and a giz­mo to posi­tion springs.

If you want to have a seat in the first row when the next ver­sion of Mirage is released you can check it out on the BlenderMarket.

All the posts you can read

No comments yet

Leave a Reply

Your email address will not be published.