Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use periodic fbm/rmf/turbulence? #3

Open
piranha771 opened this issue Jan 2, 2017 · 6 comments
Open

How to use periodic fbm/rmf/turbulence? #3

piranha771 opened this issue Jan 2, 2017 · 6 comments

Comments

@piranha771
Copy link

piranha771 commented Jan 2, 2017

Hi, first thanks for the great work!

I need periodic 2D noise for a planet texture/heightmap.

My current solution is the following.
Take the UV and do this:

vec4 tile(in vec2 pos) {
	return vec4(
		offset + cos(pos.x * 2.0 * PI) * inResolution.x / (2.0 * PI),
		offset + cos(pos.y * 2.0 * PI) * inResolution.y / (2.0 * PI),
		offset + sin(pos.x * 2.0 * PI) * inResolution.x / (2.0 * PI),
		offset + sin(pos.y * 2.0 * PI) * inResolution.y / (2.0 * PI)
	);
}

The resulting 4D position is the used in 4D simplex noise as position. This leads to sweet tileable noise.
This is how I doing fractal brownian motion for example:

float fbm(in vec4 pos, in int octaves, in float frequency, in float lacunarity, in float persistence) {
	frequency /= inResolution.x;
	float currentWeight = 1.0;
	float totalWeights = 0.0;
	float result = 0.0;
	for (int i = 0; i < MAX_OCTAVES; i++) {
		if (i >= octaves) break;
		result += snoise(vec4(pos.x * frequency, pos.y * frequency, pos.z * frequency, pos.w * frequency)) * currentWeight;
		totalWeights += currentWeight;
		currentWeight *= persistence;
		frequency *= lacunarity;
	}

	return result / totalWeights;
}

But this is 4D noise computation complexity just for 2D noise. :(

I would like to use your periodic 2d simplex noise instead, but I have problems to use it in context of fractal brownian motion, ridgit multi fractals and turbulence.
This is my approach so far:

float fbm2(in vec2 pos, in int octaves, in float frequency, in float lacunarity, in float persistence) {
	float currentWeight = 1.0;
	float totalWeights = 0.0;
	float result = 0.0;
	for (int i = 0; i < MAX_OCTAVES; i++) {
		if (i >= octaves) break;
		result += psnoise((pos)*pow(2.0,float(i)),vec2(2.0,2.0)*pow(2.0, float(i))) * currentWeight;
		totalWeights += currentWeight;
		currentWeight *= persistence;
		frequency *= lacunarity;
	}

	return result / totalWeights;
}

This works, but completly skips the frequency and lacunarity parameters.
As soon as I take frequency or lacunarity in account (ex. multiply by position like in 4D fbm) its not tileable anymore :(

So my question is: is there a way to use periodic noise and be still able to set arbitrary frequency and lacunarity?
something like:

fbm2(pos, 6, 1.0, 2.13727, 0.507123)

This is how it looks with octaves as frequency and below my approach to use the parameters:

alt text

@stegu
Copy link
Owner

stegu commented Jan 2, 2017 via email

@piranha771
Copy link
Author

Thank you for your help, that works really well! :)

Btw. For my OpenCL noise library I provided a 255 permutation table. I would like to generate a permutation table rather than using mod289 here too. Is it possible?

I had in mind to generate on the CPU a 17x17 texture with red containing the values and green containing the overflow (289 is a bit too much for one channel). So in the shader I will do a texture lookup instead of mod289.

The reason behind this is a tradeoff between weaker performance but having the ability to provide a seed and being capable to generate 289 factorial planets.

@stegu
Copy link
Owner

stegu commented Jan 3, 2017 via email

@piranha771
Copy link
Author

Hi Stefan,

thank you again for this great explanation. I will implement the permTexture as you did in your older shaders. I'm using WebGL which, as you already mentioned, doesn't support int-textures and WebGL 2 will need another year to reach critical mass, so I will have to stick with the float approach for now.

@stegu
Copy link
Owner

stegu commented Oct 14, 2020

This thread is informative, so I'm keeping it open.

@stegu
Copy link
Owner

stegu commented Jan 8, 2022

I recently did a version of 2-D simplex noise (with flow noise capabilities, i.e. rotating gradients and an analytic derivative) that lives natively on a sphere, in a Fibonacci spiral grid. Let me know if you have any interest in that. It's not super optimized right now, and there are some limitations to how far it scales into fine detail, but it's definitely useful for texturing a sphere without seams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants