Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualEndemoniada

Posted 08 May 2013 - 10:05 AM

Hi guys,

 

I am indeed using a 2D noise function, it's Perlin's Improved Noise, here it is:

 

It makes some pretty nice tileable textures but maybe they aren't as nice as they can be ? Some of your posts are hard to understand, maybe now that you see my code you can be more specific ? Thanks.

 

 

float pnoise2( float x, float y, int px, int py )
{
    int ix0, iy0, ix1, iy1;
    float fx0, fy0, fx1, fy1;
    float s, t, nx0, nx1, n0, n1;
 
    ix0 = FASTFLOOR( x ); // Integer part of x
    iy0 = FASTFLOOR( y ); // Integer part of y
    fx0 = x - ix0; // Fractional part of x
    fy0 = y - iy0; // Fractional part of y
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    ix1 = (( ix0 + 1 ) % px) & 0xff; // Wrap to 0..px-1 and wrap to 0..255
    iy1 = (( iy0 + 1 ) % py) & 0xff; // Wrap to 0..py-1 and wrap to 0..255
    ix0 = ( ix0 % px ) & 0xff;
    iy0 = ( iy0 % py ) & 0xff;
    
    t = FADE( fy0 );
    s = FADE( fx0 );
 
    nx0 = grad2(perm[ix0 + perm[iy0]], fx0, fy0);
    nx1 = grad2(perm[ix0 + perm[iy1]], fx0, fy1);
    n0 = LERP( t, nx0, nx1 );
 
    nx0 = grad2(perm[ix1 + perm[iy0]], fx1, fy0);
    nx1 = grad2(perm[ix1 + perm[iy1]], fx1, fy1);
    n1 = LERP(t, nx0, nx1);
 
    return 0.507f * ( LERP( s, n0, n1 ) );
}


#1Endemoniada

Posted 07 May 2013 - 02:14 PM

Hi guys,

 

I am indeed using a 2D noise function, it's Perlin's Improved Noise, here it is:

 

It makes some pretty nice tileable textures but maybe they aren't as nice as they can be ? Some of your posts are hard to understand, maybe now that you see my code you can be more specific ? Thanks.

 

float pnoise2( float x, float y, int px, int py )
{
    int ix0, iy0, ix1, iy1;
    float fx0, fy0, fx1, fy1;
    float s, t, nx0, nx1, n0, n1;
 
    ix0 = FASTFLOOR( x ); // Integer part of x
    iy0 = FASTFLOOR( y ); // Integer part of y
    fx0 = x - ix0; // Fractional part of x
    fy0 = y - iy0; // Fractional part of y
    fx1 = fx0 - 1.0f;
    fy1 = fy0 - 1.0f;
    ix1 = (( ix0 + 1 ) % px) & 0xff; // Wrap to 0..px-1 and wrap to 0..255
    iy1 = (( iy0 + 1 ) % py) & 0xff; // Wrap to 0..py-1 and wrap to 0..255
    ix0 = ( ix0 % px ) & 0xff;
    iy0 = ( iy0 % py ) & 0xff;
    
    t = FADE( fy0 );
    s = FADE( fx0 );
 
    nx0 = grad2(perm[ix0 + perm[iy0]], fx0, fy0);
    nx1 = grad2(perm[ix0 + perm[iy1]], fx0, fy1);
    n0 = LERP( t, nx0, nx1 );
 
    nx0 = grad2(perm[ix1 + perm[iy0]], fx1, fy0);
    nx1 = grad2(perm[ix1 + perm[iy1]], fx1, fy1);
    n1 = LERP(t, nx0, nx1);
 
    return 0.507f * ( LERP( s, n0, n1 ) );
}

 
// precompute speed up table
float freq=1.0f;

for(int i=0;i<octaves;i++){
exp_table[i]=powf(freq,-h);
freq*=lacunarity;
}
 
// fbm
int px=period_x;
int py=period_y;
float v=0.0f;
 
for(int i=0;i<octaves;i++){
v+=pnoise2(x,y,px,py)*exp_table[i];
x*=lacunarity;
y*=lacunarity;
px*=lacunarity;
py*=lacunarity;
}

PARTNERS