   help with perlin noise
  ive got a function for perlin noise but i get rly weird results... i call the functions with the following line... Generate(0.4f, 5, 128, 128, 1025 )... is there something ive missed? any more info that is needed? i render it straight from the heightmap without any further transformations..float CTERRAIN::Noise(int x, int y){int n = x + y * 57 + seed;n = (n &lt;&lt; 13) ^ n;return (float) (1.0 - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);//return value is always in range [-1.0, 1.0]}float CTERRAIN::SmoothNoise(int x, int y){float corners = (Noise(x-1, y-1) + Noise(x+1, y-1) + Noise(x-1, y+1) + Noise(x+1, y+1)) / 16;float sides   = (Noise(x-1, y) + Noise(x+1, y) + Noise(x, y-1) + Noise(x, y+1)) / 8;float center  =  Noise(x, y ) / 4;return corners + sides + center;}float CTERRAIN::Interpolate(float a, float b, float x){float ft = x * 3.1415927f;float f = float((1 - cos(ft)) * 0.5f);return  a*(1-f) + b*f; //f*(b-a)+a; //}float CTERRAIN::InterpolatedNoise(float x, float y){int wholePartX = (int) x;float fractionPartX = x - wholePartX;int wholePartY = (int) y;float fractionPartY = y - wholePartY;float v1 = SmoothNoise(wholePartX, wholePartY);float v2 = SmoothNoise(wholePartX + 1, wholePartY);float v3 = SmoothNoise(wholePartX, wholePartY + 1);float v4 = SmoothNoise(wholePartX + 1, wholePartY + 1);float i1 = Interpolate(v1, v2, fractionPartX);float i2 = Interpolate(v3, v4, fractionPartX);return Interpolate(i1, i2, fractionPartY);}void CTERRAIN::Generate(float persistence, int octaves, unsigned int width, unsigned int height, int seed ){for (unsigned int y = 0; y &lt; height; ++y){for (unsigned int x = 0; x &lt; width; ++x){float total = 0;float frequency =  1;float amplitude = persistence;for (int i = 0; i &lt; octaves-1; i++){total = total + InterpolatedNoise(x * frequency , y * frequency ) * amplitude;    frequency *= 2;amplitude *= persistence;}HeightMap[x][y] = total;}}}
  What results do you get?And you can use [ source ] and [ /source ] tags for source code.   ;  chagned the settings to... Generate(1.0f, 8, 128, 128, 1025 ).. jsut to make it more visible.. i dont get any fractal noise... and its not smoothed properly either..http://show.imagehosting.us/show/1363376/0/nouser_1363/T0_-1_1363376.jpgfor some reason i cant get [img][/img] to work...here is my render function...//loop through the Z-axis of the terrainfor( iZ=0; iZ<256-1; iZ++ ){//begin a new triangle stripglBegin( GL_TRIANGLE_STRIP );//loop through the X-axis of the terrain//this is where the triangle strip is constructedfor( iX=0; iX<256-1; iX++ ){//use height-based coloring (high-points are//light, low points are dark)ucColor= GetScaledHeightAtPoint( iX, iZ )+0.1f;//GetTrueHeightAtPoint( iX, iZ );//set the color with OpenGL, and render the pointglColor3f( ucColor, ucColor, ucColor );glVertex3f( ( float )iX, GetScaledHeightAtPoint( iX, iZ ), ( float )iZ );//use height-based coloring (high-points are//light, low points are dark)ucColor= GetScaledHeightAtPoint( iX, iZ+1 )+0.1f;//GetTrueHeightAtPoint( iX, iZ+1 );//set the color with OpenGL, and render the pointglColor3f( ucColor, ucColor, ucColor );glVertex3f( ( float )iX, GetScaledHeightAtPoint( iX, iZ+1 ), ( float )iZ+1 );//increase the vertex count by two (which is how many we sent to the API)m_iVertsPerFrame+= 2;//there are no triangles being rendered on the first X-loop, they just start the//triangle strip offif( iX!= 0 )m_iTrisPerFrame+= 2;}//end the triangle stripglEnd( );}} [Edited by - Dragon_Strike on May 15, 2006 4:31:53 PM];  I'm fairly sure it's because your frequency is starting out entirely too high.  In my heightmap generator, these values produce acceptable result:-frequency = 0.05-persistance = .5 - 2.0 (this isn't known fact, but in my experience, persistence basically controls the brightness of your high(white) spots)-octaves: 2 - 4Try it with those values and let's see what you get.  Hope that helps.-AJEDIT: Fixed a typo   ;  it is definitly the frequency as u235 mentions. the way it is set up now would be great for generating a rough texture for use on rock as an example. basically with a freqency of 128 on a 128 width texture you can expect a "hill - valley" combonation to occur every pixel.try changing the float freqency = 1; to 10 or higher. that should give you a "hill - valley" combo about every 13-15 pixels on that 128 texture if i did the math the correct direction (otherwise it should be .1 ...).   ;  this is how it looks with teh following settings... Generate(0.8f, 8, 256, 256, 1025 )frequency = 0.05fit looks better but there is way to much contrast in it.. and it gets rly flat when i render it as a mesh... doesnt look very terrainy to me… http://www.imagehosting.us/index.php?action=show&ident=1364121   ;  solved it... had to do some scaling..   