Search Unity

Question Is it possible create voxel terrain use buildin terrain tools?(MineCraft style)

Discussion in 'General Discussion' started by Stormer2020, Mar 23, 2023.

  1. Stormer2020

    Stormer2020

    Joined:
    Sep 14, 2020
    Posts:
    92
    Is it possible create voxel terrain use buildin terrain tools?(Looks like MineCraft style)

    I'm using buildin terrain tools create a terrain by height map.

    It looks good. But i wanna the voxel style. It's too smooth for me.

    Is here any method change the terrain to voxel style?

    I was wrote a terrain generator (Procedual create mesh in runtime). The performance not good even use job system. My game build at WebGL, can't use Multi-thread also.

    So, I'm trying the buildin terrain tools.It's have better performance.

    I don't need modify the terrain in runtime.

    Please help, thanks~ :)

    1.png 2.png 3.png
     
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    It is impossible to make voxel terrain using builtin tools.

    Built-in terrain uses heightmaps, meaning it is a subdivided flat plane extruded vertically according to altitude.

    This approach cannot form voxels or minecraft cubes.
     
    Stormer2020 likes this.
  3. Stormer2020

    Stormer2020

    Joined:
    Sep 14, 2020
    Posts:
    92
    Thanks~ I'll look for other way.
     
  4. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,074
    You can sample the terrain height by raycast or by directly reading terrain data.
    And generate voxels in proper position.

    But yes you cannot change terrain to voxels since it is impossible to have vertical (90 deg) sides using terrain.
     
    angrypenguin and Stormer2020 like this.
  5. Stormer2020

    Stormer2020

    Joined:
    Sep 14, 2020
    Posts:
    92
    I see, thank you bro!
     
  6. Tmtakala

    Tmtakala

    Joined:
    Mar 12, 2014
    Posts:
    16
    I used the help of ChatGPT to quickly generate a Unity script for generating Minecraft-like terrain. Well, the initial version was quick, but it took time to polish. More example images, the script itself, and a description of its creation can be found at this here Github page.

    Be aware that this script has a lot of room for optimization, as it's not currently utilizing multithreading/jobs. Increasing the voxel grid size slows down the world creation significantly, as does the number of flood-filling water sources and Perlin worms.

     
  7. Stormer2020

    Stormer2020

    Joined:
    Sep 14, 2020
    Posts:
    92
    Wow, so cool~ The code even use ECS(Unity.Entities). Thanks!
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,205
    An older release (0.51). ChatGPT isn't aware of the newer releases. I hope they train it on newer data soon.
     
    Stormer2020 likes this.
  9. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,573
    Basically, you cannot make voxel terrain using unity terrain. Because it uses heightmaps.

    You can absolutely generate minecraft-style meshes and build a landscape out of those.
     
    Stormer2020 likes this.
  10. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    That is superb result of the effort, using modern tools.
    More so exciting, it used ECS to some extend, and even 0.51, while I would expect some around 0.17. Great outcome.

    How long did take you to build and modify terrain system, including giving ChatGPT right prompts.

    How much time proportionally you spent on prompts itself, vs correcting the code, in its current state?
     
  11. Tmtakala

    Tmtakala

    Joined:
    Mar 12, 2014
    Posts:
    16
    Thank you for the positive feedback Antypodish!

    I started my experiments by querying GPT4 via OpenAI's Python API via Python. I spent 3-4 hours with this, because I was solely focused on using only one prompt to deliver the script, and the answers often took several minutes to get back to me, while I also got frequent server disconnect errors. Therefore I wouldn't add this time into the total duration. Those hours only taught me that I would need to do the script creation with multiple prompts, and that ChatGPT's solution for entity creation (attaching the RenderMesh) didn't work with ECS 0.51 and that I needed to fix it. Most of the time went into finding the fix, because there were no error messages, I was new to ECS and unable to use its debugging systems to figure out why the meshes wouldn't render.

    So after that first attempt, I switched to ChatGPT Plus and using multiple prompts. With this approach the "alpha" version of the terrain generation script didn't take many minutes to create with ChatGPT Plus, as it was produced with the first 4 prompts (1 for template, 3 to implement the empty methods in the template). The whole dialogue can be viewed here:
    https://github.com/ttakala/AI-Exper...chat-gpt-unity-terrain-generation-with-ecs.md

    At this point I only needed to fix the above-mentioned entity creation, which didn't take long because now I knew exactly the 2-3 lines of code I had to change. So few minutes after the first prompt I was generating terrains that looked like this:


    There are obvious issues here, but it didn't take more than a few minutes to write two additional prompts, each asking for a different updated method, which would fix the placements of the trees and the grass/foliage, as well as make the water "mountains" into proper lakes with flood fill.

    After those prompts there were still 2-3 bugs: the flood fill that I requested didn't have proper end conditions etc., but these were quick to fix. My final prompt asked for more varied and better looking trees. At this point a total of maybe 30 minutes had passed.

    Finally I wrote some vanity updates myself to make the trees look better and the terrain carving a bit more natural. I don't remember how many minutes that took, because it was interspersed with many other tasks that took several hours to finish: I was simultaneously writing about my experience and generating maps the size of 512x512x64 (each took 10 minutes to generate).
     
    Stormer2020, Ryiah and Antypodish like this.
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,780
    Superb detailed respone @Tmtakala.
    Many thx.

    It is amassing way to utilise ChatGPT for generating soch code.

    Briefly lurking through the git repo, it shows your deep understanding of the problem, you have aimed to solve.
    Many technicalities expertise is involved here.
    Well done.
     
    Tmtakala likes this.