Inspirateur / riverbed

A Minecraft-inspired Bevy game
MIT License
35 stars 2 forks source link

Rework Terrain Generation #24

Open Inspirateur opened 4 months ago

Inspirateur commented 4 months ago

Current terrain generation has a few problems:

Sidenote: Caves actually might be do-able with 2D noise only ? I'm thinking this could be done with 1 layer of 2D noise deciding where the cave "floor" is, and another deciding where the "roof" is. This could alleviate the need to move terrain gen to the GPU. Also parametrisation is easy to add :p

Extensible terrain generation

Current terrain generation code is messy and we can't add biome related logic to it easily. I need an API that easily lets me define Biomes with points in the parameter space (temp, hum, pH, Nitrates, etc.) and then lets me define custom terrain noise per biome (optional) which will be blended with normal terrain generation by multiplying with the biome value. Soil selection must also be abstracted away.

New system draft

  1. A first pass like we already have defines global terrain noise and parameters
  2. Biomes values are inferred given these parameters
  3. Custom biome noise can be defined for some biomes (ex: Desert dunes, canyon, etc.) and will be blended to the global noise based on the biome values. If no custom noise is provided we just proceed with the global terrain noise.
  4. Biomes also define layers of Blocks that will be applied relative to the terrain height (it can be as simple as saying that the top 3 blocks are grass)

Layer definition

The layers of blocks (which can be defined globally and per biome) could be of the form Layer(value, Block), with value being relative to the height specified by the terrain noise:

At the end of the process we get a final height noise and a sequence of Layer(value, Block) which will be applied in the order they're specified.

Future improvement

Having a clean and modular terrain generation is the first step before addressing the other issues. Once we get that, we can more easily rework terrain generation again to make it asset based (with custom biome noise written in files like desert.noise), which will enable a lot of things such as generating both GPU and CPU code and getting the slope value analytically for example.

Lemonzyy commented 1 month ago

I don't know if you've considered these issues, but I think they're very important in terms of Riverbed's goals.

All this may or may not concern you, but I just wanted to share some of the issues I've been thinking about for my game.

Inspirateur commented 1 month ago

Thanks for your input :) These are interesting questions ! I do need to evaluate whether GPU generation is worth it or not, and maybe provide a fallback method of generation if no GPU is present 🤔

Other solutions could include asking clients to generate the terrain indeed, and we could imagine cheating mitigation strategies such as validating random chunks ...

Anyway I'll see that when I go over this issue :)

nerdachse commented 1 month ago

I just want to chime in and say: cheat prevention also depends on what kind of multiplayer you want to have.

Is it just friends / small scale, is it competitive?

If a few friends play together and one friend cheats: so what? Let the friends handle that.

If you give everyone a seed and let the clients generate the terrain and one client cheats they could potentially see far away valuable ores (just an example), but the server can still decide not to send them the info that an ancient dragon sleeps near those ores. Or the server can decide that it won't send any updates for that far away chunk... Movement and actions should still be server side validated, to disallow instant teleportation etc. pp.

Just my 0,05

Inspirateur commented 1 month ago

I just want to chime in and say: cheat prevention also depends on what kind of multiplayer you want to have.

Yes, my stance on that is that being able to do multiplayer with friends is certainly valuable and is always the first step in development, but eventually I want to be able to have larger scale public server and that does require anti cheat measures, which we will figure out when we're there, meaning not now :p

Inspirateur commented 1 month ago

Added this internal crate https://github.com/Inspirateur/riverbed/tree/main/crates/riverbed_closest (what used to be "nd-intervals") for biome/plants selection. Hopefully this will allow us to blend custom noises per biomes together. It's just 1 small piece of the problem though.