Jump to content

  • Log In with Google      Sign In   
  • Create Account

Tileable fBM Noise ?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Endemoniada   Members   -  Reputation: 289


Posted 06 May 2013 - 08:40 PM

Hi guys, I'm trying to make 2D fBM tileable. I can make the underlying Perlin Noise tileable by adding an integer period to the implementation but the fBM built from it does not come out tileable. Any info would be appreciated.

Edited by Endemoniada, 08 May 2013 - 10:08 AM.


#2 LorenzoGatti   Crossbones+   -  Reputation: 2515


Posted 07 May 2013 - 01:55 AM

You should reduce x and y modulo px and py, once at the beginning; then you wouldn't need per-octave tricks.

Multiplying x and y by the scale factor is seriously wrong; the correlation s very likely to be visible. Instead, you could reduce px and py for finer scales and perturb the noise function (does it include a "seed"?) to make completely unrelated noise at each octave.

Another missing detail: the amplitude of each octave, definitely different if you want fBM noise.

Produci, consuma, crepa

#3 irreversible   Crossbones+   -  Reputation: 1205


Posted 07 May 2013 - 06:19 AM

The simplest way to make 2D noise tileable is to make it periodic using some periodic function(s). Eg:



fScaleX = x / fPeriodSize; //0 <= x <= fPeriodSize
fPeriodX = fScaleX * 2 * PI; //0 <= fPeriod <= 2PI
fRadius = 1.f; //modify this to scale noise
x = fRadius * sin(fPeriodX);

//apply same to y
y = fRadius * cos(fPeriodY);

Edited by irreversible, 07 May 2013 - 06:23 AM.

#4 Álvaro   Crossbones+   -  Reputation: 11905


Posted 07 May 2013 - 07:11 AM

You can also use some form of interpolation noise (value noise or gradient noise) where the values assigned in the grid are periodic.

#5 JTippetts   Moderators   -  Reputation: 8159


Posted 07 May 2013 - 08:04 AM

noise2() implies 2-dimensional noise, yet you're calling it as if it were noise4()? Or do px and py do something other than act as coordinates when passed to your noise2?

Trying to do tiling noise with a 2D noise function limits you somewhat. There are a few ways you can do it, but all have their problems or issues.

1) Ensure that each individual octave tiles with itself (which, I suspect, is what your noise2 function does). This can be done by modulo-ing the coordinates at each layer with their repeating period size. The limitation of this, of course, is that it leaves you unable to perform certain common artifact-reduction tricks such as rotating the domain of a noise layer around an arbitrary axis before calling the noise function. This trick is helpful for reducing or eliminating grid line artifacts in the final result. However, since this rotates the noise layer off the grid, the edges will no longer line up and tile the way they need to. Additionally, this imposes the rigid requirement that your lacunarity be integral, so that the entire grid is represented in the output, preventing you from using a non-integral lacunarity to again try to reduce grid-based artifacts. Integral lacunarity means that the grid boundaries of each successive layer line up exactly with the grid boundaries in preceding layers, thus amplifying the results of grid artifacts in certain types of noise, such as ridged noise.

2) Blend 4 regions of noise arranged in a 2x2 pattern, with continuous weighting of the 4 blended values based on distance from the horizontal and vertical edges. This has the problem of skewing the distribution of the function output toward neutral, especially at the center of the image. Consider this image (the one on the left uses this method of seamless tiling)


Because the final value of a pixel in the middle is averaged from 4 different pixels, the result is an averaged blend, with much of the contrast of the function destroyed. Additionally, since the blending is weighted by distance-to-edge, you introduce grid-based artifacts since the averaging becomes less pronounced as you approach the edge. The edge regions have higher contrast (closer to the un-blended base function) than the middle. Applied tiling on a plane, this pattern becomes very obvious.

If you can increase to higher dimensional noise, other methods open up to you:

3) Perform a spherical mapping from a 3D function. This, of course, has the large drawback of introducing a lot of distortion into the final mapping, as singularities are formed at the poles of the sphere, as demonstrated by this example:


If the noise were being mapped back onto the surface of a sphere the distortion would vanish, but since it is being mapped to a 2D rectangle it becomes very pronounced. Set to tile on a plane, this type of mapping would produce severe banding artifacts.

4) In a journal entry I wrote some time back (which was later re-written as an article for Game Developer Magazine) I discussed an alternative technique: using a 4D noise function to generate seamless 2D noise. The X axis of the final image is mapped to a 2D circle, and the Y axis is mapped to a second 2D circle. The first circle lies upon the X/Y plane in 4D space, and the second circle lies upon the Z/W plane. The result is a 4-tuple that is used to index the noise function at a given (Ximg, Yimg) coordinate. In the image of the high-contrast cellular noise posted above, the image on the right is of tiling cellular noise using this method. You can see that this method preserves the overall contrast of the function, unlike the blending method. While some distortion is introduced by the non-linearity of the axis->circle mappings, it is a much more tolerable and even distortion than what is generated by the spherical mapping.

This method works for all sorts of functions, as long as a 4D variant can be constructed. It has the advantage of preserving contrast and working with arbitrarily-rotated domains at any level of the layering. The disadvantages include performance (requiring 4D adds additional computational complexity, making it difficult to justify implementation in some cases, such as inside shader code) and the subtle distortion introduced by the mapping to circle, which makes it difficult if you are working with regular repeating patterns such as checkerboards. (The checkerboard will be warped beyond recognition.)

