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

Question help with simplexnoise

Discussion in 'Scripting' started by DroneNz, Jun 13, 2023.

  1. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    so here is my problem, i'm doing a boxel game with terrain generation, i tested with perlin noise and now simplex noise, e liked simplexnoise way more, but here is the problem
    upload_2023-6-13_1-4-25.png

    this is the terrain its generating, its is ok for a planice, but i wanted to make very high mountains and mantain this planice aspect

    something very simillar to this


    so how do i use the noise i generated?, i mean, i already know how to use noise to generate terrain, but how can i increment the noise i generated?, i liked the variables that generated this terrain in the photo, but i I would like the mountains that were generated to be taller, but at the same time keeping the base as a plain, having high mountains and smooth terrain
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Select an arbitrary height that is between the highs and the lows. Subtract this height from the voxel's height. Multiply the result with some factor. Then offset.

    In short, the formula is
    Code (csharp):
    1. new_h = (c + m(base_h - o))^p
    o = sampling offset
    m = scaling factor
    c = world space offset
    p = absolute power

    If you intend to use p (MathF.Pow), make sure that the base is brought into positives with c.

    Here's an example on desmos
     
    DroneNz and DevDunk like this.
  3. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Don't forget that you can also do
    Code (csharp):
    1. new_h = max(0, (c + m(base_h - o)))^p
    If you really like what you're getting but would like to avoid negatives.
    Of course, this will also introduce sharp angles when gradients hit the minimum.
    However, there are ways to make the transitions smooth, you can learn more about polynomial smooth minimum (smin) here.

    I cobbled up an example that uses smax instead [desmos] where:
    f = ground truth
    g = custom modulation
    s1 = union of the two
    s2 = union after smoothing

    This way you can do whatever you want with the shaping and blending.
    Feel free to change the original modulation into something else.
     
  4. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Here's a screenshot for future-proofing

    upload_2023-6-14_23-6-13.png
     
  5. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Just two cosines playing together

    upload_2023-6-14_23-19-43.png
     
  6. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,588
    Basically what @orionsyndrome said. For voxel terrain, simply mix and match coherent 3d noise functions, but the idea is the same. Your voxel engine just visualizes a noise input. Any terrain you want to visualize must thus already be contained in the noise data.

    Receiving "interresting" terrain is the creative part. You cant just plug in default perlin or simplex and expect great results. You will have to layer different octaves of noise, using varying amplitudes and frequencies to receive more interresting terrain. An octave represents one part of the noise you later combine. You could, for example, create one octave of noise to give you your general terrain shape. For the next octave you could, say, halve the amplitude and double the frequency. This makes the second octave have less effect on the overall shape of the terrain, but instead it adds details to it when you average the two octaves.

    You can use any number of octaves of perlin noise, or even mix and match different coherent noise functions in the process. You are also not limited to averaging the noise returns. You could "or" them, by simply checking if any of your noise functions returns a valur within your terrain threshold for that voxel. If you had one noise function which returned you a plains like terrain, and one which returned huge mountains and valleys, you could thus combine them to have mountains, but no valleys, on a plain. Usually you want a more smooth transition however. For that you would weight the noise differently.

    Sebastian Lague also did a nice series on procedural generation where he goes over all these topics and much more. While he uses heightmap terrain and not voxel based terrain, the ideas involved are basically identical. You'd simply be using 3d noise instead of 2d noise.
     
    DroneNz and orionsyndrome like this.
  7. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    @Yoreki Thanks for helping out, I was too busy to explain it all. Looks like the equations I provided didn't help much.
     
  8. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,588
    I think the images get the idea across well. It's the same thing in 3d, but visually it's a lot easier to explain in 2d.

    When i looked for good visualizations of the involved concepts with 3d examples (tho it's 2d noise, but that does not matter), i found this website, which has really helpful gifs: https://docs.quixel.com/mixer/1/en/topic/noise-layer

    That said, all this is more about adding detail and making terrain more interresting. To get some simple kind of mountain, OP can just add any coherend 3d noise function scaled to a sufficiently high amplitude and a fitting resolution (frequency). Wont be beautiful mountains, but it's a first step.
     
    Last edited: Jun 15, 2023
  9. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    I'm having some difficulty understanding the equation, but i'm getting there, thanks!! the graph helps a lot
     
  10. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    the smooth clamp in this topic, how could i achieve this?, i tried standard clamping i got a cool result, will try a few things too

    trying to lower this areas
    upload_2023-6-15_0-21-11.png
     
  11. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    I didn't understand what exactly are the parameters, could you give me a insight?
     
  12. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Well the parameters are pretty much arbitrary, but you can play with them on desmos.
    None of this is hard science, we use math in creative ways to shape the overall noise like Yoreki explained.
    There are no names, other than the most generic math ones -- multipliers, offsets, powers ...

    It is pretty much assumed that if you want to play with noise and voxel volumes you need to understand such basic equations as
    new_h = (c + m(base_h - o))^p
    . It couldn't be any more basic than this, it's practically primary school stuff. If you can't comprehend it then this whole topic is probably way over your head.
     
    Yoreki likes this.
  13. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,588
    Look at the clamping image. From their description i take it they clamp the input to the noise function. Not the output. Basically this simply means that lower altitudes become solid terrain, according to the clamp value. Thats why you see the "floor lift up" in the gif. The smooth version would, according to that understanding, simply calculate both the unclamped and max clamped noise returns (so you need to calculate all noise twice), and then calculated a weighted average between the two to achieve that effect.
    If that's what they do i find it pretty undesirable. The goal of clamping here would simply be to raise the lowest terrain. The smooth option simply looks less straight than the normal version. But all this does is very similar to applying a gradient over the y coordinate, to make sure more terrain is at the bottom and less at the top. That is something you probably already do.

    I would recommend focussing on the other images. You care more about amplitudes, frequencies and octaves. Lacunarity and persistance are just fancy words to describe how the amplitudes and frequencies are scaled over the different octaves.

    Separate your noises. Create one noise for a plains-like biome you are happy with. For the sake of example, let's say that's the terrain from your first screenshot. Comment that noise out, dont use it. Now create a very mountainous terrain you are happy with. The valleys dont really matter too much. You want high amplitudes and a frequency you are happy with visually.
    Now you have two separate noises that do what you want them to. Combine them! You can do this in different ways, as previously mentioned. You can average them. Or calculate a weighted average. Something like 70% mountains and 30% plains. It's just numbers at this point, after all. You can also adjust your terrain gradient function to achieve certain effects. Experiment around until you are happy. Also keep in mind.. there is no limit to how many noises you can mix that way, or how complex these individual noises / terrains already were. Each of your input noises may already have been the sum of 4 octaves. Mixing the two together means you calculated 8 noises and did some extra math per coordinate. This gets out of hand very quickly tho, so imagine you had some very detailed noises with a couple octaves and mixed 20 of them together to achieve your terrain. Eventually this will crumble performance. But you can definitely mix and match quite a bit before that happens, so feel free to experiment around!

    Also for the sake of understanding, ill link the previously mentioned video by Sebastian Lague, which explains noise octaves and generally noise layering very well. Just keep in mind that you are not limited to using one noise function to determine the shape of your terrain.



    I would recommend watching some of the other episodes, especially the ones covering noise, too. The man is very good at explaining complex topics. The later parts of the series should be very helpful aswell, as he goes over anything from how to generate chunks around the player, through multithreading, over LOD changes, to texturing. While his terrain is heightmap based and yours uses full 3d noise, the involved concepts are otherwise identical.
     
  14. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15

    thank you for your help, ironically when i was about to go to sleep, i found a very good video from a mojang developer that explains very well the concepts



    with that i was able to understand
     
    Yoreki and orionsyndrome like this.
  15. DroneNz

    DroneNz

    Joined:
    Oct 4, 2022
    Posts:
    15
    i did understand the equation, turns out i was using the noise in the wrong way, i thought that the noise itself generates the pure height, since simplex outputs a value between 0 and 255, i should use that as high and lows of my terrain, just like a cosine function, thank you for your help, now that i understand the concept behind it, the equation makes complete sense in my head, just had a misunderstanding of how the noise should be used

    not that using the absolute value will not work, but using as highs and lows gave much more space to manipulating the output
     
    Yoreki likes this.
  16. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    That's a great video, and it features similar graphs so you can learn all about it (at 11:40 you can see exactly the same setup, where I used 1 + cos(x) but they have a lot more elaborate "noise-like" function that you can use as well). I was really short on time and patience, I agree there is a lot to unpack if you're new to it. But not that hard once you get past the initial hurdles. Voxel volumes are awesome to play with and learn from, also a lot of this knowledge you can apply to many other genres as well. Keep it up!
     
    Yoreki and DroneNz like this.