koji187 122 Report post Posted June 8, 2002 Hello after reading the ''sky rendering technique'' post & watching the great pics in it i decided to try and do a sky myself, i have finished my skyplane now i want to add the clouds & stuff in it, well i''m trying to implement perlin noise for the clouds but it just wont give me the right results that it is supposed to. here is the code i use, i got it from a site that explain how perlin noise works but still i cant get it right any help appreciated... double Noise(int x,int y,int oct) { int n = x + y * 57; n = (n<<13)^n; return ( 1.0 - ( (n * (n * n * octave_primes[oct][0] + octave_primes[oct][1]) + octave_primes[oct][2]) & 0x7fffffff) *0.000000000931322574615478515625/* /1073741824.0*/); } double SmoothedNoise(int x,int y,int oct) { double corners = ( Noise(x-1, y-1,oct)+Noise(x+1, y-1,oct)+Noise(x-1, y+1,oct)+Noise(x+1, y+1,oct) ) *0.0625; double sides = ( Noise(x-1, y,oct) +Noise(x+1, y,oct) +Noise(x, y-1,oct) +Noise(x, y+1,oct) ) * 0.125; double center = Noise(x, y,oct)*0.25; return corners + sides + center; } double Interpolate(double a,double b,double x) { double ft = x * D3DX_PI; double f = sin(ft*0.5); return a*(1-f) + b*f; } double InterpolatedNoise(double x, double y,int oct) { int integer_X = int(x); double fractional_X = x - integer_X; int integer_Y = int(y); double fractional_Y = y - integer_Y; double v1 = SmoothedNoise(integer_X, integer_Y,oct); double v2 = SmoothedNoise(integer_X + 1, integer_Y,oct); double v3 = SmoothedNoise(integer_X, integer_Y + 1,oct); double v4 = SmoothedNoise(integer_X + 1, integer_Y + 1,oct); double i1 = Interpolate(v1 , v2 , fractional_X); double i2 = Interpolate(v3 , v4 , fractional_X); return Interpolate(i1 , i2 , fractional_Y); } double PerlinNoise_2D(double x,double y) { double total = 0; double p = 0.707; double n = 4; for (int i=0;i<n;i++) { double frequency = pow(2,i); double amplitude = pow(p,i); total = total + InterpolatedNoise(x * frequency, y * frequency,i) * amplitude; } return total; } 0 Share this post Link to post Share on other sites

invective 118 Report post Posted June 8, 2002 Ken Perlin''s code is here.However you might want to do it in hardware with smoothed white noise. See the Kim Pallister article. 0 Share this post Link to post Share on other sites

kill 146 Report post Posted June 8, 2002 Post the screenshots man. Most people don''t look through someone''s code but can give you a couple of hints once they see the shots. 0 Share this post Link to post Share on other sites

Yann L 1802 Report post Posted June 10, 2002 A bit off topic, but I thought it might be interesting to mention that Tom Nuydens from Delphi3D has realeased a little demo generating basic Perlin noise on the 3D hardware. I haven''t looked at it yet, so I don''t know how good it is, but it might be worth checking out. Get it here./ Yann 0 Share this post Link to post Share on other sites