void CSulPerlinNoise2D::create( osg::Image* pImage ) { float* pdata = new float[m_w*m_h]; sigma::uint32 x,y; for ( y=0; y<m_h; y++ ) { float valY = (float)y/(float)m_h; for ( x=0; x<m_w; x++ ) { float valX = (float)x/m_w; float f = PerlinNoise( valX, valY ); f = f*m_s+m_o; f = 1.0+f; if ( f<0.0 ) f = 0.0; if ( f>1.0 ) f = 1.0; *(pdata+y*(int)m_w+x) = f; } } pImage->setImage( m_w, m_h, 1, // 1=r? depth perhaps? GL_LUMINANCE, // internal format GL_LUMINANCE, GL_FLOAT, // pixelformat, type reinterpret_cast<unsigned char*>(pdata), // data osg::Image::USE_NEW_DELETE, 1 ); // packing //delete pdata; }
void makeImage (void) { int x, y; for (y = 0; y < WIDTH; y++) for (x = 0; x < HEIGHT; x++) { MatrixImage[x][y][0] = MatrixImage[x][y][1] = MatrixImage[x][y][2] = PerlinNoise (x, y , 8); } }
bool cScene::Init(FILE* fd) { maxHeight = 0; minHeight = SCENE_HEIGHT; int randomseed = 0; int amplitude = SCENE_HEIGHT/2; PerlinNoise noise = PerlinNoise(0.1,1,amplitude,8,randomseed); for(int z=0;z<SCENE_DEPTH;z++){ for(int x=0;x<SCENE_WIDTH;x++){ int alt = amplitude + (int)noise.GetHeight(x,z); int y; for (y = 0; y < alt; y++){ mapa[y][x][z] = 1; nCubes[y]++; } minHeight = min(y,minHeight); maxHeight = max(y,maxHeight); heightMap[x][z] = y; for(;y<SCENE_HEIGHT;y++){ mapa[y][x][z] = 0; } } } //fprintf(fd,"min-->%d\nmax-->%d\n",minHeight,maxHeight); initVBO(); initNormals(); unsigned long len = 0; if(shader.loadShader("vertexShader.vert", &len, VERTEX_SHADER) != OK) return false; if(shader.loadShader("fragmentShader.frag", &len, FRAGMENT_SHADER) != OK) return false; if(shader.compileShader(VERTEX_SHADER) != OK) { GLchar *log = shader.getCompilationLog(VERTEX_SHADER); return false; } if(shader.compileShader(FRAGMENT_SHADER) != OK) { GLchar *log = shader.getCompilationLog(FRAGMENT_SHADER); return false; } if(shader.linkShader(VERTEX_SHADER) != OK) { GLchar *log = shader.getLinkingLog(VERTEX_SHADER); return false; } if(shader.linkShader(FRAGMENT_SHADER) != OK) { GLchar *log = shader.getLinkingLog(FRAGMENT_SHADER); return false; } if(shader.useShader(VERTEX_SHADER) != OK) return false; //if(shader.useShader(FRAGMENT_SHADER) != OK) return false; return true; }
double Turbulence(Point point, double size) { double val = 0.0; double scale = 1.0; while (scale > size) { point /= scale; val += PerlinNoise(point.x, point.y, point.z) * scale; scale /= 2; } return val; }
double TrbEvaluate(const struct Turbulence *turbulence, double *position) { double P[3] = {0}; double noise_value = 0; P[0] = position[0] * turbulence->frequency[0] + turbulence->offset[0]; P[1] = position[1] * turbulence->frequency[1] + turbulence->offset[1]; P[2] = position[2] * turbulence->frequency[2] + turbulence->offset[2]; noise_value = PerlinNoise(P, turbulence->lacunarity, turbulence->gain, turbulence->octaves); return noise_value * turbulence->amplitude[0]; }
void ChunkManager::initialize(const std::string& saveFolder) { double amplitude = 64; double persistence = 0.01; double frequency = 0.05; double octaves = 1 ; srand(time(NULL)); double randomseed = rand() % 1990; if(jsonChunkExist(saveFolder + "A_terrain.json")) randomseed = loadTerrain(saveFolder); m_PerlinNoise = PerlinNoise(persistence, frequency, amplitude, octaves, randomseed); m_pathJson = saveFolder; saveTerrain(randomseed); }
void makeImage(void) { int x, y; int seed; int width; float disp; for (y = 0; y< ImageWidth; y++) { for (x = 0; x<ImageHeight; x++) { width = 65536; seed = 42; disp = PerlinNoise(x, y, width, 5, seed, 128); MatrixImage[x][y][0] = disp; MatrixImage[x][y][1] = disp; MatrixImage[x][y][2] = disp; } } }
void CSulPerlinNoise2D::CreateArray2D( CSulTexImage* p, float fScale, float fOfs, sigma::uint32 iMin, sigma::uint32 iMax ) { float w = p->GetWidth(); float h = p->GetHeight(); sigma::uint32 x,y; for ( y=0; y<h; y++ ) { float valY = (float)y/h; for ( x=0; x<w; x++ ) { float valX = (float)x/w; float f = PerlinNoise( valX, valY ); f = f*fScale+fOfs; if ( f<iMin ) f = iMin; if ( f>iMax ) f = iMax; p->Set( x, y, (sigma::uint8)f ); } } }
CCOPPERNORMAL::CCOPPERNORMAL( float aScale, const CPROCEDURALGENERATOR *aBoardNormalGenerator ) { m_board_normal_generator = aBoardNormalGenerator; m_copper_perlin = PerlinNoise( 0 ); m_scale = 1.0f / aScale; }
GridSystem::GridSystem() { GridSystem(10, 10, PerlinNoise(), 0.25f); }
int generateNoiseType2(char *framebuffer, int width, int height, char *imagePx) { GzColor textureColor = { 0, 0, 0 }; int finalColor[] = { 0, 0, 0 }; int seed = 63; int wide =12413; float disp1, disp2, disp3, disp4, disp5, disp6; for (float y = 0; y < height; y += 1) { for (float x = 0; x < width; x += 1) { disp1 = PerlinNoise(x, y, wide, 2, seed, 100); disp2 = PerlinNoise(x, y, wide, 2, seed, 25); disp3 = PerlinNoise(x, y, wide, 2, seed, 12.5); disp4 = PerlinNoise(x, y, wide, 2, seed, 6.25); disp5 = PerlinNoise(x, y, wide, 2, seed, 3.125); disp6 = PerlinNoise(x, y, wide, 2, seed, 1.56); float noise = disp1 + (disp2*.25) + (disp3*.125) + (disp4*.0625) + (disp5*.03125) + (disp6*.0156); //float noise = disp1 + (disp2*.25) + (disp3*.125) + (disp4*.0625) + (disp5*.03125) + (disp6*.0156); //float noise = disp6; textureColor[RED] = noise; textureColor[GREEN] = noise; textureColor[BLUE] = 255; if (noise > 255) noise = 255; if (noise < 0) noise = 0; float alpha = (noise / 255.0f) - 0.29; if (alpha > 255) alpha = 255; if (alpha < 0) alpha = 0; float r = (imagePx[3 * ((int)y * width + (int)(x))] < -1) ? imagePx[3 * ((int)y * width + (int)(x))] + 256 : imagePx[3 * ((int)y * width + (int)(x))]; float g = (imagePx[3 * ((int)y * width + (int)(x)) + 1] < -1) ? imagePx[3 * ((int)y * width + (int)(x)) + 1] + 256 : imagePx[3 * ((int)y * width + (int)(x)) + 1]; float b = (imagePx[3 * ((int)y * width + (int)(x)) + 2] < -1) ? imagePx[3 * ((int)y * width + (int)(x)) + 2] + 256 : imagePx[3 * ((int)y * width + (int)(x)) + 2]; finalColor[RED] = (int)((textureColor[RED])*(alpha)+(1 - alpha)*r); finalColor[GREEN] = (int)((textureColor[GREEN])*(alpha)+(1 - alpha)*g); finalColor[BLUE] = (int)((textureColor[BLUE])*(alpha)+(1 - alpha)*b); 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; }