#6 Endemoniada   Members   -  Reputation: 289


Posted 07 May 2013 - 02:14 PM

Hi guys,


I am indeed using a 2D noise function, it's Perlin's Improved Noise, here it is:


It makes some pretty nice tileable textures but maybe they aren't as nice as they can be ? Some of your posts are hard to understand, maybe now that you see my code you can be more specific ? Thanks.



float pnoise2( float x, float y, int px, int py )
    int ix0, iy0, ix1, iy1;
    float fx0, fy0, fx1, fy1;
    float s, t, nx0, nx1, n0, n1;
    ix0 = FASTFLOOR( x ); // Integer part of x
    iy0 = FASTFLOOR( y ); // Integer part of y
    fx0 = x - ix0; // Fractional part of x
    fy0 = y - iy0; // Fractional part of y
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    ix1 = (( ix0 + 1 ) % px) & 0xff; // Wrap to 0..px-1 and wrap to 0..255
    iy1 = (( iy0 + 1 ) % py) & 0xff; // Wrap to 0..py-1 and wrap to 0..255
    ix0 = ( ix0 % px ) & 0xff;
    iy0 = ( iy0 % py ) & 0xff;
    t = FADE( fy0 );
    s = FADE( fx0 );
    nx0 = grad2(perm[ix0 + perm[iy0]], fx0, fy0);
    nx1 = grad2(perm[ix0 + perm[iy1]], fx0, fy1);
    n0 = LERP( t, nx0, nx1 );
    nx0 = grad2(perm[ix1 + perm[iy0]], fx1, fy0);
    nx1 = grad2(perm[ix1 + perm[iy1]], fx1, fy1);
    n1 = LERP(t, nx0, nx1);
    return 0.507f * ( LERP( s, n0, n1 ) );

Edited by Endemoniada, 08 May 2013 - 10:05 AM.

#7 JTippetts   Moderators   -  Reputation: 8159


Posted 08 May 2013 - 08:11 AM

It probably does work okay, and if it works for your needs then awesome; but a potential issue with performing tiling by constraining each octave to a repeating lattice pattern can be demonstrated by this image, of a ridged fractal being built up in layers:


The upper-left portion is 1 octave, upper right is 2, lower left is 3, and bottom right is 4 octaves. If you look at that image closely you will see some horizontal and vertical lines that grow more pronounced as more octaves are added. This is a consequence of generating noise on a lattice grid. Even though Perlin's gradient and simplex noise variants use wavelet functions to throw the peaks and valleys off of the grid points, the underlying grid structure is still there and it can appear as artifacts in the final result. Some fractal variants demonstrate the artifacts more strongly than others, but they are always going to be there. You can modify lacunarity to use non-integral values, and this will help to mitigate the problem somewhat since this ensures that successive grid lines don't exactly line up with one another. (Of course, this prohibits using your method of seamless tiling, due to the fractional sizes of successive layer grids.)

In order to make a noise fractal tile in your method, you have to use the underlying grid and make the grid pattern repeat based on some period, so you're going to have to live with the artifacts.

However, one common trick to reduce or eliminate the grid artifacts is to apply a randomized rotation around an arbitrary axis for each successive noise layer. That is, for each layer you generate a random axis/angle and use it to rotate the input coordinate before sampling the noise function for that layer. Here is a build-up of a ridged 4-layer fractal with random domain rotations:


If you look closely at it, you don't see the horizontal and vertical lines that occur in the previous image. That is because each layer is rotated on a different axis, and the rotation of a layer removes the pattern of noise from the grid axis (or, at least, causes you to "view" the grid from something other than straight-on). Thus, successively layer grid artifacts do not line up with previous grids, and the result is that no grid artifacts are manifest in the final result.

The problem with this approach is that you can't implement tiling using the periodic grid-based method you use, since that relies upon the edges of the periodically repeating grid pattern you use for each layer lining up with the edges of the image in the output, but the rotation throws that off completely.

Additionally, constraining your tiling algorithm to act upon the underlying grid of each layer of noise assumes that the noise that you are using is grid-based in the first place. If you want to use something that isn't grid-based, such as sparse convolution noise (where you take a scattering of non-grid-based randomized points and convolute them to produce the final signal) then you are stuck, since there is no underlying grid to manipulate to create periodicity. In that case, you would need to use some other type of seamless tiling algorithm (such as the blending or the 4D mapping I mentioned) in order to make it tile seamlessly.

It might not be an issue for you, though, depending on your application. If your algorithm works for you, then you probably don't need to mess with it. Just be aware that there can be artifacts that you might have to deal with.

Edit: Holy crikey, this post editor is funky sometimes

Edited by JTippetts, 08 May 2013 - 08:15 AM.

#8 Endemoniada   Members   -  Reputation: 289


Posted 10 May 2013 - 09:18 PM

JTippetts, thanks a lot for explaining all that to me, I am really understanding it now; I can see you've done a lot of work with noise functions. Right now I'm pretty happy with my tileable 2D noise because I'm using it only for textures. One day I'd like to spend more time with this stuff, I find it fascinating.


Thanks again.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.