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. Dismiss Notice

Marching Cubes & smooth terrain problems

Discussion in 'General Discussion' started by magic9cube, Jun 22, 2017.

  1. magic9cube

    magic9cube

    Joined:
    Jan 30, 2014
    Posts:
    58
    Hello,

    I'm working on a marching cubes based terrain engine in my spare time. The issue i have currently is the step like nature of the terrain. In some instances slopes will be smooth but only on particular angles. There is a clue here but i have not managed to figure out what's happening as of yet. Any suggestions appreciated.
     

    Attached Files:

  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,323
    Well. Most likely you messed up the implementation of the algorithm.

    Marching cubes are supposed to sample distance from the iso-surface at it s corners, using "inside surface/outside of surface" lookup triangulation, AND points used during triangulation are calculated using interpolation of edges... or in other words, the points where iso surface intersects cube edges. Meaning... if you forget about "interpolate values" or "use point where edge intersects the surface" and use cube corner coordinates, you'll get the steps.

    It'll also help you if you visualize the grid using DrawGizmo renderer. Something like this, for example:
    debug.png
     
    Not_Sure and magic9cube like this.
  3. Not_Sure

    Not_Sure

    Joined:
    Dec 13, 2011
    Posts:
    3,541
    Yeah, I was on a huge marching cube kick for a long, long time and best I can tell is exactly what @neginfinity said.
     
  4. andrewgotow

    andrewgotow

    Joined:
    Dec 28, 2013
    Posts:
    18
    This is a common problem if you're using a binary data set.

    Marching Cubes generates an approximate "isosurface" - a theoretical shape in a field of samples which has the same value over its entire surface. If you're using binary data (Empty vs Full) to store your voxels, the surface will always cut through the center of each voxel in your sample grid, since the value between empty and full will always be "half empty".

    Instead, try representing your voxels using something like a floating-point density function. Higher values are more dense, and values with a density of 0 are open air. This will create the smoother mesh you're looking for.
     
    SamFernGamer4k likes this.