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

Best approtch to make a low poly marching cubes terrain smoother?

Discussion in 'World Building' started by MCrafterzz, Jun 28, 2019.

  1. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    Hey, I'm working on a low poly marching cubes terrain editor and got most stuff working. What I'm really unsure about tho that I haven't found a solution to on google is to smooth it out. As all points have a density value from 0 to 1 it's possible to create smooth terrains like this small example that I did:

    But more often when modifing the terrain it turns out like this:

    Doesn't look so good at all :(. So I want to create a brush that smooths the terrain in a radius to achieve the result in the first picture without manually changing every point again and again, and to make it less tedious. Any ideas? Maybe I can use some sort of blur algoritmen but how?
     
  2. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    229
    Hmm I am no expert in this matter so take what I say with a grain of salt.

    I would interpolate each node height value with the ones that are connected to it. That should smooth it out.
    A tool that applies this effect would have a radius and do it for each node within the radius.
    Quick example done in paint:
    (We want to smooth the point (1,5,0))
    upload_2019-6-30_13-11-45.png

    You could even have a factor that gives more weight to the original height.
    For example:

    Factor = 2
    (5*2+3+3.5+3+2.5)/(4+2) = 3,66666667
     
    Last edited: Jun 30, 2019
  3. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
    It works quite well to take the average point of the six neightboring points (up/down/left/right/forward/backwards) the only problem is that it seems to always lower the terrain even tho the ground is flat from the beginning.
     
  4. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    229
    That is strange. Could you provide the piece of code?
     
  5. MCrafterzz

    MCrafterzz

    Joined:
    Jun 3, 2017
    Posts:
    354
  6. jc-drile77

    jc-drile77

    Joined:
    Jul 1, 2014
    Posts:
    229
    That´s is a huge chunk of code :rolleyes:
    I would have to study the differents classes and how do they work, but I have little time available.
    Anyways I cannnot see how weighted average (linear interpolation) can reduce the height of a plane parallel to the XZ plane. There must be something wrong somewhere in your code. (n*Z)/n is always Z (disregarding floating-point errors).
    You might also want to try another type of interpolation, perhaps bicubic interpolation.