## Seamlessly tiled procedural texture generation.

I've come up with a clean method for creating seamlessly tiling procedural textures. I've already mentioned it on blenderartists.org because I'd love to see it in Blender, but I think it's worth posting it here too, because some people might be able to get some use out of the algorithm. Below is some copypasta from my post on the Blender forum. :)

As someone who's worked with textures, particularly with the intent of creating games, I keep finding myself wanting to be able to get tiling versions of Blender's textures (perlin noise, clouds, etc).

One thing I noticed early on is that it's pretty easy to make a texture that tiles in one dimension -- all you have to do is create a cylinder, assign a surface texture, and then bake that texture to an image. Since the texture is actually in 3D space, the texture image will wrap perfectly along the X dimension, but unfortunately it doesn't wrap along the Y dimension. So I got to wondering if there was some shape I could create that would have this property in both directions. The only obvious choice is a torus, but unfortunately if put a torus in 3D space and then unwrap a baked planar texture from it, you end up with weird stretching and compressing because the texture plane isn't distributed evenly over it, so that's not going to work.

Consider, for a moment, what happens mathematically when you put a cylinder into a 3D texture space and then bake the texture plane. Essentially what you're doing is taking the X coordinate of the 2D (x, y) texture space, and mapping that to an x and z coordinate of 3D texture space, and leaving the y coordinate the same. The mapping is extremely simple. x maps to x=sin(x) and z=cos(x), so the texture plane wraps around the 3d area in a circle, making it repeat along one axis. So for an (x, y) point on the plane, the corresponding point in space is (sin(x), y, cos(x)).

Now, this is kind of difficult to comprehend because our minds aren't meant to think in 4 dimensions... but, if we're wrapping our plane in four dimensions, it's possible for a 4D object to exist that wraps like a cylinder on *both* axes, without stretching the plane the way a torus would. Without breaking our brains trying to imagine what such a shape might look like, just think of the math. Your 2D (x, y) point in texture space would map to a point in 4D space as: (sin(x), cos(x), sin(y), cos(y)). So what you end up with is a smooth, continuous loop of both X and Y in 2D space.

The cool thing here is that you can apply this method to any texture that can be made 4 dimensional. My own test implementation uses Perlin Simplex noise:

http://oga2.opengameart.org/tilenoise/

I've borrowed the simplex noise code from a paper that I credit on the page above. My own code, which accomplished the above algorithm, is very brief, but it proves that it works. Note that the texture drawn on the HTML canvas repeats in both directions and doesn't look funny at all. You could easily modify the code to produce different tiling textures.

Furthermore, you can tile textures in more than two dimensions using the same general idea. For an N-dimensional tiling texture, the texture generation function needs to generate the texture in (2*N) dimensions. So you can use it to create a repeating 3D texture, a repeating 2D texture that morphs over time and returns to its original state without ping-pong-ing, or a 3D texture that does the same.

As a side note, some people might point out that perlin noise already tiles -- this is true, but you have to iterate over all of the noise to get it to tile, which means that you're very limited in terms of the character of the texture if you do it this way. My method gets around this by allowing you to combine arbitrary textures in arbitrary ways and have them all tile over some distance that you can specify yourself.

Anyway, I'd like to get a feel for how interested people would be in seeing this kind of capability in Blender. I feel like this kind of feature would go along way toward making Blender be able to compete with a lot of expensive texture editing software (since Blender's texture and material node editors are already very robust). I'd love to see this added in as an option for textures where it makes sense, allowing the user to tile the texture over an arbitrary distance in one, two, three, or four dimensions.

joined 6 years 11 months agoCan't you just use the cylinder method to tile in the X axis, then take the result of that and apply it to a wrap on a cylinder in the Y axis? Why all this 4D complication? :-)

http://forum.freegamedev.net/

joined 5 years 2 weeks agoWell, if you take the surface a cylinder along the X axis and unwrap it, you only have a 2 dimensional texture. Turning that sideways and wrapping it around a cylinder isn't going to make that seamless.

joined 6 years 8 months agoBart, the idea is very smart and I have not noticed anything wrong - then I took a look at your generator it seems to work too. I most like the idea of the "seamlessly animated 2d texture" though it's hard to imagine^^

Good one. If you write a paper, you'll be more useful than most of these current university papers...

joined 5 years 2 weeks agoI emailed Ken Perlin (the inventor of Perlin noise) about it last night, asking if a) someone else had already thought of this, and b) he had any thoughts. Hopefully he'll get back to me about it. :)

joined 4 years 3 months agoInteresting method. At first I couldnt figured it out how the first one works. After thinking it carefully I got it. Nice job on using 4th dimension to solve the problem. But the same is done before, sorry to deliver bad news.

http://www.gamedev.net/blog/33/entry-2138456-seamless-noise/

@Pompei2: animated 2D texture is nothing but a 3D texture, using 6 dimensions you can easily cover that.

joined 4 years 3 months agowow, pretty old topic :)