   libnoise: can it tile noise?
  Hello,not sure if I'm posting in the right forum, but here goes....Does anyone know if libnoise can be made to produce tileable noise textures?Simple as that!ThanksSimon   
  Out of the box, no it can't (unless there is something in the noiseutils package I haven't seen; it's possible, since I haven't played much with those). You can do some trickery by sampling different areas adjacent to each other, and blending from one to the other based on x/y/z coordinate progression across the area. IE, to make an area tile left-to-right, you would sample two regions of equal size, one to the right of the other. As the X coordinate progresses, you increase the blend between the two sample areas, so that when X=0 (or, the left edge of the area) then you blend fully from the right-hand sample area, whereas when X=WIDTH (or, the right edge of the area) you blend fully from the left sample area. Maybe this picture will illustrate a little better:In the picture we are sampling the noise function from 2 points: (-WIDTH+x, y) and (x,y). (WIDTH is the size of the area you want to output into a texture, buffer, or whatever) We can calculate a blending factor between 0 and 1 with x/WIDTH, and use this blending factor to linearly interpolate from B to A, like so:valA = NoiseModule:GetValue(-WIDTH + x, y, 0);valB = NoiseModule:GetValue(x,y,0);blend = x/WIDTH;valFinal = valB + blend*(valA - valB);In this fashion, when the sample point lies on the left edge of the areas, the blend factor is 0, and the final value is the exact value on the left edge of the right-hand area. When blend is 1, the final value is the exact value on the right edge of the left-hand area, and thus this edge will tile exactly with the edge for blend=0. The interior values are linear blends, causing a gradual fade from one side to the other.For tiling in 2 dimensions, you need to sample a block of 4 areas in a similar fashion, interpolate based on x between the top 2 and the bottom 2 values, then interpolate these intermediate values based on y for the final value. Similarly, for tiling in 3D, you need to sample a block of 8 areas, and perform intermediate interpolations on x and y, and the final on z, for a total of 9 interpolations. (I've never had to create tiling 3D noise, however, so I've avoided this expensive operation.)Note that this can alter the fundamental character of the noise. For the standard Perlin it isn't too noticable, but for modules such as the ridged multifractal, it is more obvious.   ;  What a comprehensive answer... Thank you. Its a very good approach.Really I am looking for a fast real-time noise generation technique. I wanted it to tile so I could test a theory I had:Since my engine only requires noise sampling at various points, which vary around the tile, I thought I could have a 2d array of values representing the noise values. The array starts empty. Every time a real-time noise calculation is required, I check the table to see if it contains a value yet, if not I calculate the noise function and use the value, but also store it in the array.So gradually the array is filled, and less and less noise functions are called to do the same job.The array could then perhaps also be stored to disk when the player quits, improving performance next game.----Its kind of like building up premade noise textures with one important difference. I am not restricted to the supplied frequencies and octaves of the premade textures. They can be changed in real time, I jut have to start a new array (or load one created earlier)Perhaps this is stupid, since I could do something similar by having lots of premade textures and blending them to mix new noise patterns in realtime... then its a GPU operation.... hmmm;  What you're doing is called memoization. That's a technique where you save the result of a function so that you can reuse it instead of computing the result when it is needed again.I think it's strange that a noise generation library doesn't have a method to create tileable noise. Tiling Perlin noise, and similiar types of noise, is fairly simple. Perlin noise works by interpolating between gradients defined at the intersection points on a grid. Inside each cell, the values are computed by using the gradients from the four corners and interpolating between the resulting values. Making it wrap around just requires wrapping around the grid.   ;  I took a look at the noiseutils.zip package available from the same page as libnoise, and it looks like there are several useful classes in there for generating seamless mappings, as well as other mappings (cylindrical, spherical, etc...) Might want to take a look at them to see if they suit your needs.   ;Quote:Original post by JTippetts[...]valA = NoiseModule:GetValue(-WIDTH + x, y, 0);valB = NoiseModule:GetValue(x,y,0);blend = x/WIDTH;valFinal = valB + blend*(valA - valB);In this fashion, when the sample point lies on the left edge of the areas, the blend factor is 0, and the final value is the exact value on the left edge of the right-hand area. When blend is 1, the final value is the exact value on the right edge of the left-hand area, and thus this edge will tile exactly with the edge for blend=0. The interior values are linear blends, causing a gradual fade from one side to the other.[...]Note that this can alter the fundamental character of the noise. For the standard Perlin it isn't too noticable, but for modules such as the ridged multifractal, it is more obvious.Realize that while that technique might work, it also changes the noise distribution depending on the position of the sample point. On each edge, the noise will have uniform distribution, but in the middle, it will have a guassian ditribution, and the points in between will vary between the two distributions. Perhaps this is what you meant by 'fundamental character' of the noise, but mentioning the distribution changes makes the point more obvious (to me, anyways =-)   ;Quote:Original post by Extrarius... but mentioning the distribution changes makes the point more obvious (to me, anyways =-)Your logic offends me, and I challenge you to a duel with wet spaghetti. Have at you, fiend!Yeah, that's basically what I meant, though I see it on a more visual level. It sometimes looks weird doing it this way; you can almost see the blend going on with some basis functions. [grin]EDIT: Some of the artifacting that I've noticed from doing seamless in this fashion comes from the underlying gradient noise basis function, as well. I implemented some generators based on Perlin's simplex function, and they seem to look better when made seamless. In this image, the one on the left is based on gradient noise interpolated to be seamless as above, the one on the right is simplex noise similarly interpolated. You can clearly see grid artifacts in the left image.[Edited by - JTippetts on September 9, 2007 1:09:37 PM];  What does your normal perlin noise look like when it isn't blended to be tileable? It looks like the grid is visible even near the edges, where the texture should be almost entirely from one source.   ;  Yeah, the grid artifacts are still there in the normal gradient ridged noise. The blending accentuates them quite a lot, however. Grid artifacts are quite noticeable in ridged multifractal noise based on gradient, which is why I chose ridged for the example, since it's often used for landscapes and such. In this image I have the non-seamless and seamless versions of gradient noise (top) and simplex (bottom). You can see that while both forms are made 'muddier' by the blending, the grid alignment that is present in gradient noise is accentuated. The high spots in a gradient ridged tend to follow integral boundaries, so the blending has a higher chance of blending from high-spot to high-spot on the integral boundaries, compounding the artifacts. Simplex noise isn't grid based, so while the seamless version of it is more muddled, there are fewer obvious underlying artifacts to accentuate.I'm still trying to figure out a 'good' method from producing quality tiling noise using a general library such as libnoise. By mapping noise from a cylinder in the 3D noise space, you can get good quality noise that tiles from left to right or top to bottom on a texture, but extending that to a torus for tiling in both directions presents some pretty knotty distortion problems. You can do pretty good tiling by messing with the basis functions, but that presents interface problems when using a third-party library such as libnoise.   ;  It's almost enough to make me want to write a noise generation library that actually works properly. There's no reason for there not to be a gradient interpolator module that interpolates between gradients defined on grid points by the user. Actually, writing a function to do this is extremely simple; there's really not even much of a need for a library. The function itself is completely deterministic, yet it does most of the work involved in computing perlin noise. Making it generate noise that tiles is trivial (set the gradients at the corresponding edges to be the same).   