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

Periodicity along diagonal #15

Closed
grandseiken opened this issue Aug 18, 2015 · 6 comments
Closed

Periodicity along diagonal #15

grandseiken opened this issue Aug 18, 2015 · 6 comments

Comments

@grandseiken
Copy link

Hey, this might be a dupe of issue 10 but the links are broken in that one so I couldn't be sure. Apologies if so.

It seems like both the 2D and 3D simplex noise functions are periodic with respect to a particular diagonal direction. The problem is not quite so obvious in 2D, but it's definitely still there. I tried various fixes mentioned in other issues without luck. Did I do something wrong?

In the samples below I zoomed out a lot to show the problem but it's also quite noticeable in real situations. Increasing the period would be fine for my use case I guess, it just seems very small at the moment.

I tried changing the value of 289 used in the permutation to something much higher, which did fix the periodicity problem, but it also introduced discontinuities in the noise function along diagonal lines. I guess it needs to be a real permutation polynomial rather than some number I made up, but I'm not sure how those values were constructed in the first place.

Here are code samples and results for both cases. It's just the fragment shader and I'm rendering a quad over the whole screen.

#include "noise3D.glsl"

out vec4 output_colour;

void main()
{
  highp vec3 seed = vec3(0, gl_FragCoord.xy) / 2;
  highp float n = snoise(seed);
  float v = clamp((n + 1) / 2, 0, 1);
  output_colour = vec4(v, v, v, 1);
}

screenshot

#include "noise2D.glsl"

out vec4 output_colour;

void main()
{
  highp float n = snoise(gl_FragCoord.xy / 2);
  float v = clamp((n + 1) / 2, 0, 1);
  output_colour = vec4(v, v, v, 1);
}

screenshot2d

@stegu
Copy link
Contributor

stegu commented Aug 19, 2015 via email

@grandseiken
Copy link
Author

Hey, thank you for your detailed reply.

It seems like using any axis-aligned plane (snoise(coords.xy, 0), snoise(0, coords.xy), snoise(coords.x, 0, coords.y)) has just as bad a problem. I didn't notice any subjective improvement swapping between these (I had tried already based on a comment in a different issue).

Adding a small z slope actually helps a fair bit: the noise is no longer so obviously and drastically periodic, but general recurring patterns are still fairly obvious, and additionally the general patterns now seem to repeat in two directions instead of just one.

Thanks for the other notes and links. I'll probably end up doing something with integers or using a texture lookup.

Just one more question: what are you referring to by "our original article"? I thought you might mean this but it doesn't appear to contain anything on permutation polynomials. Cheers!

@stegu
Copy link
Contributor

stegu commented Aug 20, 2015

what are you referring to by "our original article"?

Sorry for the confusion, I meant the write-up by Ian McEwan and myself on
this particular implementation of noise, from Journal of Graphics Tools:
http://www.itn.liu.se/~stegu/jgt2012/
There is a link to it on the Ashima "webgl-noise" wiki page:
https://github.com/ashima/webgl-noise/wiki

@stegu
Copy link
Contributor

stegu commented Oct 14, 2020

The thread is a detailed description of problems that still exist in the implementation, so I'm keeping it open.

@stegu
Copy link
Contributor

stegu commented Jun 29, 2021

Ian McEwan and I are in the process of writing new noise functions, and in that process we found a better permutation polynomial that does not cause these ugly diagonal streaks. I have now retroactively changed the permutation polynomial across the board for all these old functions as well. It's only a matter of changing a "1.0" to "10.0". Sad that it took this long to find that simple remedy, but finding permutations to generate "apparent randomness" are a really tricky subject where there is little relevant previous work.

@stegu
Copy link
Contributor

stegu commented Nov 26, 2021

The problem seems to have gone "poof" with that slight change to the permutation polynomial, so I'm closing this thread.

@stegu stegu closed this as completed Nov 26, 2021
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