Search Unity

Question Applying noise to a sphere produced from Marching Cubes

Discussion in 'Scripting' started by pcdcreeper, Jun 19, 2021.

  1. pcdcreeper

    pcdcreeper

    Joined:
    Feb 24, 2021
    Posts:
    3
    Hi All!

    I am currently modelling planets using the marching cubes algorithm. My current approach for making a spherical density revolves around taking the distance of the corner point from the center, and seeing if it is greater than or equal to the intended radius:

    Code (CSharp):
    1. var v = new Vector3(x - radius, y - radius, z - radius);
    2.  
    3. if (v.sqrMagnitude >= (radius * radius)) {
    4.     point = 1;
    5. }
    This works amazing, however my efforts are halted when I attempt to make reasonable 3D noise determine the "height" of the surface. In my head, I imagine I could add an arbitrary value to the variable v determined by some function (my actual sample volume is always larger than the radius, so this avoids any cutoffs), but the problem arises in determining a specific function for the task.

    I want to avoid any true 3d noise algorithms, as this causes an odd "fish tank" feel to happen. I have also attempted making a noise area, and then adding the "sea level" sphere at the bottom, but I do not like this either.

    It seems to me that I need to implement some form of 2d height map data, but how I might do that is lost on me. I really appreciate any help regarding this subject.

    Thank you!
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    I don't know marching cubes in detail and how it fits in the equation here.

    Not that with 2d noise you will have seams. If you want a seamless spherical planet you HAVE to use 3d noise.

    I wrote about the process of sampling 3d noise to generate heightmap textures. Read this as "introduction" and ask if you have specific questions remaining. But procedural planet generation is quite an undertaking so prepare for some headaches ;).
    https://forum.unity.com/threads/lib...pherical-generated-noise.919007/#post-6020918
    https://forum.unity.com/threads/trying-to-map-a-sphere-using-perlin-noise.717857/#post-4797671

    I don't understand that. Could you elaborate?
     
    pcdcreeper likes this.
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Not saying it would be impossible to make it work (as technically anything you can formalize is implementable), but combining 2D height map data where you already have an algorithm able to work on 3D data seems like a huge waste, and would likely be hard to work with.

    I would create a mix of 3D noise A and create some other function B, which returns values between 1 and 0 as well, according to the position and inner + outer diameter of a planet.
    Then sample positions where you multiply A * B and take that as input for your marching cubes algorithm. The result should print you nice planets according to your noise mix A, which B acting like a fall off map, just for planets.
     
    Last edited: Jun 19, 2021
    pcdcreeper likes this.
  4. pcdcreeper

    pcdcreeper

    Joined:
    Feb 24, 2021
    Posts:
    3
    Thank you! Ill take a look at this, and what I mean is that when I use a 3d noise function, The resultant shape is almost always a sphere with stuff "cut out" of it. Making the noise additive does not help either, and I get very "reef rock" or "pumice rock" results. I want a planet with hills and mountains determined by a heightmap-ish function, and caves with 3d noise. I can get caves to work, but nice, organic hills are seemingly impossible.
     
    Last edited: Jun 20, 2021
  5. pcdcreeper

    pcdcreeper

    Joined:
    Feb 24, 2021
    Posts:
    3
    This seems implementable! I will test it when I get home from work!