int generateTexture3D(char *framebuffer, int width, int height, char *imagePx) { GzColor textureColor = { 0, 0, 0 }; int finalColor[] = { 0, 0, 0 }; char *copybuffer = framebuffer; Perlin *per = new Perlin(4, 0.5, 2.0, 10); for (float x = 0; x < width; x += 1) { for (float y = 0; y < height; y += 1) { float noise = 0.0f; for (float z = 0; z < 256; z += 10){ noise += noise3d[(int)x][(int)y][(int)z] = per->Get(x, y, z); //noise += noise3d[(int)x][(int)y][(int)z] = ken_perlin_3D(x, y, z); } noise /= 25; textureColor[RED] = finddensity3D(y, x, 256, 256, noise, 45); textureColor[GREEN] = finddensity3D(y, x, 256, 256, noise, 45); //textureColor[RED] = noise; //textureColor[GREEN] = noise; textureColor[BLUE] = 0.8; finalColor[RED] = (int)(textureColor[RED] * 255); finalColor[GREEN] = (int)(textureColor[GREEN] * 255); finalColor[BLUE] = (int)(textureColor[BLUE] * 255); if (finalColor[RED] > 255) finalColor[RED] = 255; if (finalColor[RED] < 0) finalColor[RED] = 0; if (finalColor[GREEN] > 255) finalColor[GREEN] = 255; if (finalColor[GREEN] < 0) finalColor[GREEN] = 0; if (finalColor[BLUE] > 255) finalColor[BLUE] = 255; if (finalColor[BLUE] < 0) finalColor[BLUE] = 0; *(framebuffer++) = (char)(finalColor[RED]); *(framebuffer++) = (char)(finalColor[GREEN]); *(framebuffer++) = (char)(finalColor[BLUE]); } } return 0; }
bool Noise::perlin(Map& map, int octaves = 8, float frequency = 10.0f, float amplitude = 0.5f) { Perlin* noise = new Perlin(octaves, frequency, amplitude, rand()); for (int x = 0; x < map.getSize(); x++) { for (int y = 0; y < map.getSize(); y++) { map.map[x][y] = noise->Get((float)x / (float)map.getSize(), (float)y / (float)map.getSize()); } } return true; }
void Image::perlinNoise(int seed, bool alpha) { Perlin *perlin = new Perlin(12,33,1,seed); unsigned int *imageData32 = (unsigned int*)imageData; Color pixelColor; Number noiseVal; for(int i=0; i < width*height;i++) { noiseVal = fabs(1.0f/perlin->Get( 0.1+(0.9f/((Number)width)) * (i%width), (1.0f/((Number)height)) * (i - (i%width)))); if(alpha) pixelColor.setColor(noiseVal, noiseVal, noiseVal, noiseVal); else pixelColor.setColor(noiseVal, noiseVal, noiseVal, 1.0f); imageData32[i] = pixelColor.getUint(); } }
int generateTexture2D(char *framebuffer, int width, int height, char* imagePx) { GzColor textureColor = { 0, 0, 0 }; int finalColor[] = { 0, 0, 0 }; char *copybuffer = framebuffer; Perlin *per = new Perlin(4, 6.5, 0.5, 10); for (float x = 0; x < 256; x += 1) { for (float y = 0; y < 256; y += 1) { float noise = per->Get(x, y); //float noise = perlin_type1_2D(x, y); textureColor[RED] = finddensity(y, x, 256, 256, noise, 145); textureColor[GREEN] = finddensity(y, x, 256, 256, noise, 145); //textureColor[RED] = noise; //textureColor[GREEN] = noise; textureColor[BLUE] = 0.8; finalColor[RED] = (int)(textureColor[RED] * 255); finalColor[GREEN] = (int)(textureColor[GREEN] * 255); finalColor[BLUE] = (int)(textureColor[BLUE] * 255); if (finalColor[RED] > 255) finalColor[RED] = 255; if (finalColor[RED] < 0) finalColor[RED] = 0; if (finalColor[GREEN] > 255) finalColor[GREEN] = 255; if (finalColor[GREEN] < 0) finalColor[GREEN] = 0; if (finalColor[BLUE] > 255) finalColor[BLUE] = 255; if (finalColor[BLUE] < 0) finalColor[BLUE] = 0; *(framebuffer++) = (char)(finalColor[RED]); *(framebuffer++) = (char)(finalColor[GREEN]); *(framebuffer++) = (char)(finalColor[BLUE]); } } return 0; }
void copyNoiseToHeightmap(Perlin& pn, RECT rc, HeightMap<T>* pHMap, int tMax) { int x,y; float xStep = 1.0f/(rc.right-rc.left); float yStep = 1.0f/(rc.bottom-rc.top); //Perlin产生的值域在[-振幅,+振幅]之间 //--缩放到0-255的区间 float offset = pn.GetAmplitude(); float range = pn.GetAmplitude()*2; for(y=rc.top; y<rc.bottom; y++) { for(x=rc.left; x<rc.right; x++) { float n = pn.Get(x*xStep, y*yStep); T tn = T((n+offset)/range*tMax); pHMap->setValue(x, y, tn); } }//endof for }
inline float StdPerlin( Perlin& obj, float x, float y, float w, float h ) { return obj.Get(x,y); }
float fx1(float a) { return gMediumPerlinNoise.Get(a/(CK_MAX_WIDTH/50), 0.22) * 800; // return gPerlinNoise.Get(a/(CK_MAX_WIDTH/5), 0.22) * 800 + gMediumPerlinNoise.Get(a/(CK_MAX_WIDTH/50), 0.22) * 800; }
float fz1(float a) { return gMediumPerlinNoise.Get(a/(CK_MAX_WIDTH/20), 0.22) * 800; }