public TerrainModule(int seed) { _seed = seed; RidgedMultifractal mountains = new RidgedMultifractal(); mountains.Seed = seed; mountains.Frequency = 0.5; Billow hills = new Billow(); hills.Seed = seed; hills.Frequency = 2; ScaleBiasOutput scaleHill = new ScaleBiasOutput(hills); scaleHill.Scale = 0.04; scaleHill.Bias = 0; ScaleBiasOutput scaleMountain = new ScaleBiasOutput(mountains); scaleMountain.Scale = 1.5; Perlin selectorControl = new Perlin(); selectorControl.Seed = seed; selectorControl.Frequency = 0.10; selectorControl.Persistence = 0.25; Select selector = new Select(selectorControl, scaleMountain, scaleHill); selector.SetBounds(0, 1000); selector.EdgeFalloff = 0.5; _module = selector; }
public virtual void SetNoiseGenerator(LibNoise.RidgedMultifractal Generator) { Generator.Seed = Random.Range(int.MinValue, int.MaxValue); Generator.OctaveCount = 5; Generator.NoiseQuality = LibNoise.NoiseQuality.High; Generator.Lacunarity = 1.4f; Generator.Frequency = 6f; }
private static float[] GeneratePlanetHeightmapData(PlanetArchetypes.Archetype blueprint) { float[] height = new float[textureSize * textureSize]; LibNoise.RidgedMultifractal Generator = new LibNoise.RidgedMultifractal(); blueprint.SetNoiseGenerator(Generator); float correctMin = float.MaxValue; float correctMax = float.MinValue; float currValue; for (int y = 0; y < textureSize; y++) { for (int x = 0; x < textureSize; x++) { currValue = (float)Generator.GetValue((float)x / textureSize, (float)y / textureSize, 1); if (currValue < correctMin) { correctMin = currValue; } if (currValue > correctMax) { correctMax = currValue; } height[x + y * textureSize] = currValue; } } float oldValue; for (int y = 0; y < textureSize; y++) { for (int x = 0; x < textureSize; x++) { float mult = (float)x / textureSize; oldValue = height[x + y * textureSize]; currValue = (float)Generator.GetValue(((float)x / textureSize) + 1, (float)y / textureSize, 1); float yMult = (float)y / textureSize; yMult = Mathf.Clamp01(11.11f * Mathf.Pow(yMult, 2) - 11.11f * yMult + 1); height[x + y * textureSize] = Mathf.Lerp(currValue, oldValue, mult); height[x + y * textureSize] = Mathf.Lerp(height[x + y * textureSize], 0, yMult); } } for (int y = 0; y < textureSize; y++) { for (int x = 0; x < textureSize; x++) { height[x + y * textureSize] = (height[x + y * textureSize] - correctMin) / (correctMax - correctMin); } } return(height); }
public TerrainModule(int seed) { _seed = seed; Perlin perlin_mountains = new Perlin(); perlin_mountains.Seed = seed; perlin_mountains.Frequency = 0.5; perlin_mountains.NoiseQuality = NoiseQuality.High; //ScaleBiasOutput scalePerlinMountain = new ScaleBiasOutput(perlin_mountains); //scalePerlinMountain.Scale = 1; mountains = new RidgedMultifractal(); mountains.Seed = 0;// seed; mountains.Frequency = 0.5; mountains.Lacunarity = 2; mountains.NoiseQuality = NoiseQuality.High; //scaleMountain = new ScaleBiasOutput(mountains); //scaleMountain.Scale = 0.5; //Add blendMountains = new Add(perlin_mountains, scaleMountain); double scale = 2; //inputScaledMountains = new ScaleInput(perlin_mountains, scale, 1, scale); /*Billow hills = new Billow(); * hills.Seed = seed; * hills.Frequency = 2; * * ScaleBiasOutput scaleHill = new ScaleBiasOutput(hills); * scaleHill.Scale = 0.04; * scaleHill.Bias = 0;*/ //Perlin selectorControl = new Perlin(); //selectorControl.Seed = seed; //selectorControl.Frequency = 0.10; //selectorControl.Persistence = 0.25; //Select selector = new Select(selectorControl, scaleMountain, scaleHill); //selector.SetBounds(0, 1000); //selector.EdgeFalloff = 0.5; //scaleSelector = new ScaleOutput(inputScaledMountains, SmoothVoxelSettings.amplitude); _module = perlin_mountains;//new BiasOutput(scaleSelector, SmoothVoxelSettings.groundOffset); }
public RidgedMultifractalModifier(int seed, int octave, float freq, float lacun, bool addOrErode) { _generator = new RidgedMultifractal(); _generator.NoiseQuality = NoiseQuality.Standard; _seed = seed; _octave = octave; _frequency = freq; _lacunarity = lacun; AddOrErode = addOrErode; }
public GenStandard() { random = new Random(); perlin = new Perlin(); perlin.Frequency = 0.009; perlin.Persistence = 0.3; perlin.Seed = (int)( DateTime.Now.Ticks & 0xffffffff ); perlin2 = new Perlin(); perlin2.Frequency = 0.007; perlin2.Persistence = 0.6; perlin2.Lacunarity = 0.1; perlin2.Seed = perlin.Seed - 7; caves = new RidgedMultifractal(); caves.Frequency = 0.0089; caves.Seed = perlin2.Seed + 99; voronoi = new Voronoi(); voronoi.Frequency = 0.008; voronoi.Seed = perlin.Seed + 2; desertSelector = new Perlin(); desertSelector.Frequency = 0.01; desertSelector.Persistence = 0.4; desertSelector.Lacunarity = 0.14; desertSelector.Seed = perlin.Seed + 245; mountains = new RidgedMultifractal(); mountains.Frequency = 0.021; mountains.NoiseQuality = NoiseQuality.Low; mountains.Seed = perlin.Seed + 41; mountains2 = new Perlin(); mountains2.Frequency = 0.025; mountains2.NoiseQuality = NoiseQuality.Low; mountains2.Seed = perlin.Seed + 41; }
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 override void SetNoiseGenerator(LibNoise.RidgedMultifractal Generator) { base.SetNoiseGenerator(Generator); Generator.Lacunarity = 2f; }
public override void SetNoiseGenerator(LibNoise.RidgedMultifractal Generator) { base.SetNoiseGenerator(Generator); Generator.Lacunarity = 1.8f; Generator.Frequency = 4f; }
private void InitGenerators() { //prepare noise generators perlinLeft = new Perlin() { Frequency = RiverShapeFrequency, NoiseQuality = NoiseQuality.Standard, Seed = Seed + 1, OctaveCount = 6, Lacunarity = RiverShapeLacunarity, Persistence = RiverShapePersistence }; perlinRight = new Perlin() { Frequency = RiverShapeFrequency, NoiseQuality = NoiseQuality.Standard, Seed = Seed + 2, OctaveCount = 6, Lacunarity = RiverShapeLacunarity, Persistence = RiverShapePersistence }; perlinLeftWidth = new Perlin() { Frequency = RiverWidthFrequency, NoiseQuality = NoiseQuality.Standard, Seed = Seed + 3, OctaveCount = 6, Lacunarity = RiverWidthLacunarity, Persistence = RiverWidthPersistence }; perlinRightWidth = new Perlin() { Frequency = RiverWidthFrequency, NoiseQuality = NoiseQuality.Standard, Seed = Seed + 4, OctaveCount = 6, Lacunarity = RiverWidthLacunarity, Persistence = RiverWidthPersistence }; Perlin terrainPerlin = new Perlin() { Frequency = TerrainPerlinFrequency, NoiseQuality = NoiseQuality.Standard, Seed = Seed, OctaveCount = 6, Lacunarity = TerrainPerlinLacunarity, Persistence = TerrainPerlinPersistence }; RidgedMultifractal terrainRMF = new RidgedMultifractal() { Frequency = TerrainRMFFrequency, NoiseQuality = NoiseQuality.High, Seed = Seed - 1, OctaveCount = 6, Lacunarity = TerrainRMFLacunarity }; ScaleOutput scaledRMF = new ScaleOutput(terrainRMF, TerrainRMFScale); Add terrainAdd = new Add(terrainPerlin, new BiasOutput(scaledRMF, TerrainRMFBias)); terrainScaledModule = new ScaleOutput(terrainAdd, HeightScale); biomesPerlin = new Perlin() { Frequency = BiomesFrequency, NoiseQuality = NoiseQuality.Low, Seed = Seed - 10, OctaveCount = 6, Lacunarity = BiomesLacunarity, Persistence = BiomesPersistence }; }
private static void Run(int octaves, double persistence, double frequency, double lacunarity) { string fileName = string.Format("O{3}_P{0:N3}_F{1:N3}.png", persistence, frequency, lacunarity, octaves); Billow billow = new Billow(); billow.Frequency = frequency; billow.NoiseQuality = NoiseQuality.High; billow.Seed = 0; 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; ridged.NoiseQuality = NoiseQuality.High; ridged.Seed = 0; ridged.OctaveCount = octaves; ridged.Lacunarity = lacunarity; Perlin perlin = new Perlin(); perlin.Frequency = frequency; perlin.NoiseQuality = NoiseQuality.High; perlin.Seed = 0; perlin.OctaveCount = octaves; perlin.Lacunarity = lacunarity; perlin.Persistence = persistence; Select selector = new Select(perlin, ridged, scaledBillow); selector.SetBounds(0, 1000); selector.EdgeFalloff = 0.5; IModule module = selector; //RidgedMultifractal module = new RidgedMultifractal(); //((RidgedMultifractal)module).Frequency = frequency; //((RidgedMultifractal)module).NoiseQuality = NoiseQuality.High; //((RidgedMultifractal)module).Seed = 0; //((RidgedMultifractal)module).OctaveCount = octaves; //((RidgedMultifractal)module).Lacunarity = lacunarity; //((RidgedMultifractal)module).Persistence = persistence; Pen blackPen = new Pen(Color.Black, 1); Font arialFont = new Font("Arial", 8); double min = double.MaxValue; double max = double.MinValue; double avg = 0; using (Bitmap b = new Bitmap(300, 2500)) { using (Graphics g = Graphics.FromImage(b)) { g.Clear(Color.White); for (int i = 0; i < 5000; i++) { var value = module.GetValue(i, 0, 0); avg += value; if (value < min) { min = value; } if (value > max) { max = value; } g.DrawRectangle(blackPen, 150 + (int)System.Math.Round(value * 100), i / 2, 1, 1); } avg /= 5000; g.DrawString(string.Format("Samples: {0:N3}\r\nMin: {1:N3}\r\nMax: {2:N3}\r\nAverage: {3:N3}", 5000, min, max, avg), arialFont, Brushes.DarkBlue, 5f, 60f); g.DrawString(string.Format("Frequency: {0:N3}\r\nPersistence: {1:N3}\r\nLacunarity: {2:N3}\r\nOctaves: {3:N3}", frequency, persistence, lacunarity, octaves), arialFont, Brushes.DarkGreen, 5f, 5f); } b.Save(@"Combined\" + fileName, ImageFormat.Png); } }
private static float[] GeneratePlanetHeightmapData(PlanetArchetypes.Archetype blueprint) { float[] height = new float[textureSize * textureSize]; LibNoise.RidgedMultifractal Generator = new LibNoise.RidgedMultifractal(); blueprint.SetNoiseGenerator(Generator); float correctMin = float.MaxValue; float correctMax = float.MinValue; float currValue; for (int y = 0; y < textureSize; y++) { for (int x = 0; x < textureSize; x++) { currValue = (float)Generator.GetValue((float)x / textureSize, (float)y / textureSize, 1); if (currValue < correctMin) correctMin = currValue; if (currValue > correctMax) correctMax = currValue; height[x + y * textureSize] = currValue; } } float oldValue; for (int y = 0; y < textureSize; y++) { for (int x = 0; x < textureSize; x++) { float mult = (float)x / textureSize; oldValue = height[x + y * textureSize]; currValue = (float)Generator.GetValue(((float)x / textureSize) + 1, (float)y / textureSize, 1); float yMult = (float)y / textureSize; yMult = Mathf.Clamp01(11.11f * Mathf.Pow(yMult, 2) - 11.11f * yMult + 1); height[x + y * textureSize] = Mathf.Lerp(currValue, oldValue, mult); height[x + y * textureSize] = Mathf.Lerp(height[x + y * textureSize], 0, yMult); } } for (int y = 0; y < textureSize; y++) { for (int x = 0; x < textureSize; x++) { height[x + y * textureSize] = (height[x + y * textureSize] - correctMin) / (correctMax - correctMin); } } return height; }
public virtual void AddSoil(long X, long Z, RidgedMultifractal CavernNoise, Perlin CaveNoise, double[,] hm,ref byte[,,] b, BiomeType[,] biomes, int WaterHeight, int depth, MapGenMaterials mats) { int YH = b.GetLength(1) - 2; double xo = (double)(X * b.GetLength(0)); double zo = (double)(Z * b.GetLength(2)); for (int x = 0; x < b.GetLength(0); x++) { //Console.WriteLine(); for (int z = 0; z < b.GetLength(2); z++) { double hmY=(double)(System.Math.Min(hm[x, z],1d) * (b.GetLength(1) - 3)); bool HavePloppedGrass = false; bool HaveTouchedSoil = false; // Caves first if (GenerateCaves) { for (int y = 0; y < b.GetLength(1); y++) { // If we're in rock, and CavernNoise value is under a threshold value calculated by height // or CaveNoise value is over threshold value, and the block we're removing won't fall on us... if ( b[x, y, z] == 1 && ( ((CavernNoise.GetValue(x + xo, y, z + zo) / 2) + 1) < Utils.Lerp(CavernThresholdMax, CavernThresholdMin, (((double)y / (hmY + 1)))) || (Utils.FixLibnoiseOutput(CaveNoise.GetValue(x + xo, y, z + zo)) > CaveThreshold) ) && !(b[x, y, z] == 9 || b[x, y, z] == 8 || b[x, y, z] == 12 || b[x, y, z] == 13)) { // Remove it b[x, y, z] = 0; } } } for (int y = (int)b.GetLength(1) - 1; y > 0; y--) { byte supportBlock = b[x, y-1, z]; // Ensure there's going to be stuff holding us up. if (b[x, y, z] == mats.Rock && supportBlock==mats.Rock) { HaveTouchedSoil = true; if (y + depth >= YH) continue; byte ddt = b[x, y+depth, z]; switch (ddt) { case 0: // Air case 8: // Water case 9: // Water BiomeType bt = biomes[x,z]; if (bt == BiomeType.Tundra) { b[x, y, z] = mats.Sand; } else { if (y - depth <= WaterHeight && GenerateWater) { if ((bt == BiomeType.Taiga || bt == BiomeType.TemperateForest || bt == BiomeType.Tundra) && y > WaterHeight) { b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } else { b[x, y, z] = mats.Sand; } } else b[x, y, z] = (HavePloppedGrass) ? mats.Soil : mats.Grass; } if (!HavePloppedGrass) HavePloppedGrass = true; break; default: y = 0; break; } } else if (b[x, y, z] == 0 && y <= WaterHeight && !HaveTouchedSoil && GenerateWater) { b[x, y, z] = mats.Water; } } } } }
//keep libnoise namepsace prefix, as it's names are incredibly generic private IModule GetGen(int seed) { IModule bas = null; float frequency = target.frequency * 0.01f; int octaveCount = Mathf.Max(target.octaveCount, 1); float lacunarity = target.lacunarity; switch (target.noiseType) { case NoiseType.Billow: var b = new Billow {Frequency = frequency, OctaveCount = octaveCount, Lacunarity = lacunarity, Seed = seed}; bas = b; break; case NoiseType.Pink: var p = new Perlin {Frequency = frequency, OctaveCount = octaveCount, Lacunarity = lacunarity, Seed = seed}; bas = p; break; case NoiseType.Ridged: var r = new RidgedMultifractal { Frequency = frequency, OctaveCount = target.octaveCount, Seed = seed, Lacunarity = lacunarity, }; bas = r; break; case NoiseType.Voronoi: var v = new Voronoi {Frequency = target.frequency * 0.05f, Seed = seed}; bas = v; break; } var t = new Turbulence(bas) {Frequency = target.turbulenceFrequency, Power = target.turbulencePower, Seed = seed + 789}; return t; }
public override bool Generate(long X, long Z, out double min, out double max) { min = 0; max = (double)ChunkY; if (treeNoise == null) { treeNoise = new Perlin(); treeNoise.Seed = (int)this.RandomSeed + 4; treeNoise.Frequency = 1; treeNoise.Persistence = 0.5; treeNoise.OctaveCount = 1; dungeonNoise = new Random((int)RandomSeed); cavernNoise = new RidgedMultifractal(); cavernNoise.Seed = (int)this.RandomSeed + 5; cavernNoise.Frequency = 0.025; //caveNoise.Persistence = 0.25; cavernNoise.OctaveCount = 1; caveNoise = new Perlin(); caveNoise.Seed = (int)RandomSeed + 2; caveNoise.Frequency = 0.03; caveNoise.Lacunarity = 0.01; caveNoise.Persistence = 0.01; caveNoise.OctaveCount = 1; } if (_Generator == null) { return false; } string lockfile = Path.ChangeExtension(GetChunkFilename((int)X,(int)Z), "genlock"); if (!_Generator.NoPreservation) { if (File.Exists(lockfile)) return true; } else { if (File.Exists(lockfile)) File.Delete(lockfile); } //Console.WriteLine("GEN"); profGen.Start(); double[,] hm = _Generator.Generate(this, X, Z,out min, out max); profGen.Stop(); if (hm == null) { Console.WriteLine("ERROR: hm==null"); return false; } // Erosion shit here. Chunk _c = NewChunk(X, Z); byte[, ,] blocks = _c.Blocks; //Console.WriteLine("BIOME"); profBiome.Start(); BiomeType[,] biomes = _Generator.DetermineBiomes(ChunkScale, X, Z); profBiome.Stop(); IMapHandler mh = this; // These use the block array. profVoxelize.Start(); HeightmapToVoxelspace(hm, ref blocks); AssertBottomBarrierIntegrity(blocks, "HeightmapToVoxelspace"); profVoxelize.Stop(); profSoil.Start(); _Generator.AddSoil(X,Z,cavernNoise, caveNoise, hm,ref blocks, biomes, 63, 6, _Generator.Materials); AssertBottomBarrierIntegrity(blocks, "AddSoil"); profSoil.Stop(); //profDgn.Start(); //_Generator.AddDungeons(ref blocks, ref mh, dungeonNoise, X, Z); AssertBottomBarrierIntegrity(blocks, "AddDungeons"); //profDgn.Stop(); profPrecip.Start(); _Generator.Precipitate(ref blocks, biomes, _Generator.Materials, X, Z); AssertBottomBarrierIntegrity(blocks, "Precipitate"); profPrecip.Stop(); profSave.Start(); mh.SaveAll(); _c.Blocks = blocks; //_c.UpdateOverview(); SetChunk(_c); File.WriteAllText(lockfile, _Generator.ToString()); // These use SetBlockAt() and company. //Console.WriteLine("SAVE"); SaveAll(); profSave.Stop(); string profres = profBiome.ToString(); profres += "\r\n"; profres += profDgn.ToString(); profres += "\r\n"; profres += profErode.ToString(); profres += "\r\n"; profres += profGen.ToString(); profres += "\r\n"; profres += profPrecip.ToString(); profres += "\r\n"; profres += profSave.ToString(); profres += "\r\n"; profres += profSoil.ToString(); profres += "\r\n"; profres += profVoxelize.ToString(); File.WriteAllText("GEN_PROFILE.txt", profres); return true; }
public LibNoise.IModule GenerateNoise(TerrainArchetype curTerrain, LibNoise.IModule noiseCombine) { LibNoise.Perlin Temp = new LibNoise.Perlin(); tempnoise = Temp; noise = Temp; noise1 = Temp; noise2 = Temp; noiseCombine = Temp; // Apply Noise Values for (int i = 0; i < curTerrain.C_nNoiseList.Length; i++) { switch (curTerrain.C_nNoiseList[i]) { case SetNoise.Perlin: LibNoise.Perlin perlin = new LibNoise.Perlin(); perlin.Frequency = curTerrain.C_nFrequency; perlin.Lacunarity = curTerrain.C_nLacunarity; perlin.NoiseQuality = curTerrain.C_nQuality; perlin.OctaveCount = curTerrain.C_nOctaves; perlin.Persistence = curTerrain.C_nPersistence; perlin.Seed = curTerrain.C_nSeed; tempnoise = perlin; break; case SetNoise.Billow: LibNoise.Billow billow = new LibNoise.Billow(); billow.Frequency = curTerrain.C_nFrequency; billow.Lacunarity = curTerrain.C_nLacunarity; billow.NoiseQuality = curTerrain.C_nQuality; billow.OctaveCount = curTerrain.C_nOctaves; billow.Persistence = curTerrain.C_nPersistence; billow.Seed = curTerrain.C_nSeed; tempnoise = billow; break; case SetNoise.MultiFractal: LibNoise.RidgedMultifractal MultiFrac = new LibNoise.RidgedMultifractal(); MultiFrac.Frequency = curTerrain.C_nFrequency; MultiFrac.Lacunarity = curTerrain.C_nLacunarity; MultiFrac.NoiseQuality = curTerrain.C_nQuality; MultiFrac.OctaveCount = curTerrain.C_nOctaves; //MultiFrac.Persistence = Persistence; MultiFrac.Seed = curTerrain.C_nSeed; tempnoise = MultiFrac; break; } switch (i) { case 0: noise = tempnoise; break; case 1: noise1 = tempnoise; break; case 2: noise2 = tempnoise; break; } } //selector = new LibNoise.Modifiers.Select(noise,noise1,noise2); LibNoise.IModule tempNoise1 = new LibNoise.Modifiers.Add(noise, noise1); LibNoise.IModule tempNoise2 = new LibNoise.Modifiers.Add(tempNoise1, noise2); noiseCombine = tempNoise2; return(noiseCombine); }