Perlin Noise Help - Not Random Enough?

Hi all, I’m working on implementing Perlin Noise from the Infinite_Map example and I’m not getting noise that I think is random enough… for example I’m seeing repeating patterns which I thought wouldn’t happen. I haven’t changed any code really except for setting some logic as to what range a tile should be placed. Attached is my code for the perlin noise script and my script that makes my map. As you can see from my attached screenshot there’s lots of ‘mole hills’ of the same size and kind of in a straight line. Any suggestions on how to make this not look like this would be amazing.

My apologies I wasn’t sure how to post formatted code here.

perlin.lua (3.0 KB)

terrainGeneration.script (2.5 KB)

1 Like

Your function update_tilemap is called once: update_tilemap(0,0)

and the code looks like this:

local function update_tilemap(tx, ty)
	for x=1,math.ceil(WIDTH / TILESIZE) + 1 do
		for y=1,math.ceil(HEIGHT / TILESIZE) + 1 do
			local n = perlin.noise((tx + x) / 10, (ty + y) / 10, 0.3)

The input to the noise function are a looping numbers (integers) in the range [0,9]
So, that’s what the base for your pattern. 10 seems to match the size of your hills.

You should look into fBm’s as well, since you can combine several noise functions, to create something more complex, and break up patterns too.

I’m not an export on this, but here is some terrain test I did, which uses fBm.
demo
source

2 Likes

I’ll look into fBm, thank you. This is all a little daunting for a beginner but I’ll try my best. If I change the number 10 then the pattern becomes more spread out the larger the number so still an issue. Guess I really do need to combine noise functions. It looks like the code you posted is in C++. At my skill level I don’t think I can redo all of that in Lua… yet. I’m getting tired of messing around with the map generator so might start working on other parts of the game and come back to this, lol. Thank you for the help it is greatly appreciated.

I’d say it’s a design choice you’ve made :slight_smile:

You chose to wrap the values in steps of 10.
And as you’ve mentioned, this produces artefacts.
And increasing the number produces less artefacts…

So, the question is: Why wrap the values at all?
What was the effect you wanted to achieve?

As for C++, that wasn’t really the point, but rather the methodology of how to use a noise function in several steps to create an fBm. the fBm() function

And here’s one example on how to use it on an entire map

1 Like

The majority of the code is from the Infinite Map example and honestly I’m trying to learn and the number 10 was already in there so I went with it. :slight_smile:

I think you underestimate how much of a beginner I am. Not your fault! :slight_smile:

Thank you for the example code. I will take a look at it.

I have no idea what you mean when you say ‘why wrap the values at all?’

1 Like

First, I’l like to apologize for the confusion. I mixed it up a bit in my head when reading. I kind of interpreted it as “%” which makes the values wrap.

That said, if we look at the properties of the noise function, here’s what is looks like if we scale the coordinates (using perlin.lua), using a scale factor of 1, 4, 10 and 20 (10 being the same as you example):

1:

4:

10:

20:

The “repeating pattern” you see is in fact the original pixels.
When increasing the scale factor, you basically spread the original pixels and get a blur between them.
So they don’t completely disappear.

The trick is to do several noise calls for the same pixel, and combine these values with so that we break up this pattern. I.e. using different amplitude and frequency. This is what Fractal Brownian Motion (fBm) is doing.

Here’s a small tutorial on how to combine simple noise into a more complex function:

2 Likes

This is very helpful and I understand much better now. Thank you for sticking with me Mathias!

3 Likes

Is there any way to add different noise functions that are already built in to the Defold API? I feel like I’m having to reinvent the wheel here! :slight_smile: