• Create Account

### #ActualJTippetts

Posted 30 October 2012 - 04:41 PM

It's a little tough reading your code, since it seems the forums ate your newlines, so correct me if I'm wrong about what you are trying to do.

1) You have an array of tiles, tiles indexed on i and j.
2) Each tile is a chunk of noise, the individual pixels of which are indexed on localx and localy.
3) You want to calculate each pixel of the tiles such that the whole map tiles seamlessly with itself

For reference, here is how the 2D tiling noise in ANL is constructed:
 {
size_t w=a.width();
size_t h=a.height();
static double pi2=3.141592*2.0;
size_t x,y;
for(x=0; x<w; ++x)
{
for(y=0; y<h; ++y)
{
double p=(double)x / (double)w;
double q=(double)y / (double)h;
double r;
double nx,ny,nz,nw,nu,nv,val=0.0;
double dx, dy, dz;
dx=ranges.loopx1-ranges.loopx0;
dy=ranges.loopy1-ranges.loopy0;
p=p*(ranges.mapx1-ranges.mapx0)/(ranges.loopx1-ranges.loopx0);
q=q*(ranges.mapy1-ranges.mapy0)/(ranges.loopy1-ranges.loopy0);
nx=ranges.loopx0 + cos(p*pi2) * dx/pi2;
ny=ranges.loopx0 + sin(p*pi2) * dx/pi2;
nz=ranges.loopy0 + cos(q*pi2) * dy/pi2;
nw=ranges.loopy0 + sin(q*pi2) * dy/pi2;
val=m.get(nx,ny,nz,nw);

a.set(x,y,val);
}
}


Now, comparing your code, these lines where you calculate your noise input coords look suspicious to me:

nx = absx + Math.cos(s * 2 * Math.PI)*dx/(2*Math.PI);
ny = absy + Math.cos(t * 2 * Math.PI)*dy/(2*Math.PI);
nz = absx + Math.sin(s * 2 * Math.PI)*dx/(2*Math.PI);
nw = absy + Math.sin(t * 2 * Math.PI)*dy/(2*Math.PI);


absx and absy are calculated as the global pixel coordinates of the sample, so they are going to change in value as the pixel coords change. In my original implementation, I use loopx0 and loopy0 here, which do not change. The only way the coordinates change is through the value of s and t, which should be calculated from the pixel coords.

In my implementation, I specify the ranges over which the noise loops explicitly, rather than tying the range to the tile coordinates. Similarly, I specify the ranges over which the tiles are mapped explicitly. The ranges loopx0 to loopx1 and loopy0 to loopy1 specify the range of noise mapped to the entire map. The ranges mapx0 to mapx1 and mapy0 to mapy1 specify the range of noise (a sub-range of the larger looping range) to map to a given tile. This would be calculated by dividing the larger loop range up into as many equal-sized pieces as there are tiles.

As far as getting different terrain, I implement a seeding technique where a seed is passed as another input to the noise function, and is hashed together with the input coordinates. Change the seed, get a different output.

### #1JTippetts

Posted 30 October 2012 - 04:41 PM

It's a little tough reading your code, since it seems the forums ate your newlines, so correct me if I'm wrong about what you are trying to do.

1) You have an array of tiles, tiles indexed on i and j.
2) Each tile is a chunk of noise, the individual pixels of which are indexed on localx and localy.
3) You want to calculate each pixel of the tiles such that the whole map tiles seamlessly with itself

For reference, here is how the 2D tiling noise in ANL is constructed:
	 {
size_t w=a.width();
size_t h=a.height();
static double pi2=3.141592*2.0;
size_t x,y;
for(x=0; x<w; ++x)
{
for(y=0; y<h; ++y)
{
double p=(double)x / (double)w;
double q=(double)y / (double)h;
double r;
double nx,ny,nz,nw,nu,nv,val=0.0;
double dx, dy, dz;
dx=ranges.loopx1-ranges.loopx0;
dy=ranges.loopy1-ranges.loopy0;
p=p*(ranges.mapx1-ranges.mapx0)/(ranges.loopx1-ranges.loopx0);
q=q*(ranges.mapy1-ranges.mapy0)/(ranges.loopy1-ranges.loopy0);
nx=ranges.loopx0 + cos(p*pi2) * dx/pi2;
ny=ranges.loopx0 + sin(p*pi2) * dx/pi2;
nz=ranges.loopy0 + cos(q*pi2) * dy/pi2;
nw=ranges.loopy0 + sin(q*pi2) * dy/pi2;
val=m.get(nx,ny,nz,nw);

a.set(x,y,val);
}
}


Now, comparing your code, these lines where you calculate your noise input coords look suspicious to me:

nx = absx + Math.cos(s * 2 * Math.PI)*dx/(2*Math.PI);
ny = absy + Math.cos(t * 2 * Math.PI)*dy/(2*Math.PI);
nz = absx + Math.sin(s * 2 * Math.PI)*dx/(2*Math.PI);
nw = absy + Math.sin(t * 2 * Math.PI)*dy/(2*Math.PI);


absx and absy are calculated as the global pixel coordinates of the sample, so they are going to change in value as the pixel coords change. In my original implementation, I use loopx0 and loopy0 here, which do not change. The only way the coordinates change is through the value of s and t, which should be calculated from the pixel coords.

In my implementation, I specify the ranges over which the noise loops explicitly, rather than tying the range to the tile coordinates. Similarly, I specify the ranges over which the tiles are mapped explicitly. The ranges loopx0 to loopx1 and loopy0 to loopy1 specify the range of noise mapped to the entire map. The ranges mapx0 to mapx1 and mapy0 to mapy1 specify the range of noise (a sub-range of the larger looping range) to map to a given tile. This would be calculated by dividing the larger loop range up into as many equal-sized pieces as there are tiles.

As far as getting different terrain, I implement a seeding technique where a seed is passed as another input to the noise function, and is hashed together with the input coordinates. Change the seed, get a different output.

PARTNERS