Using Procedural Noise Inside Of Roblox

Hi DevForum!

This will be a very basic tutorial on how to use procedural noise inside of Roblox Studio, and will skim the surface of what you can do with it.

Noise is an algorithm that creates a “random” image, and is used for an incredibly large amount of computer generated imagery, along with much more.
The first form of noise was called Perlin Noise, and was created by Ken Perlin in 1983.
There are many other variations of noise, such as Simplex, Worley, and many, many, more.

Perlin Noise
perlin

Simplex Noise
simplex

Worley Noise
worley

We can use this inside of Roblox with the math.noise() function. The particular version that Roblox uses is Perlin Noise.
To test this, we can run some code like this:

print(math.noise(12.34, 56.78)) -- Outputs 0.41 (and some more numbers)

The first parameter of this function is the X coordinate of the noise, and the second parameter is the Y coordinate. You can also use a Z coordinate as a third parameter, but 3D noise isn’t too different from 2D.
Think of this function as picking a colour from an infinite image, and the coordinates are choosing which pixel to pick.

How about we run some code that visualizes this?

for x = 1, 100 do
	for y = 1, 100 do
		local xNoise = x / 10 -- Dividing by 10 increases the size of the noise. To decrease it, divide by less; and to increase it, divide by more. You will likely have to play around with this.
		local yNoise = y / 10
		
		local part = Instance.new("Part")
		part.Anchored = true
		part.Size = Vector3.new(1, 1, 1) -- Stops parts from colliding with each other.
		part.Position = Vector3.new(x, math.noise(xNoise, yNoise) * 3 + 5, y) -- Multiplying by 3 increases the strength of the noise; to increase or decrease the strength, change that number. Adding 5 creates an offset, so that everything is visible.
		-- If you want to half the scale, use the commented code below instead:
		-- part.Size = Vector3.new(0.5, 0.5, 0.5)
		-- part.Position = Vector3.new(x / 2, math.noise(xNoise, yNoise) * 3 + 5, y / 2)
		part.Color = Color3.fromRGB(50, 50, 50)
		part.Material = Enum.Material.SmoothPlastic
		part.Parent = workspace
	end
end

This will make lighter numbers of the noise protrude more than the darker numbers.
We can also visualize noise with colour with this:

for x = 1, 100 do
	for y = 1, 100 do
		local xNoise = x / 10
		local yNoise = y / 10

		local part = Instance.new("Part")
		part.Anchored = true
		part.Size = Vector3.new(1, 1, 1)
		part.Position = Vector3.new(x, 5, y)
		part.Color = Color3.fromRGB(math.noise(xNoise, yNoise) * 250 - 250, math.noise(xNoise, yNoise) * 250 - 250, math.noise(xNoise, yNoise) * 250 - 250) -- Multiplying by 250 increases the strength of the noise, so that it is easier to see. Subtracting 250 stops a large portion from being just white.
		part.Material = Enum.Material.SmoothPlastic
		part.Parent = workspace
	end
end

There are many uses of noise inside of Roblox, but a common one is terrain generation. One good example of a game that uses this is Minecraft; although it isn’t in Roblox. (I also think that it uses a different type of noise)
The biggest problem with using this for your game is how resource demanding placing so many parts is; so if you’re making a large open world game, I would recommend Roblox terrain or using a script to load and unload portions.

6 Likes

Is it possible to use worley noise in roblox too?

No, you’d have to write your own implementation in Lua if you want to use it. The problem with that is that you’d also need to know how to write an implementation for Worley Noise to even try to write one in Luau and that the performance will probably be extremely bad, so you should try sticking to Perlin Noise.

It’s not a good idea to assume the performance of something before trying it out. Computers are fast. Definitely not as fast if you did the implementation in a compiled language like C, but it’s not impossible and not always atrociously unperformant.

1 Like

Believe me when I say, I have tried to make something like that but for something else. The difference in performance can be extreme to the point where its unusable on runtime.

It isn’t even an assumption I made. If you write a Perlin noise implementation in Luau, the performance difference is gonna be atleast 10x slower than math.noise

That still would not be reason to discourage someone from implementing based on fear of poor performance. There are techniques you can do to such as parallel processing and spreading work across multiple frames.

The person you were responding to was talking about Worley noise which is used for different applications than perlin noise.

1 Like

So what do you want me to do with this information? I was just saying that it probably isn’t a good idea but it depends on their use-case. Worley noise seems to mostly be used for procedural textures, don’t think that’s what they’re going to use it for and since it’s on Roblox it should be fine to assume that they’re going to use it for something like terrain?