public HillGenerator(long seed) { Frequency = 0.03; Lacunarity = 0.01; Persistance = 0.01; OctaveCount = 1; Seed = seed; TerrainNoise = new FastNoise(); ContinentNoise = new FastNoise(); CaveNoise = new Perlin(); GravelNoise = new Perlin(); TreeNoise = new Perlin(); TerrainNoise.Seed = (int)Seed; ContinentNoise.Seed = (int)Seed + 2; CaveNoise.Seed = (int)Seed + 3; GravelNoise.Seed = (int)Seed + 4; TreeNoise.Seed = (int)Seed + 4; rand = new Random((int)Seed); TerrainNoise.Frequency = Frequency; TerrainNoise.NoiseQuality = NoiseQuality; TerrainNoise.OctaveCount = OctaveCount; TerrainNoise.Lacunarity = Lacunarity; TerrainNoise.Persistence = Persistance; ContinentNoise.Frequency = ContinentNoiseFrequency; ContinentNoise.NoiseQuality = NoiseQuality; ContinentNoise.OctaveCount = OctaveCount; ContinentNoise.Lacunarity = Lacunarity; ContinentNoise.Persistence = Persistance; CaveNoise.Frequency = Frequency; CaveNoise.NoiseQuality = NoiseQuality; CaveNoise.OctaveCount = OctaveCount + 2; CaveNoise.Lacunarity = Lacunarity; CaveNoise.Persistence = Persistance; GravelNoise.Frequency = Frequency; GravelNoise.NoiseQuality = NoiseQuality; GravelNoise.OctaveCount = OctaveCount; GravelNoise.Lacunarity = Lacunarity; GravelNoise.Persistence = Persistance; TreeNoise.Frequency = Frequency + 2; TreeNoise.NoiseQuality = NoiseQuality; TreeNoise.OctaveCount = OctaveCount; TreeNoise.Lacunarity = Lacunarity; TreeNoise.Persistence = Persistance; }
public FastTurbulence(IModule sourceModule) { if (sourceModule == null) throw new ArgumentNullException(); SourceModule = sourceModule; XDistort = new FastNoise(); YDistort = new FastNoise(); ZDistort = new FastNoise(); Frequency = 1.0; Power = 1.0; Roughness = 3; Seed = 0; }
private void button1_Click(object sender, EventArgs e) { panel2.Enabled = false; NoiseQuality quality = NoiseQuality.Standard; if (radiolow.Checked) quality = NoiseQuality.Low; if (radiostandard.Checked) quality = NoiseQuality.Standard; if (radiohigh.Checked) quality = NoiseQuality.High; int seed = 0; try { seed = Convert.ToInt32(textBox1.Text); } catch { seed = 0; textBox1.Text = "0"; } int octaves = 0; try { octaves = Convert.ToInt32(textBox2.Text); } catch { octaves = 6; textBox2.Text = "6"; } if (octaves > 30) octaves = 30; double frequency = 0; try { frequency = Convert.ToDouble(textBox3.Text); } catch { frequency = 0.05; textBox3.Text = "0.05"; } double lacunarity = 0; try { lacunarity = Convert.ToDouble(textBox4.Text); } catch { lacunarity = 2.0; textBox4.Text = "2.0"; } double persistence = 0; try { persistence = Convert.ToDouble(textBox5.Text); } catch { persistence = 0.5; textBox5.Text = "0.5"; } bool mapToSphere = false; IModule module; switch (listBox1.SelectedItem.ToString()) { case "Slow Perlin": module = new Perlin(); ((Perlin)module).Frequency = frequency; ((Perlin)module).NoiseQuality = quality; ((Perlin)module).Seed = seed; ((Perlin)module).OctaveCount = octaves; ((Perlin)module).Lacunarity = lacunarity; ((Perlin)module).Persistence = persistence; break; case "Fast Perlin": module = new FastNoise(); ((FastNoise)module).Frequency = frequency; ((FastNoise)module).NoiseQuality = quality; ((FastNoise)module).Seed = seed; ((FastNoise)module).OctaveCount = octaves; ((FastNoise)module).Lacunarity = lacunarity; ((FastNoise)module).Persistence = persistence; break; case "Slow Billow": module = new Billow(); ((Billow)module).Frequency = frequency; ((Billow)module).NoiseQuality = quality; ((Billow)module).Seed = seed; ((Billow)module).OctaveCount = octaves; ((Billow)module).Lacunarity = lacunarity; ((Billow)module).Persistence = persistence; break; case "Fast Billow": module = new FastBillow(); ((FastBillow)module).Frequency = frequency; ((FastBillow)module).NoiseQuality = quality; ((FastBillow)module).Seed = seed; ((FastBillow)module).OctaveCount = octaves; ((FastBillow)module).Lacunarity = lacunarity; ((FastBillow)module).Persistence = persistence; break; case "Slow Ridged Multifractal": module = new RidgedMultifractal(); ((RidgedMultifractal)module).Frequency = frequency; ((RidgedMultifractal)module).NoiseQuality = quality; ((RidgedMultifractal)module).Seed = seed; ((RidgedMultifractal)module).OctaveCount = octaves; ((RidgedMultifractal)module).Lacunarity = lacunarity; break; case "Fast Ridged Multifractal": module = new FastRidgedMultifractal(); ((FastRidgedMultifractal)module).Frequency = frequency; ((FastRidgedMultifractal)module).NoiseQuality = quality; ((FastRidgedMultifractal)module).Seed = seed; ((FastRidgedMultifractal)module).OctaveCount = octaves; ((FastRidgedMultifractal)module).Lacunarity = lacunarity; break; case "Slow Combined": Billow billow = new Billow(); billow.Frequency = frequency; billow.NoiseQuality = quality; billow.Seed = seed; billow.OctaveCount = octaves; billow.Lacunarity = lacunarity; billow.Persistence = persistence; ScaleBiasOutput scaledBillow = new ScaleBiasOutput(billow); scaledBillow.Bias = -0.75; scaledBillow.Scale = 0.125; RidgedMultifractal ridged = new RidgedMultifractal(); ridged.Frequency = frequency/2.0; ridged.NoiseQuality = quality; ridged.Seed = seed; ridged.OctaveCount = octaves; ridged.Lacunarity = lacunarity; Perlin perlin = new Perlin(); perlin.Frequency = frequency/10.0; perlin.NoiseQuality = quality; perlin.Seed = seed; perlin.OctaveCount = octaves; perlin.Lacunarity = lacunarity; perlin.Persistence = persistence; Select selector = new Select(perlin, ridged, scaledBillow); selector.SetBounds(0, 1000); selector.EdgeFalloff = 0.5; module = selector; break; case "Fast Combined": FastBillow fastbillow = new FastBillow(); fastbillow.Frequency = frequency; fastbillow.NoiseQuality = quality; fastbillow.Seed = seed; fastbillow.OctaveCount = octaves; fastbillow.Lacunarity = lacunarity; fastbillow.Persistence = persistence; ScaleBiasOutput fastscaledBillow = new ScaleBiasOutput(fastbillow); fastscaledBillow.Bias = -0.75; fastscaledBillow.Scale = 0.125; FastRidgedMultifractal fastridged = new FastRidgedMultifractal(); fastridged.Frequency = frequency/2.0; fastridged.NoiseQuality = quality; fastridged.Seed = seed; fastridged.OctaveCount = octaves; fastridged.Lacunarity = lacunarity; FastNoise fastperlin = new FastNoise(); fastperlin.Frequency = frequency/10.0; fastperlin.NoiseQuality = quality; fastperlin.Seed = seed; fastperlin.OctaveCount = octaves; fastperlin.Lacunarity = lacunarity; fastperlin.Persistence = persistence; Select fastselector = new Select(fastperlin, fastridged, fastscaledBillow); fastselector.SetBounds(0, 1000); fastselector.EdgeFalloff = 0.5; module = fastselector; break; case "Voronoi": module = new Voronoi(); ((Voronoi)module).Frequency = frequency; break; case "Slow Planet": mapToSphere = true; Perlin slowPlanetContinents = new Perlin(); slowPlanetContinents.Frequency = 1.5; Billow slowPlanetLowlands = new Billow(); slowPlanetLowlands.Frequency = 4; LibNoise.Modifiers.ScaleBiasOutput slowPlanetLowlandsScaled = new ScaleBiasOutput(slowPlanetLowlands); slowPlanetLowlandsScaled.Scale = 0.2; slowPlanetLowlandsScaled.Bias = 0.5; RidgedMultifractal slowPlanetMountainsBase = new RidgedMultifractal(); slowPlanetMountainsBase.Frequency = 4; ScaleBiasOutput slowPlanetMountainsScaled = new ScaleBiasOutput(slowPlanetMountainsBase); slowPlanetMountainsScaled.Scale = 0.4; slowPlanetMountainsScaled.Bias = 0.85; FastTurbulence slowPlanetMountains = new FastTurbulence(slowPlanetMountainsScaled); slowPlanetMountains.Power = 0.1; slowPlanetMountains.Frequency = 50; Perlin slowPlanetLandFilter = new Perlin(); slowPlanetLandFilter.Frequency = 6; Select slowPlanetLand = new Select(slowPlanetLandFilter, slowPlanetLowlandsScaled, slowPlanetMountains); slowPlanetLand.SetBounds(0, 1000); slowPlanetLand.EdgeFalloff = 0.5; Billow slowPlanetOceanBase = new Billow(); slowPlanetOceanBase.Frequency = 15; ScaleOutput slowPlanetOcean = new ScaleOutput(slowPlanetOceanBase, 0.1); Select slowPlanetFinal = new Select(slowPlanetContinents, slowPlanetOcean, slowPlanetLand); slowPlanetFinal.SetBounds(0, 1000); slowPlanetFinal.EdgeFalloff = 0.5; module = slowPlanetFinal; break; case "Fast Planet": mapToSphere = true; FastNoise fastPlanetContinents = new FastNoise(seed); fastPlanetContinents.Frequency = 1.5; FastBillow fastPlanetLowlands = new FastBillow(); fastPlanetLowlands.Frequency = 4; LibNoise.Modifiers.ScaleBiasOutput fastPlanetLowlandsScaled = new ScaleBiasOutput(fastPlanetLowlands); fastPlanetLowlandsScaled.Scale = 0.2; fastPlanetLowlandsScaled.Bias = 0.5; FastRidgedMultifractal fastPlanetMountainsBase = new FastRidgedMultifractal(seed); fastPlanetMountainsBase.Frequency = 4; ScaleBiasOutput fastPlanetMountainsScaled = new ScaleBiasOutput(fastPlanetMountainsBase); fastPlanetMountainsScaled.Scale = 0.4; fastPlanetMountainsScaled.Bias = 0.85; FastTurbulence fastPlanetMountains = new FastTurbulence(fastPlanetMountainsScaled); fastPlanetMountains.Power = 0.1; fastPlanetMountains.Frequency = 50; FastNoise fastPlanetLandFilter = new FastNoise(seed+1); fastPlanetLandFilter.Frequency = 6; Select fastPlanetLand = new Select(fastPlanetLandFilter, fastPlanetLowlandsScaled, fastPlanetMountains); fastPlanetLand.SetBounds(0, 1000); fastPlanetLand.EdgeFalloff = 0.5; FastBillow fastPlanetOceanBase = new FastBillow(seed); fastPlanetOceanBase.Frequency = 15; ScaleOutput fastPlanetOcean = new ScaleOutput(fastPlanetOceanBase, 0.1); Select fastPlanetFinal = new Select(fastPlanetContinents, fastPlanetOcean, fastPlanetLand); fastPlanetFinal.SetBounds(0, 1000); fastPlanetFinal.EdgeFalloff = 0.5; module = fastPlanetFinal; break; default: module = new Constant(1.0); break; } System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch(); stopWatch.Start(); LibNoise.Models.Sphere sphere = new LibNoise.Models.Sphere(module); for (int x = 0; x < pictureBox1.ClientSize.Width - 1; x++) for (int y = 0; y < pictureBox1.ClientSize.Height - 1; y++) { double value; if(mapToSphere) { int offsetX = -(x-512); int offsetY = -(y-512); double longitude = offsetY/5.6888888888; if(longitude > 90.0) longitude = 90.0; if(longitude < -90.0) longitude = -90.0; double latitude = offsetX/2.844444444; if(latitude > 180.0) latitude = 180.0; if(latitude < -190.0) latitude = -180.0; value = sphere.GetValue(longitude, latitude); } else value = (module.GetValue(x, y, 10) + 1) / 2.0; if (mapToSphere) { if (value < 0) value = 0; if (value > 1.0) value = 1.0; int index = (int)(value * earthLookupTable.Length); if (index >= earthLookupTable.Length) index = earthLookupTable.Length - 1; colors[x, y] = earthLookupTable[index]; } else { if (value < 0) value = 0; if (value > 1.0) value = 1.0; byte intensity = (byte)(value * 255.0); colors[x, y] = Color.FromArgb(255, intensity, intensity, intensity); } } stopWatch.Stop(); label2.Text = "Generation time for a 1024x1024 image, not including rendering: " + stopWatch.Elapsed.TotalMilliseconds + " ms"; for (int x = 0; x < pictureBox1.ClientSize.Width - 1; x++) for (int y = 0; y < pictureBox1.ClientSize.Height - 1; y++) bitmap.SetPixel(x, y, colors[x, y]); pictureBox1.Image = bitmap; panel2.Enabled = true; }
public void GetChunk(int x, int y, int z, ushort[] chunk) { if (!started) { Init(); started = true; } bool addCaves = (bool)m.GetOption("DefaultGenCaves"); bool addCaveLava = (bool)m.GetOption("DefaultGenLavaCaves"); int ChunkSize = m.GetChunkSize(); x *= ChunkSize; y *= ChunkSize; z *= ChunkSize; int chunksize = ChunkSize; var noise = new LibNoise.FastNoise(); noise.Frequency = 0.01; for (int xx = 0; xx < chunksize; xx++) { for (int yy = 0; yy < chunksize; yy++) { int currentHeight = (byte)((finalTerrain.GetValue((xx + x) / 100.0, 0, (yy + y) / 100.0) * 60) + 64); int ymax = currentHeight; int biome = (int)(BiomeSelect.GetValue((x + xx) / 100.0, 0, (y + yy) / 100.0) * 2); //MD * 2 int toplayer = BLOCK_DIRT; if (biome == 0) { toplayer = BLOCK_DIRT; } if (biome == 1) { toplayer = BLOCK_SAND; } if (biome == 2) { toplayer = BLOCK_DIRT; } if (biome == 3) { toplayer = BLOCK_DIRT; } if (biome == 4) { toplayer = BLOCK_DIRT; } if (biome == 5) { toplayer = BLOCK_CLAY; } int stoneHeight = (int)currentHeight - ((64 - (currentHeight % 64)) / 8) + 1; if (ymax < seaLevel) { ymax = seaLevel; } ymax++; if (ymax > z + chunksize - 1) { ymax = z + chunksize - 1; } for (int bY = z; bY <= ymax; bY++) { int curBlock = 0; // Place bedrock if (bY == 0) { curBlock = BLOCK_BEDROCK; } else if (bY < currentHeight) { if (bY < stoneHeight) { curBlock = BLOCK_STONE; // Add caves if (addCaves) { if (caveNoise.GetValue((x + xx) / 4.0, (bY) / 1.5, (y + yy) / 4.0) > cavestreshold) { if (bY < 10 && addCaveLava) { curBlock = BLOCK_LAVA; } else { curBlock = BLOCK_AIR; } } } } else { curBlock = toplayer; } } else if ((currentHeight + 1) == bY && bY > seaLevel && biome == 3) { curBlock = BLOCK_SNOW; continue; } else if ((currentHeight + 1) == bY && bY > seaLevel + 1) { if (biome == 1 || biome == 0) { continue; } double f = flowers.GetValue(x + xx / 10.0, 0, y + yy / 10.0); if (f < -0.999) { curBlock = BLOCK_RED_ROSE; } else if (f > 0.999) { curBlock = BLOCK_YELLOW_FLOWER; } else if (f < 0.001 && f > -0.001) { curBlock = BLOCK_PUMPKIN; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { curBlock = BLOCK_SAND; // FF } else if (bY < seaLevel - 1) { curBlock = BLOCK_GRAVEL; // FF } else if (toplayer == BLOCK_DIRT) { curBlock = BLOCK_GRASS; } else { curBlock = toplayer; // FF } } else { if (bY <= seaLevel) { curBlock = BLOCK_WATER; // FF } else { curBlock = BLOCK_AIR; // FF } if (bY == seaLevel && biome == 3) { curBlock = BLOCK_ICE; } } chunk[m.Index3d(xx, yy, bY - z, chunksize, chunksize)] = (ushort)curBlock; } } } }
public void GetChunk(int x, int y, int z, ushort[] chunk) { if (!started) { Init(); started = true; } bool addCaves = (bool)m.GetOption("DefaultGenCaves"); bool addCaveLava = (bool)m.GetOption("DefaultGenLavaCaves"); int ChunkSize=m.GetChunkSize(); x *= ChunkSize; y *= ChunkSize; z *= ChunkSize; int chunksize = ChunkSize; var noise = new LibNoise.FastNoise(); noise.Frequency = 0.01; for (int xx = 0; xx < chunksize; xx++) { for (int yy = 0; yy < chunksize; yy++) { int currentHeight = (byte)((finalTerrain.GetValue((xx + x) / 100.0, 0, (yy + y) / 100.0) * 60) + 64); int ymax = currentHeight; int biome = (int)(BiomeSelect.GetValue((x + xx) / 100.0, 0, (y + yy) / 100.0) * 2); //MD * 2 int toplayer = BLOCK_DIRT; if (biome == 0) { toplayer = BLOCK_DIRT; } if (biome == 1) { toplayer = BLOCK_SAND; } if (biome == 2) { toplayer = BLOCK_DIRT; } if (biome == 3) { toplayer = BLOCK_DIRT; } if (biome == 4) { toplayer = BLOCK_DIRT; } if (biome == 5) { toplayer = BLOCK_CLAY; } int stoneHeight = (int)currentHeight - ((64 - (currentHeight % 64)) / 8) + 1; if (ymax < seaLevel) { ymax = seaLevel; } ymax++; if (ymax > z + chunksize - 1) { ymax = z + chunksize - 1; } for (int bY = z; bY <= ymax; bY++) { int curBlock = 0; // Place bedrock if (bY == 0) { curBlock = BLOCK_BEDROCK; } else if (bY < currentHeight) { if (bY < stoneHeight) { curBlock = BLOCK_STONE; // Add caves if (addCaves) { if (caveNoise.GetValue((x + xx) / 4.0, (bY) / 1.5, (y + yy) / 4.0) > cavestreshold) { if (bY < 10 && addCaveLava) { curBlock = BLOCK_LAVA; } else { curBlock = BLOCK_AIR; } } } } else { curBlock = toplayer; } } else if ((currentHeight + 1) == bY && bY > seaLevel && biome == 3) { curBlock = BLOCK_SNOW; continue; } else if ((currentHeight + 1) == bY && bY > seaLevel + 1) { if (biome == 1 || biome == 0) { continue; } double f = flowers.GetValue(x + xx / 10.0, 0, y + yy / 10.0); if (f < -0.999) { curBlock = BLOCK_RED_ROSE; } else if (f > 0.999) { curBlock = BLOCK_YELLOW_FLOWER; } else if (f < 0.001 && f > -0.001) { curBlock = BLOCK_PUMPKIN; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { curBlock = BLOCK_SAND; // FF } else if (bY < seaLevel - 1) { curBlock = BLOCK_GRAVEL; // FF } else if (toplayer == BLOCK_DIRT) { curBlock = BLOCK_GRASS; } else { curBlock = toplayer; // FF } } else { if (bY <= seaLevel) { curBlock = BLOCK_WATER; // FF } else { curBlock = BLOCK_AIR; // FF } if (bY == seaLevel && biome == 3) { curBlock = BLOCK_ICE; } } chunk[m.Index3d(xx, yy, bY - z, chunksize, chunksize)] = (ushort)curBlock; } } } }
public static IModule GetEarthModule(int seed, int resolution) { if(true) { double factor = 1.0/resolution; FastNoise Continentsprescale = new FastNoise(seed); Continentsprescale.Frequency = 1*factor; ScaleBiasOutput Continents = new ScaleBiasOutput(Continentsprescale); Continents.Scale = .65; Continents.Bias = .35; FastBillow LowLands = new FastBillow(seed); LowLands.Frequency = .4*factor; ScaleBiasOutput LowLandsScaled = new ScaleBiasOutput(LowLands); LowLandsScaled.Scale = 0.1; LowLandsScaled.Bias = 0.5; FastRidgedMultifractal Mountains = new FastRidgedMultifractal(seed); Mountains.Frequency = 1*factor; Mountains.Lacunarity = 2; Mountains.OctaveCount = 16; ScaleBiasOutput MountainsScaledpreturb = new ScaleBiasOutput(Mountains); MountainsScaledpreturb.Scale = 0.4; MountainsScaledpreturb.Bias = 0.85; //FastTurbulence MountainsFinal = new FastTurbulence(MountainsScaled) FastTurbulence MountainsScaled = new FastTurbulence(MountainsScaledpreturb); MountainsScaled.Frequency = 50*factor; MountainsScaled.Power = 0.1; FastNoise LandFilterprescale = new FastNoise(seed+1); LandFilterprescale.Frequency = .6*factor; ScaleBiasOutput LandFilter = new ScaleBiasOutput(LandFilterprescale); LandFilter.Bias = 0; Select LandFinal1 = new Select(LandFilter, LowLandsScaled, MountainsScaled); LandFinal1.SetBounds(0, 100); LandFinal1.EdgeFalloff = (.5); //AbsoluteOutput LandFinal = new AbsoluteOutput(LandFinal1); var LandFinal = new ScaleBiasOutput(LandFinal1); FastBillow Ocean = new FastBillow(seed); Ocean.Frequency = .5*factor; ScaleBiasOutput OceanScaled = new ScaleBiasOutput(Ocean); OceanScaled.Scale = 0.1; OceanScaled.Bias = 0.1; Select Final = new Select(Continents, new Constant(0), new Constant(1)); Final.SetBounds(0, 100); //Final.EdgeFalloff=(0.5); Select Finalx = new Select(Continents, LandFinal, OceanScaled); Finalx.SetBounds(0, 100); //Finalx.EdgeFalloff=(0.5); Select Final2 = new Select(LandFinal1, new Constant(.5), new Constant(.3)); Final2.SetBounds(0, 100); //Final2.EdgeFalloff = .5; Select Final3 = new Select(Finalx, Final, Final2); Final3.SetBounds(0, 100); var outpoot = /*new AbsoluteOutput*/new VoronoiRelaxed() { Frequency = 4*factor,RelaxationFactor=1 ,Seed=seed}; var fin = new Select(Continentsprescale, new Constant(-1), outpoot); fin.SetBounds(0, 100); //Final3.EdgeFalloff = .5; //fin.EdgeFalloff=0.05; var zones = /*new VoronoiLarge(new VoronoiLarge(*/new VoronoiLarge(fin) { Frequency = factor*20, RelaxationFactor = .75 };//){Frequency=factor*8,RelaxationFactor=0}){Frequency=factor*16,RelaxationFactor=0}; var fin2 = zones; return fin2; } else { double factor = 1.0/resolution; FastNoise fastPlanetContinents = new FastNoise(seed); fastPlanetContinents.Frequency = 1.5*factor; FastBillow fastPlanetLowlands = new FastBillow(); fastPlanetLowlands.Frequency = 4*factor; LibNoise.Modifiers.ScaleBiasOutput fastPlanetLowlandsScaled = new ScaleBiasOutput(fastPlanetLowlands); fastPlanetLowlandsScaled.Scale = 0.2; fastPlanetLowlandsScaled.Bias = 0.5; FastRidgedMultifractal fastPlanetMountainsBase = new FastRidgedMultifractal(seed); fastPlanetMountainsBase.Frequency = 4*factor; ScaleBiasOutput fastPlanetMountainsScaled = new ScaleBiasOutput(fastPlanetMountainsBase); fastPlanetMountainsScaled.Scale = 0.4; fastPlanetMountainsScaled.Bias = 0.85; FastTurbulence fastPlanetMountains = new FastTurbulence(fastPlanetMountainsScaled); fastPlanetMountains.Power = 0.1; fastPlanetMountains.Frequency = 50*factor; FastNoise fastPlanetLandFilter = new FastNoise(seed+1); fastPlanetLandFilter.Frequency = 6*factor; Select fastPlanetLand = new Select(fastPlanetLandFilter, fastPlanetLowlandsScaled, fastPlanetMountains); fastPlanetLand.SetBounds(0, 1000); fastPlanetLand.EdgeFalloff = 0.5; FastBillow fastPlanetOceanBase = new FastBillow(seed); fastPlanetOceanBase.Frequency = 15*factor; ScaleOutput fastPlanetOcean = new ScaleOutput(fastPlanetOceanBase, 0.1); Select fastPlanetFinal = new Select(fastPlanetContinents, fastPlanetOcean, fastPlanetLand); fastPlanetFinal.SetBounds(0, 1000); fastPlanetFinal.EdgeFalloff = 0.5; return fastPlanetFinal; } }
public void Initialize(MaterialMap matmap, long seed) { mMap = matmap; this.Seed = seed; Frequency = 0.03; ContinentNoiseFrequency = Frequency / 2.0; Lacunarity = 0.01; Persistance = 0.01; OctaveCount = 1; Seed = seed; TerrainNoise = new FastNoise(); ContinentNoise = new FastNoise(); CaveNoise = new Perlin(); GravelNoise = new Perlin(); TreeNoise = new Perlin(); TerrainNoise.Seed = (int)Seed; ContinentNoise.Seed = (int)Seed + 2; CaveNoise.Seed = (int)Seed + 3; GravelNoise.Seed = (int)Seed + 4; TreeNoise.Seed = (int)Seed + 4; rand = new Random((int)Seed); TerrainNoise.Frequency = Frequency; TerrainNoise.NoiseQuality = NoiseQuality; TerrainNoise.OctaveCount = OctaveCount; TerrainNoise.Lacunarity = Lacunarity; TerrainNoise.Persistence = Persistance; ContinentNoise.Frequency = ContinentNoiseFrequency; ContinentNoise.NoiseQuality = NoiseQuality; ContinentNoise.OctaveCount = OctaveCount; ContinentNoise.Lacunarity = Lacunarity; ContinentNoise.Persistence = Persistance; CaveNoise.Frequency = Frequency; CaveNoise.NoiseQuality = NoiseQuality; CaveNoise.OctaveCount = OctaveCount + 2; CaveNoise.Lacunarity = Lacunarity; CaveNoise.Persistence = Persistance; GravelNoise.Frequency = Frequency; GravelNoise.NoiseQuality = NoiseQuality; GravelNoise.OctaveCount = OctaveCount; GravelNoise.Lacunarity = Lacunarity; GravelNoise.Persistence = Persistance; TreeNoise.Frequency = Frequency + 2; TreeNoise.NoiseQuality = NoiseQuality; TreeNoise.OctaveCount = OctaveCount; TreeNoise.Lacunarity = Lacunarity; TreeNoise.Persistence = Persistance; }
/// <summary> /// 产生大范围的地图 /// </summary> public void Generate() { if (NoiseModule == null || NoiseModule.Seed != MapSeed) { NoiseModule = new LibNoise.FastNoise(MapSeed); } NoiseModule.OctaveCount = 5; NoiseModule.Frequency = 0.2; NoiseModule.Lacunarity = 2.0; NoiseModule.Persistence = 0.3; int DataW, DataH; DataW = ImageW / SampleDis; DataH = ImageH / SampleDis; if (ImageW % SampleDis != 0) DataW++; if (ImageH % SampleDis != 0) DataH++; float[,] NoiseData = new float[DataW, DataH]; float max = float.MinValue; float min = float.MaxValue; for (int x = 0; x < DataW; ++x) { for (int y = 0; y < DataH; ++y) { NoiseData[x, y] = (float)(NoiseModule.GetValue(x, y, 0)); if (NoiseData[x, y] > max) max = NoiseData[x, y]; if (NoiseData[x, y] < min) min = NoiseData[x, y]; } } float value; int _x, _y; Color clr = new Color(1.0f, 1.0f, 1.0f, 1.0f); for (int x = 0; x < ImageW; ++x) { for (int y = 0; y < ImageH; ++y) { _x = x / SampleDis; _y = y / SampleDis; value = (NoiseData[_x, _y] - min) / (max - min); if (value < 0.3f) value = 0.4f; else if (value < 0.6f) value = 0.6f; else if (value < 0.8f) value = 0.8f; else value = 1.0f; if (value == 0.4f) { clr.r = 0.0f; clr.g = 0.8f; clr.b = 0.0f; } else { clr.r = value; clr.g = value; clr.b = value; } ImageTexture.SetPixel(x, y, clr); } } ImageTexture.Apply(); }
private void Setup() { Frequency = 0.1; ContinentNoiseFrequency = 0.02; Lacunarity = 2; // 0.05 Persistance = 0.5; OctaveCount = 3; mContinentNoiseOctaves = 6; TerrainNoise = new FastNoise(); ContinentNoise = new Perlin(); CaveNoise = new Perlin(); TerrainNoise.Seed = (int)Seed; ContinentNoise.Seed = (int)Seed + 2; CaveNoise.Seed = (int)Seed + 3; TerrainNoise.Frequency = Frequency; TerrainNoise.NoiseQuality = NoiseQuality; TerrainNoise.OctaveCount = OctaveCount; TerrainNoise.Lacunarity = Lacunarity; ContinentNoise.Frequency = ContinentNoiseFrequency; ContinentNoise.NoiseQuality = NoiseQuality; ContinentNoise.OctaveCount = mContinentNoiseOctaves; ContinentNoise.Lacunarity = Lacunarity; ContinentNoise.Persistence = Persistance; CaveNoise.Frequency = Frequency; CaveNoise.NoiseQuality = NoiseQuality; CaveNoise.OctaveCount = OctaveCount + 2; CaveNoise.Lacunarity = Lacunarity; CaveNoise.Persistence = Persistance; }
public byte[, ,] GetChunk(int x, int y, int z) { byte[, ,] chunk = new byte[ChunkSize, ChunkSize, ChunkSize]; x *= ChunkSize; y *= ChunkSize; z *= ChunkSize; int chunksize = ChunkSize; var noise = new LibNoise.FastNoise(); noise.Frequency = 0.01; for (int xx = 0; xx < chunksize; xx++) { for (int yy = 0; yy < chunksize; yy++) { /* * var v = noise.GetValue(x + xx, y + yy, 0); * //if (v < min) { min = v; } * int height = (int)(((v + 1) * 0.5) * 64) + 5; * //if (height < 0) * { * // Console.Beep(); * } */ int currentHeight = (byte)((finalTerrain.GetValue((xx + x) / 100.0, 0, (yy + y) / 100.0) * 60) + 64); int ymax = currentHeight; /*for (int zz = 0; zz < chunksize; zz++) * { * if (z + zz <= currentHeight) { chunk[xx, yy, zz] = 1; } * }*/ int biome = (int)(BiomeSelect.GetValue((x + xx) / 100.0, 0, (y + yy) / 100.0) * 2); //MD * 2 byte toplayer = BLOCK_DIRT; if (biome == 0) { toplayer = BLOCK_DIRT; } if (biome == 1) { toplayer = BLOCK_SAND; } if (biome == 2) { toplayer = BLOCK_DIRT; } if (biome == 3) { toplayer = BLOCK_DIRT; } if (biome == 4) { toplayer = BLOCK_DIRT; } if (biome == 5) { toplayer = BLOCK_CLAY; } //biomecoun[biome]++; int stoneHeight = (int)currentHeight - ((64 - (currentHeight % 64)) / 8) + 1; int bYbX = ((y << 7) + (x << 11)); if (ymax < seaLevel) { ymax = seaLevel; } ymax++; if (ymax > z + chunksize - 1) //md { ymax = z + chunksize - 1; } //for (int bY = 0; bY <= ymax; bY++) for (int bY = z; bY <= ymax; bY++) { //curBlock = &(chunk->blocks[bYbX++]); int curBlock = 0; // Place bedrock if (bY == 0) { curBlock = BLOCK_BEDROCK; continue; } if (bY < currentHeight) { if (bY < stoneHeight) { curBlock = BLOCK_STONE; // Add caves if (addCaves) { //cave.AddCaves(curBlock, x + xx, bY, y + yy); if (caveNoise.GetValue((x + xx) / 4.0, (bY) / 1.5, (y + yy) / 4.0) > cavestreshold) { if (bY < 10 && addCaveLava) { curBlock = BLOCK_LAVA; } else { curBlock = BLOCK_AIR; } } } } else { curBlock = toplayer; } } else if ((currentHeight + 1) == bY && bY > seaLevel && biome == 3) { curBlock = BLOCK_SNOW; continue; } else if ((currentHeight + 1) == bY && bY > seaLevel + 1) { if (biome == 1 || biome == 0) { continue; } double f = flowers.GetValue(x + xx / 10.0, 0, y + yy / 10.0); if (f < -0.999) { curBlock = BLOCK_RED_ROSE; } else if (f > 0.999) { curBlock = BLOCK_YELLOW_FLOWER; } else if (f < 0.001 && f > -0.001) { curBlock = BLOCK_PUMPKIN; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { curBlock = BLOCK_SAND; // FF } else if (bY < seaLevel - 1) { curBlock = BLOCK_GRAVEL; // FF } else if (toplayer == BLOCK_DIRT) { curBlock = BLOCK_GRASS; } else { curBlock = toplayer; // FF } } else { if (bY <= seaLevel) { curBlock = BLOCK_WATER; // FF } else { curBlock = BLOCK_AIR; // FF } if (bY == seaLevel && biome == 3) { curBlock = BLOCK_ICE; } } chunk[xx, yy, bY - z] = (byte)curBlock; } } } return(chunk); }
public void BuildWorld(int x, int y, int z, World world) { if (!started) { Init(); started = true; } //for (var xx = 0; xx < ChunkManager.CHUNK_SIZE; xx++) // for (var zz = 0; zz < ChunkManager.CHUNK_SIZE; zz++) // chunk[xx, 0, zz] = 0xffffff; //chunk[0, 1, 0] = 0xffffff; //chunk[0, 1, 1] = 0xffffff; //chunk[0, 1, 2] = 0xffffff; //chunk[0, 1, 3] = 0xffffff; ////chunk[1, 2, 1] = 0xffffff; ////chunk[1, 2, 2] = 0xffffff; ////chunk[2, 2, 2] = 0xffffff; ////chunk[1, 0, 1] = 0xffffff; ////chunk[1, 0, 2] = 0xffffff; ////chunk[2, 0, 2] = 0xffffff; //return; bool addCaves = false; // (bool)m.GetOption("DefaultGenCaves"); bool addCaveLava = false; // (bool)m.GetOption("DefaultGenLavaCaves"); int ChunkSize = world.Size;// m.GetChunkSize(); int chunksize = world.Size; var noise = new FastNoise(); noise.Frequency = 0.01; for (int xx = 0; xx < chunksize; xx++) { for (int yy = 0; yy < chunksize; yy++) { int currentHeight = (byte)((finalTerrain.GetValue((xx + x) / 100.0f, 0, (yy + y) / 100.0f) * 60) + 64); int ymax = currentHeight; int biome = (int)(BiomeSelect.GetValue((x + xx) / 100.0f, 0, (y + yy) / 100.0f) * 2); //MD * 2 MapCell toplayer = MapCell.DIRT; if (biome == 0) { toplayer = MapCell.DIRT; } if (biome == 1) { toplayer = MapCell.SAND; } if (biome == 2) { toplayer = MapCell.DIRT; } if (biome == 3) { toplayer = MapCell.DIRT; } if (biome == 4) { toplayer = MapCell.DIRT; } if (biome == 5) { toplayer = MapCell.CLAY; } int stoneHeight = (int)currentHeight - ((64 - (currentHeight % 64)) / 8) + 1; if (ymax < seaLevel) { ymax = seaLevel; } ymax++; if (ymax > z + chunksize - 1) { ymax = z + chunksize - 1; } for (int bY = z; bY <= ymax; bY++) { MapCell curBlock = MapCell.AIR; // Place bedrock if (bY == 0) { curBlock = MapCell.BEDROCK; } else if (bY < currentHeight) { if (bY < stoneHeight) { curBlock = MapCell.STONE; // Add caves if (addCaves) { if (caveNoise.GetValue((x + xx) / 4.0f, (bY) / 1.5f, (y + yy) / 4.0f) > cavestreshold) { if (bY < 10 && addCaveLava) { curBlock = MapCell.LAVA; } else { curBlock = MapCell.AIR; } } } } else { curBlock = toplayer; } } else if ((currentHeight + 1) == bY && bY > seaLevel && biome == 3) { curBlock = MapCell.SNOW; continue; } else if ((currentHeight + 1) == bY && bY > seaLevel + 1) { if (biome == 1 || biome == 0) { continue; } double f = flowers.GetValue(x + xx / 10.0f, 0, y + yy / 10.0f); if (f < -0.999) { curBlock = MapCell.REDROSE; } else if (f > 0.999) { curBlock = MapCell.YELLOWFLOWER; } else if (f < 0.001 && f > -0.001) { curBlock = MapCell.PUMPKIN; } } else if (currentHeight == bY) { if (bY == seaLevel || bY == seaLevel - 1 || bY == seaLevel - 2) { curBlock = MapCell.SAND; // FF } else if (bY < seaLevel - 1) { curBlock = MapCell.GRAVEL; // FF } else if (toplayer.TypeID == MapCell.DIRT.TypeID) { curBlock = MapCell.GRASS; } else { curBlock = toplayer; // FF } } else { if (bY <= seaLevel) { curBlock = MapCell.WATER; // FF } else { curBlock = MapCell.AIR; // FF } if (bY == seaLevel && biome == 3) { curBlock = MapCell.ICE; } } //var idx = xx + chunksize * ((yy) + chunksize * (bY - z)); world[xx, yy, bY - z] = curBlock; //chunk[idx] = curBlock; //chunk[m.Index3d(xx, yy, bY - z, chunksize, chunksize)] = curBlock; } } } }
/// <summary> /// 生成地图信息 /// </summary> public void Generate() { if (NoiseModule == null || NoiseModule.Seed != WorldSeed) { NoiseModule = new LibNoise.FastNoise(WorldSeed); } CubeTerrain WorldConfig = CubeTerrain.Instance; NoiseModule.OctaveCount = Global.OctaveCount; NoiseModule.Frequency = Global.Frequency; NoiseModule.Lacunarity = Global.Lacunarity; NoiseModule.Persistence = Global.Persistence; int MinHeight = Global.MinHeight; int MaxHeight = Global.MaxHeight; int SampleDis = Global.SampleDis; int DataW, DataH; DataW = NoiseDataSize / SampleDis; DataH = NoiseDataSize / SampleDis; if (NoiseDataSize % SampleDis != 0) DataW++; if (NoiseDataSize % SampleDis != 0) DataH++; float[,] NoiseData = new float[DataW, DataW]; float max = float.MinValue; float min = float.MaxValue; for (int x = 0; x < DataW; ++x) { for (int y = 0; y < DataW; ++y) { NoiseData[x, y] = (float)(NoiseModule.GetValue(x, y, 0)); if (NoiseData[x, y] > max) max = NoiseData[x, y]; if (NoiseData[x, y] < min) min = NoiseData[x, y]; } } int height; float value; int _x, _y; for (int x = 0; x < NoiseDataSize; ++x) { for (int y = 0; y < NoiseDataSize; ++y) { _x = x / SampleDis; _y = y / SampleDis; value = (NoiseData[_x, _y] - min) / (max - min); value = (int)(value * 5.0f) / 5.0f; height = MinHeight + (int)((MaxHeight - MinHeight) * value); for (int z = 0; z < height; ++z) { // U3D Y轴向上 VoxelsData[x, z, y] = VoxelType.Dirt; } } } }