Perlin Noise library Module! (4D and octaves!)

Hello! I’m Dieg, and I’m a scripter that likes a lot to mess with terrain generation.

I’ve recently started working on a game that requires Perlin Noise to generate its terrain, and I decided to quit my usual unorganized fashion of scripting and make a Module. Surprisingly, it’s very easy to use and get used to, so I decided to release it publicly!

Now, you might ask, what’s so special about this module? It supports 4 axes, meaning that you can either get 4-dimensional Perlin Noise or set a seed for 3D noise! Amazing!

How to use

The module only has one function:

PerlinNoise.new({X, Y, Z, W}, amplitude, octaves, persistence)

{X, Y, Z, W}

Table with the coordinates in order. You can leave any of these axes blank and it’ll consider them 0 by default. WARNING: The W axis is kind of wonky, so if you’re not interested in the 4th dimension I’d recommend leaving it to ensure you don’t get weird results.

amplitude

Number that specifies the amplitude of the noise. Default is 10.

octaves

Number of Perlin noises overlayed on top of eachother to get a more realistic result. Default is 1, which is regular noise.

persistence

Number that specifies how much octaves influence the original result. It’s set to .5 by default, and I recommend leaving it to that unless you know what you’re doing, as not even I know for sure how it modifies the noise 100%. From what I’ve tested, the closer the number is to 0 the more octaves influence the noise, but for some reason, really small numbers give weird results.

EXAMPLE USE: print(PerlinNoise.new({5,4,6},15,3,0.5)

Screenshots!

4 dimensional noise!

Octaves!

Waves/Clouds!

Embarrassing picture 😔

Why you shouldn’t use the W axis if it’s not needed!

Tried my best to fix this, as you can see once the W axis is different than 0 it generates weird lines, and I believe the result is symmetrical, but it looks cool!

Get the model here!

EDIT: This is my first public module/contribution to the community, so any sort of feedback is appreciated! :relaxed:

141 Likes

Very nicely done, and thanks for the open source :+1:

3 Likes

Awesome work!! :clap: thanks for bringing it to public, I’ll try to use this as soon as I can!! :+1:

2 Likes

I don’t get whats wrong with the picture

6 Likes

For some reason, it generates horizontal and vertical lines which you can see at the distance, and the whole shape is completely symmetrical vertically. I don’t think it happens when you generate 3D noise though.

Wait a second, I’ve always wanted symmetrical terrain for my game. This is because my game is going to be a real time skill game and I need both sides of the terrain to be the same! Coincidence? I think not.

Mind explaining how you got that? I don’t have studio with me right now.

2 Likes

Generate a heightmap like you would regularly, but make the W coordinate a number other than 0!

1 Like

Is 4D good for caves or am i thinking of 3D?

3D Perlin worms is your best bet here.

Very nice. When you are so hip that your work goes into 4D XD

1 Like

Can you give me a quick run down on how to use it? I actually have never really used module scripts and I don’t know how to make the script generate anything.

Nice module, I think I’m gonna use it, but I got a question, how did you made a 4 dimensional noise?:

I might want to implement this as a Minigame, thanks for reading.

Type this on your code first.

module = -- Enter the location of the module here.

PerlinNoise = require(module)

And then use this function as you normally would with math.noise() to get a value from -0.5 to 0.5.

Simply enter a W coordinate on the PerlinNoise.new() function and increase it over time!

1 Like

I am asking me the same question…

I’m really confused on what this is. Does the terrain move according to the music?

No, it isn’t related to music or audio at all.

“Perlin Noise” is the name of an algorithm which is what I’m using to generate the terrain. Other games like Minecraft use this algorithm too.

6 Likes

Perlin noise can be extended into as many dimensions as needed, due to the nature of the algorithm. 4D noise is mostly used to generate cohesive procedural structures, where the fourth dimension is usually time.

2 Likes

Very neat! Always thought about working on something like this for a project.

mineblox here we come

2 Likes

May seem obvious but if you want 3 axes with a seed you can just offset any of the axes by the seed, no need for an additional axis for this purpose

1 Like