Hello! I am making a terrain generation system, and something I was wondering about, was how do I make it more likely for certain spots to be lower than others? Like for example, I want the edges of my terrain to be lower than the rest, to provide a smooth transition into the deep ocean. This is a photo of what I got so far.
If you have converted your perlin noise values to the interval [0, 1], you can multiply the perlin value with a value given by another function. I’d recommend using a function that gives values in the interval [0, 1].
Here’s a module I’ve written around three years ago. Perhaps having “falloff” in the name would have been better than “grayscale”.
local CircularGrayscale = {}
local function sineEase(val)
return math.sin(val * math.pi / 2)
end
local function cosEase(val)
return 1 - math.cos(val * math.pi / 2)
end
-- input values between -1 and 1, output value between 0 and 1
function CircularGrayscale.GetVal(xScale, yScale)
xScale, yScale = math.abs(xScale), math.abs(yScale)
local squaredDistToEdgeInXZDir = 1 + math.min(xScale, yScale)^2
local linear = 1 - math.sqrt( (xScale^2 + yScale^2) / squaredDistToEdgeInXZDir )
local val = linear ^ squaredDistToEdgeInXZDir
--val = sineEase(val)
--val = cosEase(val)
return val
end
return CircularGrayscale
Here’s the old post.
To get xScale and yScale (perhaps zScale would have been a better name than yScale), you can divide the center x-coordinate and center z-coordinate of the terrain cell with half of the map width if your map is centered at the world center. Otherwise, subtract the map center coordinates from the cell coordinates before the division.
If you want to search for different multiplier functions, falloff function will probably be a good search word.
Wow! This is great, and it works great too. Though, I have one question. Do you know how it would be possible for me to change the output to numbers between 1 and -1? Otherwise, this is perfect!