Hi Comet,
That would sure do it, and this is how I create seamless images in photoshop. The problem of course is the outer part of your image is seamless, the inner seams through the middle aren't unless the original image was seamless.
What I am trying to do is implement Ken Perlin's noise algorithms from GPU Gems 2:
http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter26.html
The algorithm generates perlin noise by subdividing the image into cells, then generating gradient vectors at the corner of each cell (one per corner but random). All four vectors in the cell are blended together to generate a smooth surface. The influence of each gradient at an point in a cell is determined by the dot product between the gradient vector at a corner and a vector from the cell corner to the point in the cell. You can see that in my image above..there are 16x16 cells in that image. Now as long as the 4 gradient vectors are the same two cells should be identical (hence the repeat every 8 cells in my image). Consequently if we make the gradient vectors periodic, the texture should be seamless (which it isn't
). The shader snippet is shown below. I've added some extra comments to make life easier:
// 3D noise
float4 inoise(float3 p)
{
float3 P = fmod(floor(p), 256.0); // FIND UNIT CUBE THAT CONTAINS POINT
p -= floor(p); // FIND RELATIVE X,Y,Z OF POINT IN CUBE.
float3 f = fade(p); // COMPUTE FADE CURVES FOR EACH OF X,Y,Z FOR BLENDING.
P = P/256.0;
float one = 1.0/256.0;
// HASH COORDINATES OF THE 8 CUBE CORNERS (PSUEDORANDOM NUMBERS)
float4 AA = perm2d(P.xy) + P.z;
//GET RANDOM VECTORS FOR CORNERS AND ADD BLENDED RESULTS FROM 8 CORNERS OF CUBE
return lerp( lerp( lerp( gradperm(AA.x, p),
gradperm(AA.z, p + float3(-1, 0, 0) ), f.x),
lerp( gradperm(AA.y, p + float3(0, -1, 0) ),
gradperm(AA.w, p + float3(-1, -1, 0) ), f.x), f.y),
lerp( lerp( gradperm((AA.x + one), p + float3(0, 0, -1) ),
gradperm((AA.z + one), p + float3(-1, 0, -1) ), f.x),
lerp( gradperm((AA.y + one), p + float3(0, -1, -1) ),
gradperm((AA.w + one), p + float3(-1, -1, -1) ), f.x), f.y), f.z);
}
float4 perm2d(float2 p)
{
//2D PERMUTATION TABLE USED TO GENERATE PSEUDORANDOM NUMBERS
return tex2Dlod(permSampler2d, float4(p % (numCells/(numRepeats*256.0)), 0, 0));
}
//3D
float gradperm(float x, float3 p)
{
//TEXTURE CONTAINING AN ARRAY OF GRADIENT VECTORS
float4 f = (tex1Dlod(permGradSampler, float4(x, 0, 0, 0))-0.5)*2.0;
return dot(f, p);
}
numCells and numRepeats are globals.
Right now I have confirmed that the gradients at each point are indeed periodic...so why they don't blend to make a seamless texture is....puzzling. The modulus seems to have caused a negative shift in the output by 1 pixel...this might be the reason...or there may be an issue in the lerp blend.
Determined to solve it
GrumpyOne - the natural state of the programmer - Forester Pro (Tree & Plant Creator), Medusa Pro (Rock Creator), Mr Normal (Normal Map Generator) http://www.hptware.co.uk