Experimenting with this mod i had an idea to use an arctan density gradient instead of a linear one.
Basic 3D noise mapgen
Basic mapgen with 3D noise is done by calculating a sort-of density value for each node, then making that node solid if that value is above zero.
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local grad = (TCEN - y) / GRAD
local density = nvals_terrain[ni] + grad
'density' is a combination of some 3D perlin noise and a linear density gradient 'grad' which decreases steadily (linearly) with altitude.
'grad' is what creates a land surface, if it wasnt there, the noise on it's own would create an asteroid field / floatlands type realm, if the noise wasnt there there would just be a completely flat world at y = TCEN, the average terrain level.
So the blend of the 2 creates rough terrain, at certain locations the 3D noise overpowers 'grad' to create overhangs and a few bits of floating terrain, likewise underground a few caves are formed near the surface, this is something that basic 2D noise mapgen cannot do.
Minetest mapgen V5 was in it's simplest form 3D noise plus gradient as described above.
Arctan density gradient
In my moonlet mod i had an idea to put positive and negative limits on 'grad', so that floatlands would continue to be generated throughout the atmosphere, and caves throughout the underground. These hard limits worked but the transitions sharp, i recently realised an arctan function is a smoothed version ideal for mapgen, near zero it is similar to the basic linear gradient, but then smoothly approaches the limits at roughly +/-1.5.

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local grad = math.atan((TCEN - y) / GRAD) * 0.8
local density = nvals_terrain[nixyz] + grad
The * 0.8 can be adjusted to tune the number / size of the floatlands and caves.