Sign in to follow this  
N1ghtDr34m3r

Perlin Noise gives too small values?

Recommended Posts

N1ghtDr34m3r    378

Hello.

 

Today I've implemented a perlin noise algorithm with extra methods like pertubation and eroding to create a terrain. smile.png

I found the code for it here: Click me smile.png

 

After the "addPerlinNoise()" method, you can see 3 reference pictures on that page (in the middle), build with the frequencies 1.0f, 4.0f and 1.0f + 8.0f (without perturb or sth like that, just plain noise).

 

If I use a frequency of 4.0f, this is my output (plain noise): https://imgur.com/7OElD3n

 

And when I use 64.0f as my frequency, I get this: https://imgur.com/dqA04N6

 

Can you help me to achieve something like the reference pictures with the reference frequencies (1.0f, 4.0f, 1.0f + 8.0f)?

I only understand a little behind the maths of it, so I can't really do something to fix it. sad.png

 

The code on the linked site is in C#, mine is in C++.

 

The only things, which are different between my code and the code on the site is the following part:

void PerlinGenerator::initGradients()
{
	//Type of random number distribution
	std::uniform_real_distribution<float> dist(0.0f, 1.0f);  //(min, max)

	//Mersenne Twister: Good quality random number generator
	std::mt19937 rng;
	//Initialize with non-deterministic seeds
	rng.seed(std::random_device{}());

	for (int i = 0; i < gradientTableSize; i++)
	{
		float z = 1.0f - 2.0f * dist(rng);
		float r = (float)sqrt(1.0f - z * z);
		float theta = 2 * (float)M_PI * dist(rng);
		gradients[i * 3] = r * cos(theta);
		gradients[i * 3 + 1] = r * sin(theta);
		gradients[i * 3 + 2] = z;
	}
}

Can it be the random double, which is used for the computing?

 

For the rendering I determine the vertex coordinates for a VBO like this and render it with glDrawElements(...) :

void Terrain::createVBO()
{
	// Create vertex data
	float *vertices = new float[3 * heightMap->size * heightMap->size];
	float blockSize = 16.0f;
	int vertex = 0;

	for (int y = 0; y < heightMap->size; y++) {
		for (int x = 0; x < heightMap->size; x++) {
			vertices[vertex++] = x * blockSize;
			vertices[vertex++] = y * blockSize;
			vertices[vertex++] = heightMap->heights[y][x] * blockSize;
		}
	}

	// Create index data
	[...]

	// Create VAO
	[...]

	// Create VBO
	[...]

	// Create EBO
	[...]

	// Handle vertex attributes in shader prog
	[...]
}

Hopefully you can help me, thanks,

NightDreamer

Edited by N1ghtDr34m3r

Share this post


Link to post
Share on other sites
N1ghtDr34m3r    378

Thank you very much for replying. wink.png 

 

This is 3D perlin noise. However heightmaps should use 2D noise. Using 3D noise with heightmaps is useless, at the end you will be discarding one coordinate:  Heights[i, j] += Perlin.Noise(f * i / (float)Size, f * j / (float)Size, 0); Watch that zero, the third coordinate is useless. Using 3D perlin noise can work, but 2D noise is easier and cheaper(in terms of performance).

 

Alright, I think I will implement 2D noise. smile.png

 

The smooth function use the old 3p² - 2p³. However this is not C2 (it is C1), it should be 6p^5-15p^4+10p^3 (http://mrl.nyu.edu/~perlin/paper445.pdf)

 

I don't know, what you mean by "C2 (it is C1)". Would you explain that to me? rolleyes.gif

 

I prefer this Perlin noise reference: http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html I think that this link is very comprehensible.

 

Thank you very much. I'll have a look at it and try it out. biggrin.png

Edited by N1ghtDr34m3r

Share this post


Link to post
Share on other sites

I don't know, what you mean by "C2 (it is C1)". Would you explain that to me? rolleyes.gif
C0 = points are connected, no holes (basically a polyline)

C1 = tangents (the "first derivative") interpolate smoothly (e.g. a typica cubic spline)

C2 = tangents interpolate smoothly and curvature (the "second derivtative") is smooth, too.

 

In particular, in this case it means that the second derivative is zero both for t = 0 and t = 1. The difference between C1 and C2 appears to be not so important, after all, the curve is "smooth" either way. However, it becomes grossly visible once you do something like e.g. bump mapping. C1 will give you nasty artifacts.

Share this post


Link to post
Share on other sites
N1ghtDr34m3r    378

Ah, okay, thank you very much! smile.png 
Due to the word "derivative" I now know what you meant.
Just didn't know, that you can name it as C0/C1/... wink.png 
In university, we only use "derivative"... rolleyes.gif

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this