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

I really like this! Would be cool to try to write procedural terrain generator with Roblox terrain using this.
Could end up looking pretty good.

I remember something like that from KonekoKitten’s channel when he showed someone ported the entire code of Minecraft to Roblox, perlin noise included. Sadly after the video the game was put under review because of copyright infringement.

Here is what i’m doing differently:

At around line 7 where I make the noise variable, and call module.new I also, subtract this from the number that the module returns:

(y/(64*2))

64 is basically the number that the for loop uses.

the Y Axis is the height generated from the perlin noise.

1 Like

For instance

local height = math.noise(x,y,z + (seed*1000)) -- probably doesn't need to be 1000
1 Like

Soo… You stacked two layers of 3D perlin noise to create a mixed effect? Could you run that method a few more times on different seeds?

also, I think it’s time we move this to private messages…

i know this is a dumb question but how can i calculate the grass position and the grass should be like the positon like in minecraft in order to make grass but only like 70 grasses each grass biome

Check out my replies to this thread.

Here's a preview of the kind of results you can get:

2 Likes

Could you add parameters for frequency and lacunarity?


EDIT: Some other feedback:

The interface doesn’t make a lot of sense. The ModuleScript returns a table with a method called “new”, which suggests that there’s some OOP stuff going on and that PerlinNoiseAPI.new is a constructor that would return some kind of object. But actually calling the function just samples the noise function at the given coordinates and other parameters. It would make more sense to not call it an “API” and just return a function from the ModuleScript.

E.g.:

Instead of this:

local PerlinNoiseAPI = {}
function PerlinNoiseAPI.new(coords,amplitude,octaves,persistence)
end
return PerlinNoiseAPI

Just do

local PerlinNoise = function(coords,amplitude,octaves,persistence)
end
	
return PerlinNoiseAPI

The amplitude parameter should be a multiplier on the output of the Perlin noise function, but the way you’re using it makes it behave more like a period or (the inverse of) frequency parameter should.

E.g.:
local perlinvalue = math.noise(X/amplitude,Y/amplitude,Z/amplitude)

should actually be

local perlinvalue = math.noise(X/period,Y/period, Z/period) * amplitude

and again in the loop where you sample each of the octaves.


When checking if the arguments are valid, you can do

assert(condition, error_message)
--rest of the code

instead of

if not condition then
    error(error_message)
else
    --rest of the code
end

Having fewer if statements, and especially fewer deeply nested if statements, just makes your code more readable and easy to understand. It also lets you have the main part of your code be at the lowest level of indentation possible, which can sometimes be helpful if it allows you to scroll sideways to see everything.


Hope this is helpful :slight_smile: :+1:

7 Likes

Thanks for the feedback! I’m actually working on a revamp of this module to fix the 4D and the amplitude/frequency misconception of mine, and I’ll definitely change what you said. I had no idea something as assert() existed, so again, thanks!

3 Likes

Any progress on this? I’ve been waiting for this for a while now.

1 Like

any update on this? doing some terrain things and am needing this. Also how can i get the seperate X, Y, Z values?

EDIT: Sorry for the bump.

2 Likes

Sorry for the bump, but I’m looking into something like this for my game. Is it still being worked on?

Hi man, I just want to say thanks a ton for this, I’ve been tinkering with your module for about 4 weeks now, and devouring resources about procedural generation. Still I’m by no means an expert, but if it wasn’t for your module, it would have been extremely hard for me to get started.

Using your module I just spawned a tile map, and passed a radia filter on top of it, the results have been short of amazing, I just wish making ridges and valleys was easier.

3 Likes

as it is right now is completely usable, you can go a long way w/o ever having to touch the internals of the module, but the lack of lacunarity and frequency can bother advance users, and you will have a hard time attempting to add FBM to this, which I attempted for the last 3 days and failed miserably. other than that it’s an amazing module as it is.

Hey, I’m not advanced at all in building, terrain heightmaps etc, do you have any sort of tutorials on “making parts” with this module?

Hi! Sadly there is no tutorial that uses this module, but thanksfully it’s not that hard to use, you see this is just an enhanced noise function, basically math.noise in roids. now into my implementation, I had to sweat for 3 weeks looking at papers and tutorials from other engines to understand basically how this worked because although there are tutorials in roblox about procedural generation, w/o offense to those content creators, they are not useable in an scalable project. now if you want to see my implementation, here is the project file so you can play with it

BOP.rbxl (81.3 KB)

it has an easy to use panel in replicated storage/Configuration, and most of the meat of the module is in the server storage, I just leverage dieg module to make my procedural map implementation.

If you have any questions you can find me on discord as CluelessDev(Quique)#5459

EDIT: btw, I believe for what I’ve been told from other devs that the code in the project is clean and well organized, so I don’t think you will have a very hard time understanding what is happening there.

3 Likes

This looks amazing. The way you used the perlin noise is jusy amazing!

1 Like

Oh, and it improved a lot after that :smiley:

The 4d perlin makes it like true Minecraft generation

Thanks for contributing us a useful module!

This is good. Good, good, good.