public static float[,] ValueNoiseMapGenerator(int width, int height, int seed, float noiseScale, int octaves, float persistance) { float[,] noiseMap = new float[width, height]; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { float valor = VoronoiNoise.FractalNoise2D(x, y, octaves, noiseScale, persistance, seed) * 2f; noiseMap[x, y] = valor; } } return(noiseMap); }
float SampleGround(float x, float z, PerlinNoise perlin, VoronoiNoise voronoi) { //This creates the noise used for the ground. //The last value (8.0f) is the amp that defines (roughly) the maximum //and minimum vaule the ground varies from the surface level //return perlin.FractalNoise2D(x, z, 12, 80.0f, 8.0f); test = voronoi.FractalNoise2D(x, z, 8, 32.0f, 8.0f) + perlin.FractalNoise2D(x, z, 12, 80.0f, 8.0f)/2; if(test > 1.85f) { return Mathf.Min (1.85f, test) + test/3f; } else { return test; } //return Mathf.Min (2.75f,test); }
public void CreateVoxels(PerlinNoise surfacePerlin, PerlinNoise cavePerlin) { //float startTime = Time.realtimeSinceStartup; //Creates the data the mesh is created form. Fills m_voxels with values between -1 and 1 where //-1 is a soild voxel and 1 is a empty voxel. int w = m_voxels.GetLength(0); int h = m_voxels.GetLength(1); int l = m_voxels.GetLength(2); for (int x = 0; x < w; x++) { for (int z = 0; z < l; z++) { //world pos is the voxels position plus the voxel chunks position float worldX = x + m_pos.x; float worldZ = z + m_pos.z; float ht = SampleGround(worldX, worldZ, surfacePerlin); // float localBiom = 0f; // localBiom += (float)z/h * ((float)m_neighbourBiomes[2] - (float)m_biome); // localBiom += (float)x/w * ((float)m_neighbourBiomes[1] - (float)m_biome); // localBiom += (1f-(float)z/h) * ((float)m_neighbourBiomes[0]- (float)m_biome); // localBiom += (1f-(float)x/w) * ((float)m_neighbourBiomes[3]- (float)m_biome); // float factor = Mathf.Clamp01((surfacePerlin.FractalNoise2D(x, z, 4, 400.0f, 1.0f) + 0.75f)/1.5f); // float it = ht + SampleIslands(worldX, worldZ, surfacePerlin); // ht = (ht+m_surfaceLevel+1f) * factor + it * (1f-factor); // float factor = Mathf.Clamp01((surfacePerlin.FractalNoise2D(x, z, 4, 400.0f, 1.5f) + 0.75f)/1.5f); // float it = ht + SampleSpikes(worldX, worldZ, surfacePerlin); // ht = it; //(ht-1f) * factor + it * (1f-factor); /* * float factor = Mathf.Clamp01((surfacePerlin.FractalNoise2D(x, z, 4, 400.0f, 1.0f) + 0.75f)/1.5f); * float st = SampleSpikes(worldX, worldZ, surfacePerlin); * ht = (ht+m_surfaceLevel-1f) * factor + (ht + st) * (1f-factor); * * factor = Mathf.Clamp01((surfacePerlin.FractalNoise2D(x, z, 4, 150.0f, 1.0f) + 0.75f)/1.5f); * float it = SampleIslands(worldX, worldZ, surfacePerlin); * ht = (ht+m_surfaceLevel+1f) * factor + (ht + it) * (1f-factor); * * ht -= m_surfaceLevel; * ht -= SampleMountains(worldX, worldZ, surfacePerlin); */ VoronoiNoise.SetDistanceToEuclidian(); VoronoiNoise.SetCombinationTo_D2_D0(); ht *= VoronoiNoise.FractalNoise2D(worldX, worldZ, 2, 500f, 2f, 6); float factor = Mathf.Clamp01((surfacePerlin.FractalNoise2D(worldX, worldZ, 4, 400.0f, 1.0f) + 0.9375f) / 1.875f); float st = SampleSpikes(worldX, worldZ, surfacePerlin); ht = (ht + m_surfaceLevel - 1f) * factor + (ht + st) * (1f - factor); factor = Mathf.Clamp01((surfacePerlin.FractalNoise2D(worldX, worldZ, 4, 150.0f, 1.0f) + 0.9375f) / 1.875f); float it = SampleIslands(worldX, worldZ, surfacePerlin); ht = (ht + m_surfaceLevel + 1f) * factor + (ht + it) * (1f - factor); ht -= m_surfaceLevel * 1.5f; // ht -= SampleMountains(worldX, worldZ, surfacePerlin); for (int y = 0; y < h; y++) { float worldY = y + m_pos.y - m_surfaceLevel; //If we take the heigth value and add the world //the voxels will change from positiove to negative where the surface cuts through the voxel chunk m_voxels[x, y, z] = Mathf.Clamp(ht + worldY, -1.0f, 1.0f); if (m_biome == 15) { float caveHt = SampleCaves(worldX, worldY, worldZ, cavePerlin); //This fades the voxel value so the caves never appear more than h units from //the surface level. float fade = 1.0f - Mathf.Clamp01(Mathf.Max(0.0f, worldY) / h); m_voxels[x, y, z] += caveHt * fade; m_voxels[x, y, z] = Mathf.Clamp(m_voxels[x, y, z], -1.0f, 1.0f); } } } } //Debug.Log("Create voxels time = " + (Time.realtimeSinceStartup-startTime).ToString() ); }