Hello, I’m making my terrain plugin. But now I want add Node editor, which will have “Caves” node. But for some of them, I need use 4 variables - X, Y, Z, And SEED. But default roblox Perlin noise function have only first three variables. Can someone tell me, is there any way to make more than 3-D Perlin noise?
Luau’s math.noise
function is only 3D, so there’s no way to add an actual 4th dimension to it. In order to “seed” it, you may just need to use your seed as some sort of offset of the XYZ coordinates. It’s not ideal, and it would be nice if Roblox let us actually seed the noise generator, but it’s all we can do at the moment. It’s up to you how to offset it. In the example below, I just use the seed to add/subtract each argument to noise
.
local seed = 4363622365
-- e.g. add/subtract the seed from each argument
math.noise(x + seed, y - seed, z - seed)
The obvious downside to this is that seeds that are close in range to each other will look similar. A way to “fix” this is to randomize the seed. You could do this by seeding an actual RNG and using the first output of it as the noise offset.
local seed = Random.new(24473023):NextNumber(-100000, 100000)
local noise = math.noise(x + seed, y - seed, z - seed)
A stepping stone would be to get 3D Perlin noise, which is possible by using 3 different noise functions with different parameters and then summing up their output values.
local function perlin3D(x, y, z, seed)
local _x = math.noise(y, z, seed)
local _y = math.noise(x, z, seed)
local _z = math.noise(x, y, seed)
return (_x+_y+_z)*.333 --maximum value is 3 so we divide it by 3 to get a [-1, 1] interval
end
I guess you can take this idea of summing different noise functions up a notch to get 4D noise