Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Small question about procedural terrain generation

Discussion in 'General Discussion' started by Cnfnbcn, Feb 24, 2021.

  1. Cnfnbcn

    Cnfnbcn

    Joined:
    Apr 30, 2019
    Posts:
    4
    Am I getting it right, that when I'll make a single mesh that represents terrain using unity's built-in 2d perlinnoise function, then I'll be able to somehow add caves using whatever (perlin worms for example)? Or do I need to find solution with 3d noise?
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,325
    No.

    Unity's built in perlin noise function is 2 dimensional. And it can be used to produce a height map.
    Caves are 3 dimensional. Meaning you'll need to poke holes in the heightmapped terrain and stuck a cave inside.... OR....

    You'll need to look for 3 dimensional version of perlin noise.

    However, 3d perlin noise will not produce a terrain, but rather something similar to a cloud.

    20210224-224551-1314.gif
    And to turn 3d perlin noise into a mesh you'd need marching cubes algorithm, voxelization or something similar.
     
    Antypodish likes this.
  3. Cnfnbcn

    Cnfnbcn

    Joined:
    Apr 30, 2019
    Posts:
    4
    what I'm trying to do is make a voxel procedural world similar to Cube World or Minecraft. Most guides through the internet use Mathf.PerlinNoise so that's why I ask.

    Research to be continued.
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,325
    Perlin noise ALONE will produce a smooth cloud-like structure. Like the one in the gif I uploaded. Even if it s a "cube world".

    To make minecraft terrain you'll need multiple noise patterns, they'll need to be altered, filtered, combined and so on. For example, you could make a base 2d pattern which will create a heightmap, then could combine it with 3d noise to make it uneven, then you could combine it with additional noise iteration to make caves.

    For example, this is also perlin noise:
    upload_2021-2-25_0-49-54.png

    And this is what happens if I start combining multiple noise functions.
    upload_2021-2-25_0-52-41.png
    Not exactly a "cave", but going in that direction.

    Basically, regardless of what you do, landscape generation can be thought of as a function that for any given point in space returns density (and type of the matter there).
    So, you start with a function that returns density based on a heightmap produced by a perlin noise. Then you combine it with a function that carves holes and cave systems. Then you blend them together in such way that areas close to surface do not turn into swiss cheese and only a few tunnels are produced near the surface, while a lot of them are created underground.

    That's the rough idea of it.
     
    Last edited: Feb 24, 2021
  5. Cnfnbcn

    Cnfnbcn

    Joined:
    Apr 30, 2019
    Posts:
    4
    A small addition: Cube World is 2013 game that procedurally generates its world as Minecraft. I added this as it seems you don't know about the game. However, overall I got your idea
     
  6. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    968
    I remember this thread having a lot of information about creating a minecraft-like world