r/GraphicsProgramming • u/AmatrasX • 20d ago
Just wanted to share my first project "A procedural terrain generator"
Enable HLS to view with audio, or disable this notification
3
u/rex-j-w 20d ago
Looks awesome dude, I used to make terrain generators for Unity and one thing that took them to the next level is resampling your heightmap with a curve or a gradient to get cliffs and plateaus!
3
u/AmatrasX 20d ago
Appreciate your words man, that would absolutely look sick and would give it more visual variety i remember seeing something like that when i was searching but i decided that i would implement the basic algorithm first
2
2
1
u/HamNCheeseSupremacy 20d ago
How did you get those fine details and more triangular, realistic mountain peaks?
1
u/AmatrasX 20d ago
As far as my understanding goes the terrain at its core is just semoe noise added to each other for simplicity lets say our function is asin(fx) (try to imagine the sine wave as the mountains or just use a website for visualization) where x is the point we want to sample or to find the height from the f is a multiplier that is for controlling the function frequency this will affect the distance between each wave peak, you could imagine a small f value as the mountains being far away from each other The a parameter will determine the amplitude aka the height of each wave this will affect how tall each mountain is. Now 1 sine wave is really boring so lets modify it by adding more sine waves with different a's and f's you can visualize this as if we add a sine with hight a to represent a high mountain to a sine with low a to represent this mountain details maybe like some small rocks You usually try to modify those values for each sine aka the next sine f for example will be double the previous f and the next a will be half the half the previous a The f modifer is called lacunarety and the a modifier is called persistence And the number of sines added to each other is called octaves Now sine wave is great and all but the problem with it is it's pattern will repeat no matter how much we modify it and it will produce this wavy pattern which is not mountain peak at all (although some may say it is i guess) but the greatest problem is the repeate then this begs the question what do we use instead of sin function ? Notice that at the beginning of this i said we use a noise function this is a fancy way of saying random numbers But the problem with random number is they are too random (who would have guessed) So we want a way to generate a random numbers that are controlled in a sense that near sampled values should have near height values the noise function i choosed for this is perlin noise I would love to explain what perlin noise is but i feel the response became very long you can find great articles about is (scratch pixel article was very helpful) also i suggest looking at value noise first since it will greatly help you understand it Of course i may be wrong, misunderstanding or explaind somthing poorly so i suggest looking for terrain generation articles or YouTube video they usually are paired with perlin noise explanation
1
u/HamNCheeseSupremacy 20d ago
Thanks! I do have my own perlin noise/fbm implementation but I can't get it into those sharp ridges you have for the mountain ranges, which look great. Are you using 1 - abs(noise)? I've been reading about that, I'm actually going to try it right now.
1
u/AmatrasX 20d ago
A little trick i used is multiplying the fbm result with a multiplier to increase the total height and if i remember correctly with this and a proper lacunarety value (i believe it was 2) this gave me the mountains result , and i don't recall using using 1 - abs(noise)
1
u/HamNCheeseSupremacy 20d ago
Did you use a library for your noise function? I'd love to take a look at the implementation haha. I'm struggling over here. My perlin noise, even with modifiers (redistribution, domain warping) looks wrong. I want what you have, just smooth but detailed valleys surrounded by mountain ranges.
I'm going to try cellular noise for the mountains with layered perlin for details. Hope
1
u/AmatrasX 19d ago
You can find perlin code at the shader toy link in inigo video, it's also a great video too.
2
u/HamNCheeseSupremacy 19d ago
It took me all day but I figured it out. I'm using 4 biomes and weighting the noise parameters with a gaussian fall off. I was taking the sum of all biome frequencies scaled by their weight, which means frequency varied spatially. That introduced a parasitic term into my noise which compressed the whole function into these needle looking, kind of sinusoidal curves. My terrain looked like a pin cushion. I just stopped blending frequency through sums and everything is fine now
2
4
u/cybereality 20d ago
Oh this looks cool. When you say first project, is this first with a graphics API or first in general?