Search Unity

Quad tree terrain rendering

Discussion in 'Graphics for ECS' started by snacktime, Apr 26, 2021.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Put this up quickly as a Unity package before it gets so tightly woven into our specific game that it's not easy to extract.

    https://github.com/gamemachine/QuadTerrainSystem

    I created this because we needed a continuous terrain with ocean floors spanning the entire scene, and we also needed very performant heightmap updates more so then what Unity's terrain is capable of.

    The approach is pretty much the same as Unity's instanced terrain rendering. Use a quad tree to sort out the set of patch meshes to use and what scale they should be. Culling against the camera frustum. Has a simple LOD system based on quad centers.

    This does NOT include anything terrain specific. No height/normal map stuff or terrain shading. Actually nothing terrain specific about the implementation, you could use it for water for example. A set of patch meshes is included along with a basic DrawMeshInstanced rendering setup. It doesn't actually use ECS just jobs and burst.

    I integrated with MicroSplat but the terrain specific stuff is still a work in progress and quite specific to our setup that requires ocean floors and multiple islands. MS integration is pretty straight forward, but mapping areas you have heights/normals for you will have to sort out.

    Forgot to include the test scene. Just create a GameObject with the QuadTerrainManager and link in the TestPrefab and it should work.
     
  2. RoughSpaghetti3211

    RoughSpaghetti3211

    Joined:
    Aug 11, 2015
    Posts:
    1,708
    pretty excited to try this thank you
     
  3. TheST4R

    TheST4R

    Joined:
    Apr 22, 2019
    Posts:
    4
    upload_2022-12-17_22-18-17.png

    I'm getting these errors, i'm sure im being stupid can u help me?
     
  4. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Did you include the unity collections package?
     
  5. stor314

    stor314

    Joined:
    Apr 26, 2019
    Posts:
    20
    has anyone sorted out how to apply a height map to this implementation? have no idea how to blend noise between the different sized meshes
     
  6. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    You need to provide the shading layer yourself and however you want to provide it with height data.

    This is also a fairly basic setup, Unity's terrain for example also does height based LOD. Ie if your terrain is very high then you might be at LOD0 but effectively at LOD1 or even LOD2 since the height has stretched the mesh. This is a more complex algorithm that has to account for not just height but height differences.

    For the best result you also want some tessellation in the shader to smooth out transitions. There are no cracks but popping will still be noticeable without that.

    Basically this is just a base to work from. It's useful because there were not any good implementations of basic meshing that I could find. They were all dated approaches or seriously flawed in some way. But you first need a reason to even need a custom terrain system (outside of just being a learning exercise). Or using something like this over Unity's terrain makes no sense.
     
  7. stor314

    stor314

    Joined:
    Apr 26, 2019
    Posts:
    20
    thanks for the quick response and the good pointers. i'm using this in an attempt to create a procedural infinite (lengthwise not heightwise) rock wall which means the meshes need to be rotated 90 degrees. unfortunately unity's terrain system can't rotate due to optimizations they make apparently, and rotating the character controller to accommodate for that won't work with my use case.

    i need game objects as well so can't use the instanced rendering setup. i ended up figuring out today that i can convert the vertices of the meshes to worldspace and use that as the sample coordinates for the noise, was able to get continuous noise across the meshes that way. performance seems fine so far as well. i'm definitely not capable nor do i have the time to create a terrain system with high performance in mind by myself, so i really appreciate you putting this package out as I think i'll be able to adapt it to my needs and in the long run it will save me a lot of time. i'm definitely a major noob when it comes to all of this stuff though so we'll see :)