<p>It's unfortunate that people commonly recommend this.  Blending between two (or four, etc.) translated copies of a noise function in that way is a pretty bad idea. Not only is it expensive, it doesn't even produce correct-looking results!</p>

<p><img src="https://i.sstatic.net/DgnQE.png" alt="Perlin noise"> <img src="https://i.sstatic.net/949SB.png" alt="Blended Perlin noise"></p>

<p>On the left is some Perlin noise. On the right is two instances of Perlin noise, stacked and blended left-to-right.</p>

<p>The difference is kind of subtle, but you can see that the second image has lower contrast in a vertical column running down the middle.  That's where it's a 50% blend between two different instances of the noise function. Such a blend doesn't look like the original noise function: it just looks like a muddy mess.</p>

<p>OK, so it's not quite <em>that</em> bad just looking at the raw noise...but if you then do any nonlinear transformations on the image, the nonuniform contrast can cause issues. For instance, here are those images thresholded at 60%. (Think of generating islands in an ocean, for instance.)</p>

<p><img src="https://i.sstatic.net/elyF1.png" alt="Thresholded Perlin noise"> <img src="https://i.sstatic.net/Micts.png" alt="Thresholded blended Perlin noise"></p>

<p>Now you can plainly see how the image on the right has fewer, smaller white areas in the middle.</p>

<p>Like you mentioned, for grid-based noise like Perlin, a better way is to tile the pseudorandom gradients at the grid points. That's easy and cheap to do, and then you can apply the interpolation algorithm to the gradients as usual (much like bilinear interpolation of a tiling texture). This produces tiling noise without any weird artifacts, because it works <em>with</em> the underlying noise algorithm rather than over the top of it. You can use a similar strategy with Worley noise (cellular noise) by tiling the random feature points it uses as a basis.</p>

<p>With multiple octaves of noise it's not always so easy, though. If the relative scale between the octaves (aka "lacunarity") isn't an integer or simple rational number, then you may not be able to find a convenient tiling point where all the octaves' grids match up. You could tile each octave independently, but the overall noise would still not be tilable in that case.</p>

CC BY-SA 3.0
2015-08-15T09:49:46.923Z
Side by side images *really* make a difference for getting an intuitive feel for the explanation. I'm going to bear this in mind for my own answers.
trichoplax is on Codidact now
CC BY-SA 3.0
2015-08-15T05:55:52.820Z
2015-08-15T05:55:52.820Z
Nathan Reed
<p>I've seen in several places that making Perlin noise loop seamlessly requires calculating it twice in slightly different ways, and summing the two results.</p>

<p><a href="http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html#loop" rel="noreferrer">This Perlin noise math FAQ</a> gives a formula:</p>

<p>$$F_{loop}(x, y, z) = \frac{ (t - z) \cdot F(x, y, z) + z \cdot F(x, y, z - t) }{ t}$$</p>

<p>to make a noise function $F$ loop in the $z$ direction. It also mentions that extending this, to loop in 2 dimensions would take 4 evaluations of $F$ and to loop in 3 dimensions would take 8 evaluations of $F$.</p>

<p>I understand that this gives a seamless join between tiles that is not only continuous but continuously differentiable, but I intuitively expect that to be the case if the noise function is simply evaluated once with grid points reduced modulo the required tile size. If the noise function is only ever based on the immediately surrounding grid points (4 for 2D noise, 8 for 3D noise) then surely just using the leftmost grid points when the point to calculate gets past the right hand edge of the tile will give the same quality of noise as between any other grid points?</p>

<p>Since I've seen this multiple calculation approach in several places I assume it must have some advantage, but I'm struggling to see the disadvantage with simply wrapping the grid points back to the start when they get too big. What am I missing?</p>

<algorithm><noise>
Why is it twice as expensive to make a noise function that can be tiled?
trichoplax is on Codidact now
# Why is it twice as expensive to make a noise function that can be tiled?

(Asked by: username_0 on 2015-08-14)

I've seen in several places that making Perlin noise loop seamlessly requires calculating it twice in slightly different ways, and summing the two results.

[This Perlin noise math FAQ](http://webstaff.itn.liu.se/~stegu/TNM022-2005/perlinnoiselinks/perlin-noise-math-faq.html#loop) gives a formula:

$$F\_{loop}(x, y, z) = \frac{ (t - z) \cdot F(x, y, z) + z \cdot F(x, y, z - t) }{ t}$$

to make a noise function $F$ loop in the $z$ direction. It also mentions that extending this, to loop in 2 dimensions would take 4 evaluations of $F$ and to loop in 3 dimensions would take 8 evaluations of $F$.

I understand that this gives a seamless join between tiles that is not only continuous but continuously differentiable, but I intuitively expect that to be the case if the noise function is simply evaluated once with grid points reduced modulo the required tile size. If the noise function is only ever based on the immediately surrounding grid points (4 for 2D noise, 8 for 3D noise) then surely just using the leftmost grid points when the point to calculate gets past the right hand edge of the tile will give the same quality of noise as between any other grid points?

Since I've seen this multiple calculation approach in several places I assume it must have some advantage, but I'm struggling to see the disadvantage with simply wrapping the grid points back to the start when they get too big. What am I missing?

**Tags:** algorithm, noise


---

## 1 answers

### Answer by username_1 on 2015-08-15. Score: 20 | Accepted answer

It's unfortunate that people commonly recommend this. Blending between two (or four, etc.) translated copies of a noise function in that way is a pretty bad idea. Not only is it expensive, it doesn't even produce correct-looking results!

![Perlin noise](https://i.sstatic.net/DgnQE.png) ![Blended Perlin noise](https://i.sstatic.net/949SB.png)

On the left is some Perlin noise. On the right is two instances of Perlin noise, stacked and blended left-to-right.

The difference is kind of subtle, but you can see that the second image has lower contrast in a vertical column running down the middle. That's where it's a 50% blend between two different instances of the noise function. Such a blend doesn't look like the original noise function: it just looks like a muddy mess.

OK, so it's not quite *that* bad just looking at the raw noise...but if you then do any nonlinear transformations on the image, the nonuniform contrast can cause issues. For instance, here are those images thresholded at 60%. (Think of generating islands in an ocean, for instance.)

![Thresholded Perlin noise](https://i.sstatic.net/elyF1.png) ![Thresholded blended Perlin noise](https://i.sstatic.net/Micts.png)

Now you can plainly see how the image on the right has fewer, smaller white areas in the middle.

Like you mentioned, for grid-based noise like Perlin, a better way is to tile the pseudorandom gradients at the grid points. That's easy and cheap to do, and then you can apply the interpolation algorithm to the gradients as usual (much like bilinear interpolation of a tiling texture). This produces tiling noise without any weird artifacts, because it works *with* the underlying noise algorithm rather than over the top of it. You can use a similar strategy with Worley noise (cellular noise) by tiling the random feature points it uses as a basis.

With multiple octaves of noise it's not always so easy, though. If the relative scale between the octaves (aka "lacunarity") isn't an integer or simple rational number, then you may not be able to find a convenient tiling point where all the octaves' grids match up. You could tile each octave independently, but the overall noise would still not be tilable in that case.

> **Comments:**
> **username_0**: Side by side images *really* make a difference for getting an intuitive feel for the explanation. I'm going to bear this in mind for my own answers.  

---

