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

Faster Voxel Terrain Generation

Discussion in 'Scripting' started by sterynkng14, Aug 9, 2015.

  1. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    Hello, I've been following this http://forum.unity3d.com/threads/tutorial-procedural-meshes-and-voxel-terrain-c.198651/ tutorial, but I've noticed the chunk loading is rather slow (at least on my system). I deep profiled it and found that the perlin noise is what is taking so long to load due to the many calls to it. So my question is rather than making every call to the noise to determine how the chunk is loading, is there some possible way I can run a call for it at the beginning in order to predetermine how it will load throughout the loading. Is there already tutorial for doing this out there? Is there just an all out more efficient way of voxel terrain generation? I a decent understand of scripting and coding, but I am new to terrain generation so any help would be great. This is just a learning experience so it's not commercial by any means.
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,148
    EliasMasche likes this.
  3. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    I have done that one actually, but I will check it out anyways.
     
  4. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    I suggest using threading if not already, but if you want it much faster you should use the GPU for noise generation. I think there is a free asset called Turbulence.
     
    Ryiah likes this.
  5. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    Using the GPU for noise computing sounds like a good idea. And I didn't know they had threading capability in unity, I am going to have to look further into that.
     
    Last edited: Aug 9, 2015
  6. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    @Brainswitch How would I go about threading my chunks, assuming that's what you meant? Or thread the Noise.Generate(x, y, z) function yet still receive it's return value?
     
  7. Brainswitch

    Brainswitch

    Joined:
    Apr 24, 2013
    Posts:
    270
    Mono has threading, which means Unity has it. Although almost everything related to Unity classes (MonoBehaviour, Mesh, MeshCollider etc) needs to be done on the Unity main thread.

    I meant threading the noise generation (but GPU noise generation will be much faster anyway), but you should thread the mesh creation - or all parts related to creating the vertices and the normals. Setting them to a Mesh needs to be done on the Unity main thread. You are probably creating a List<Vector3> or an array of Vector3s and then setting chunkMesh.vertices. It's only the mesh.vertices = array of Vector3s line that needs to be done on the Unity main thread.
     
  8. sterynkng14

    sterynkng14

    Joined:
    Sep 19, 2013
    Posts:
    36
    Oh yeah, threading the mesh generation is definitely a smart idea, didn't even think of that, too busy with the noise haha and do you know of any good docs based around GPU noise generation, or GPU processing in general?