public XNoiseTurbulence() { left = 6; right = 10; top = 1; bottom = 5; var mountainTerrain = new RidgedMultifractal(); var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); var terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; var terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType); terrainSelector.SetBounds(0, 1000); terrainSelector.FallOff = 0.125f; var terrainScaler = new ScaleBias(terrainSelector); terrainScaler.Scale = 375; terrainScaler.Bias = 375; finalTerrain = new Turbulence(terrainScaler); finalTerrain.Frequency = 4; finalTerrain.Power = 0.125f; }
private void Start() { // STEP 1 // Gradient is set directly on the object var mountainTerrain = new RidgedMultifractal(); // // STEP 2 var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; // STEP 3 var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); // STEP 4 var terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; var finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType); finalTerrain.SetBounds(0, 1000); finalTerrain.FallOff = 0.125; float start = Time.realtimeSinceStartup; RenderAndSetImage(finalTerrain); Debug.Log("BurstLibNoise runtime: " + (Time.realtimeSinceStartup - start)); }
public void generate() { // Get the terrain data of the currently active terrain var terrainData = Terrain.activeTerrain.terrainData; // A new ridged multifractal generator var generator = new RidgedMultifractal(frequency, lacu, octaves, (int)(Random.value * 0xffffff), QualityMode.High); // The thresholded output -- choose either 0.0 or 1.0, based on the output var clamped = new LibNoise.Operator.Select(new Const(0.0f), new Const(1.0f), generator); // Set the threshold and falloff rate clamped.SetBounds(0f, threshold); clamped.FallOff = falloff; // Create a 2D noise generator for the terrain heightmap, using the generator we just created var noise = new Noise2D(terrainData.heightmapResolution, clamped); // Generate a plane from [0, 1] on x, [0, 1] on y noise.GeneratePlanar(0, 1, 0, 1); // Get the data in an array so we can use it to set the heights // var data = noise.GetData(true, 0, 0, true); var data = noise.GetNormalizedData(); // .. and actually set the heights terrainData.SetHeights(0, 0, data); }
/// <summary> /// Initializes the base mod /// </summary> public override void OnSetup() { Billow billow = new Billow() { Seed = seed, Frequency = 2 * (1f / smoothness) }; ScaleBias scaleBia = new ScaleBias((1f / plainSmoothness), mesaVsPlainsBias, billow); RidgedMultifractal riggedMultifractal = new RidgedMultifractal { Seed = seed, OctaveCount = noisePasses, Frequency = 1 / smoothness }; Perlin perlin = new Perlin { Seed = seed, OctaveCount = noisePasses, Frequency = 1 / plainsVsMountainSmoothness, Persistence = 1 / falloff }; terrainHeightMap = new Select(0, 1, plainsVsMountainThreshold, scaleBia, riggedMultifractal) { Controller = perlin }; }
ModuleBase GetModule(PlanetProfile profile) { ModuleBase Generator; switch (profile.type) { case NoiseType.Perlin: Generator = new Perlin( profile.frequency, profile.lacunarity, profile.persistence, profile.octaves, Random.Range(0, int.MaxValue), QualityMode.Low); break; case NoiseType.Billow: Generator = new Billow( profile.frequency, profile.lacunarity, profile.persistence, profile.octaves, Random.Range(0, int.MaxValue), QualityMode.Low); break; case NoiseType.RiggedMultifractal: Generator = new RidgedMultifractal(profile.frequency, profile.lacunarity, profile.octaves, Random.Range(0, int.MaxValue), QualityMode.Low); break; case NoiseType.Voronoi: Generator = new Voronoi( profile.frequency, profile.displacement, Random.Range(0, int.MaxValue), true); break; default: Generator = new Perlin( profile.frequency, profile.lacunarity, profile.persistence, profile.octaves, Random.Range(0, int.MaxValue), QualityMode.Low); break; } return(Generator); }
public void Generate() { // Create the module network ModuleBase moduleBase; switch (noise) { case NoiseType.Billow: moduleBase = new Billow(); break; case NoiseType.RidgedMultifractal: moduleBase = new RidgedMultifractal(); break; case NoiseType.Voronoi: moduleBase = new Voronoi(); break; // case NoiseType.Mix: //Perlin perlin = new Perlin(); //RidgedMultifractal rigged = new RidgedMultifractal(); //moduleBase = new Add(perlin, rigged); //break; default: moduleBase = new Perlin(); break; } // Initialize the noise map this.m_noiseMap = new Noise2D(resolution, resolution, moduleBase); this.m_noiseMap.GeneratePlanar( offset + -1 * 1 / zoom, offset + offset + 1 * 1 / zoom, offset + -1 * 1 / zoom, offset + 1 * 1 / zoom); // Generate the textures this.m_textures[0] = this.m_noiseMap.GetTexture(GradientPresets.Grayscale); this.m_textures[0].Apply(); this.m_textures[1] = this.m_noiseMap.GetTexture(GradientPresets.Terrain); this.m_textures[1].Apply(); this.m_textures[2] = this.m_noiseMap.GetNormalMap(3.0f); this.m_textures[2].Apply(); //display on plane GetComponent <Renderer>().material.mainTexture = m_textures[0]; //write images to disk File.WriteAllBytes(Application.dataPath + "/../Gray.png", m_textures[0].EncodeToPNG()); File.WriteAllBytes(Application.dataPath + "/../Terrain.png", m_textures[1].EncodeToPNG()); File.WriteAllBytes(Application.dataPath + "/../Normal.png", m_textures[2].EncodeToPNG()); Debug.Log("Wrote Textures out to " + Application.dataPath + "/../"); }
public static float[,] Generate(int width, int height, int seed, int flatness, int voronoi_iterations, int voronoi_start) { // Create the module network ModuleBase moduleBase; moduleBase = new RidgedMultifractal(); Noise2D sound = new Noise2D(width, height, moduleBase); sound.GeneratePlanar( -1, 1, -1, 1, true); for (int i = 0; i <= voronoi_iterations; i++) { seed++; ModuleBase tempBase = new Voronoi(voronoi_start + i, displacement, seed, false); Noise2D temp = new Noise2D(width, height, tempBase); temp.GeneratePlanar( -1, 1, -1, 1, true); LayerNoise(sound, tempBase); ModuleBase pBase = new Perlin() { OctaveCount = perlinOctaves }; LayerNoise(sound, pBase); } Flatten(sound, flatness); return(sound.GetData()); }
void Awake() { noiseGenerator = new NoiseGenerator(); billowModule = new Billow(n1frequency, n1lacunarity, n1persistence, n1octaves, n1seed, QualityMode.High); //(frequency, lacunarity, persistence, octaves, seed, QualityMode.High)); //billowModule = new Voronoi(n1frequency, n1lacunarity, n1seed, true); billowScaleBiasModule = new ScaleBias(n1scale, n1bias, billowModule); ridgedModule = new RidgedMultifractal(n2frequency, n2lacunarity, n2octaves, n2seed, QualityMode.High); ridgedScaleBiasModule = new ScaleBias(n2scale, n2bias, ridgedModule); perlinModule = new Perlin(n3frequency, n3lacunarity, n3persistence, n3octaves, n3seed, QualityMode.High); perlinScaleBiasModule = new ScaleBias(n3scale, n3bias, perlinModule); selectModule = new Select(billowScaleBiasModule, ridgedScaleBiasModule, perlinScaleBiasModule); selectModule.SetBounds(0.5, 1000); // parameterize? selectModule.FallOff = 0.3928571; turbulenceModule = new Turbulence(0.335, selectModule); turbulenceModule.Frequency = 4.742f; turbulenceScaleBias = new ScaleBias(n1scale, n1bias, turbulenceModule); currentModule = billowScaleBiasModule; waterGenerator = GameObject.FindObjectOfType <WaterGenerator> (); }
void Start() { var mountainTerrain = new RidgedMultifractal(); var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); var terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; // Create the selector for turbulence var terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType); terrainSelector.SetBounds(0, 1000); terrainSelector.FallOff = 0.125f; var finalTerrain = new Turbulence(terrainSelector); finalTerrain.Frequency = _frequency; finalTerrain.Power = _power; RenderAndSetImage(finalTerrain); }
private void Meh(bool random = false) { if (random) { Noise.xOrg = Random.Range(-1000, 1000); Noise.yOrg = Random.Range(-1000, 1000); } // STEP 1 // Gradient is set directly on the object var mountainTerrain = new RidgedMultifractal(); // STEP 2 var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = Noise.Frequency; // STEP 3 var flatTerrain = new ScaleBias(Noise.Scale, Noise.Bias, baseFlatTerrain); // STEP 4 var terrainType = new Perlin(); terrainType.Frequency = Noise.TFrequency; terrainType.Persistence = Noise.Persistence; generator = new Select(flatTerrain, mountainTerrain, terrainType); generator.SetBounds(Noise.Min, Noise.Max); generator.FallOff = Noise.FallOff; RenderAndSetImage(generator); }
public SS_Cloud(int seed, int size, double frequency, double lacunarity, int octaves, Color tint, float brightness) { // Create sprite texture Sprite = new SS_Texture(size, size, Color.white); // Initialize noise with parameters RidgedMultifractal noise = new RidgedMultifractal(frequency, lacunarity, octaves, seed, QualityMode.Medium); // Create cloud for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { float distance = SS_Point.Distance(new SS_Point(x, y), Sprite.Center); float n = (float)noise.GetValue(x, y, 0); Color pixelColor = tint * n * brightness; float blackness = ((pixelColor.r + pixelColor.g + pixelColor.b) / 3.0f); float fade = distance / (size / 2); pixelColor.a = (1f - fade) * blackness; if (distance > (size / 2)) { pixelColor.a = 0f; } Sprite.SetPixel(x, y, pixelColor); } } }
static bool GenRidged2D(Player p, Level lvl, string seed) { RidgedMultifractal ridged2D = new RidgedMultifractal(); ridged2D.Seed = MapGen.MakeInt(seed); return(Gen2D(lvl, ridged2D)); }
void Start() { // STEP 1 // Gradient is set directly on the object var mountainTerrain = new RidgedMultifractal(); RenderAndSetImage(mountainTerrain); // Stop rendering if we're only getting as far as this tutorial // step. It saves me from doing multiple files. if (_tutorialStep <= 1) return; // STEP 2 var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; RenderAndSetImage(baseFlatTerrain); if (_tutorialStep <= 2) return; // STEP 3 var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); RenderAndSetImage(flatTerrain); if (_tutorialStep <= 3) return; // STEP 4 var terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; var finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType); finalTerrain.SetBounds(0, 1000); finalTerrain.FallOff = 0.125; RenderAndSetImage(finalTerrain); }
public float[,] Generate(IModule module, int _seed, bool _enableCaves, float _amp, float _caveDensity, float _groundOffset, float _grassOffset) { try { NoiseModule = module; seed = _seed; enableCaves = _enableCaves; amp = _amp; caveDensity = _caveDensity; groundOffset = _groundOffset; grassOffset = _grassOffset; RidgedMultifractal _caves = new RidgedMultifractal(); _caves.Seed = _seed; _caves.Frequency = 0.3; caveModule = _caves; Vector2Int bottomLeft = new Vector2(Location.x * ChunkSizeX, Location.z * ChunkSizeZ); Vector2Int topRight = new Vector2(Location.x * ChunkSizeX + ChunkSizeX, Location.z * ChunkSizeZ + ChunkSizeZ); SetSurfaceData(bottomLeft, topRight); } catch (Exception e) { SafeDebug.LogError(string.Format("{0}\nFunction: Generate\n Chunk: {1}", e.Message, Location.ToString()), e); } return(SurfaceData); }
private void SetupSwampinessNoise() { float freqMultiplier = WorldGenStep_Terrain.FreqMultiplier; ModuleBase input = new Perlin(0.090000003576278687 * freqMultiplier, 2.0, 0.40000000596046448, 6, Rand.Range(0, 2147483647), QualityMode.High); ModuleBase input2 = new RidgedMultifractal(0.02500000037252903 * freqMultiplier, 2.0, 6, Rand.Range(0, 2147483647), QualityMode.High); input = new ScaleBias(0.5, 0.5, input); input2 = new ScaleBias(0.5, 0.5, input2); this.noiseSwampiness = new Multiply(input, input2); ModuleBase module = this.noiseElevation; FloatRange swampinessMaxElevation = WorldGenStep_Terrain.SwampinessMaxElevation; float max = swampinessMaxElevation.max; FloatRange swampinessMaxElevation2 = WorldGenStep_Terrain.SwampinessMaxElevation; InverseLerp rhs = new InverseLerp(module, max, swampinessMaxElevation2.min); this.noiseSwampiness = new Multiply(this.noiseSwampiness, rhs); ModuleBase module2 = this.noiseRainfall; FloatRange swampinessMinRainfall = WorldGenStep_Terrain.SwampinessMinRainfall; float min = swampinessMinRainfall.min; FloatRange swampinessMinRainfall2 = WorldGenStep_Terrain.SwampinessMinRainfall; InverseLerp rhs2 = new InverseLerp(module2, min, swampinessMinRainfall2.max); this.noiseSwampiness = new Multiply(this.noiseSwampiness, rhs2); NoiseDebugUI.StorePlanetNoise(this.noiseSwampiness, "noiseSwampiness"); }
private void SetupSwampinessNoise() { float freqMultiplier = FreqMultiplier; ModuleBase input = new Perlin((double)(0.09f * freqMultiplier), 2.0, 0.40000000596046448, 6, Rand.Range(0, 2147483647), QualityMode.High); ModuleBase input2 = new RidgedMultifractal((double)(0.025f * freqMultiplier), 2.0, 6, Rand.Range(0, 2147483647), QualityMode.High); input = new ScaleBias(0.5, 0.5, input); input2 = new ScaleBias(0.5, 0.5, input2); noiseSwampiness = new Multiply(input, input2); ModuleBase module = noiseElevation; FloatRange swampinessMaxElevation = SwampinessMaxElevation; float max = swampinessMaxElevation.max; FloatRange swampinessMaxElevation2 = SwampinessMaxElevation; InverseLerp rhs = new InverseLerp(module, max, swampinessMaxElevation2.min); noiseSwampiness = new Multiply(noiseSwampiness, rhs); ModuleBase module2 = noiseRainfall; FloatRange swampinessMinRainfall = SwampinessMinRainfall; float min = swampinessMinRainfall.min; FloatRange swampinessMinRainfall2 = SwampinessMinRainfall; InverseLerp rhs2 = new InverseLerp(module2, min, swampinessMinRainfall2.max); noiseSwampiness = new Multiply(noiseSwampiness, rhs2); NoiseDebugUI.StorePlanetNoise(noiseSwampiness, "noiseSwampiness"); }
static bool GenRidged2D(MapGenArgs args) { RidgedMultifractal ridged2D = new RidgedMultifractal(); ridged2D.Seed = args.UseSeed ? args.Seed : new Random().Next(); return(Gen2D(args, ridged2D)); }
} // Base Height Result Module protected override void SetModules() { base.SetModules(); #region 1 ModuleBase module1 = new Const(5); #endregion #region 2 ModuleBase module2a = new RidgedMultifractal(frequency: Mathf.Pow(2, -8), lacunarity: 2.0, octaves: 6, seed: Random[IdxForRnd].Next(), quality: QualityMode.Low); ModuleBase module2b = new Turbulence(input: module2a); ((Turbulence)module2b).Seed = Random[IdxForRnd].Next(); ((Turbulence)module2b).Frequency = Mathf.Pow(2, -2); ((Turbulence)module2b).Power = 1; ModuleBase module2c = new ScaleBias(scale: 1.0, bias: 30.0, input: module2b); #endregion #region 3 ModuleBase module3a = new Billow(frequency: Mathf.Pow(2, -7) * 1.6, lacunarity: 2.0, persistence: 0.5, octaves: 8, seed: Random[IdxForRnd].Next(), quality: QualityMode.Low); ModuleBase module3b = new Turbulence(input: module3a); ((Turbulence)module3b).Seed = Random[IdxForRnd].Next(); ((Turbulence)module3b).Frequency = Mathf.Pow(2, -2); ((Turbulence)module3b).Power = 1.8; ModuleBase module3c = new ScaleBias(scale: 1.0, bias: 31.0, input: module3b); #endregion #region 4 ModuleBase module4a = new Perlin(frequency: Mathf.Pow(2, -6), lacunarity: 2.0, persistence: 0.5, octaves: 6, seed: Random[IdxForRnd].Next(), quality: QualityMode.Low); ModuleBase module4b = new Select(inputA: module2c, inputB: module3c, controller: module4a); ((Select)module4b).SetBounds(min: -.2, max: .2); ((Select)module4b).FallOff = .25; ModuleBase module4c = new Multiply(lhs: module4b, rhs: module1); #endregion MaterialSelectors[0] = (Select)module4b; Modules.Add(module4c); }
// This lets us load the modules once when the game starts and then treat them as static. private static void LoadModules(int game_seed) { seed = game_seed; // Create noise functions. mountain = new RidgedMultifractal(); mountain.Seed = seed; baseFlatTerrain = new Billow(); baseFlatTerrain.Seed = seed; baseFlatTerrain.Frequency = 0.5; //0.125 flatTerrain = new ScaleBias(0.0625, -0.75, baseFlatTerrain); //flatTerrain = new LibNoise.Unity.Generator.Const (-0.75); terrainType = new Perlin(); terrainType.Seed = seed; terrainType.Frequency = 0.5; terrainType.Persistence = 0.125; finalTerrain = new Select(flatTerrain, mountain, terrainType); finalTerrain.SetBounds(0.25, 1000.0); finalTerrain.FallOff = 0.125; modules_loaded = true; }
private void UpdateTexture() { texture.Resize(resolution.x, resolution.y); texture.wrapModeU = wrapModeU; texture.wrapModeV = wrapModeV; texture.alphaIsTransparency = true; texture.name = "Noise_" + name; if (seed == 0) { seed = Random.Range(int.MinValue, int.MaxValue); } ModuleBase noiseGenerator; switch (noiseType) { case NoiseType.Billow: Billow billow = new Billow(frequency, lacunarity, persistence, octaves, seed, QualityMode.High); noiseGenerator = billow; break; case NoiseType.RidgedMultifractal: RidgedMultifractal ridgedMultifractal = new RidgedMultifractal(frequency, lacunarity, octaves, seed, QualityMode.High); noiseGenerator = ridgedMultifractal; break; case NoiseType.Voronoi: Voronoi voronoi = new Voronoi(frequency, displacement, seed, distance); noiseGenerator = voronoi; break; default: //Default to perlin so the compiled doesn't complain Perlin perlin = new Perlin(frequency, lacunarity, persistence, octaves, seed, QualityMode.High); noiseGenerator = perlin; break; } Noise2D noiseMap = new Noise2D(resolution.x, resolution.y, noiseGenerator); noiseMap.GeneratePlanar( offset.x + -1 * 1 / zoom.x, offset.x + offset.x + 1 * 1 / zoom.x, offset.y + -1 * 1 / zoom.y, offset.y + 1 * 1 / zoom.y, isSeamless ); Texture2D noiseTexture = noiseMap.GetTexture(colorGradient); Color32[] colorArray = noiseTexture.GetPixels32(); texture.SetPixels32(0, 0, texture.width, texture.height, colorArray); texture.Apply(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(texture)); EditorUtility.SetDirty(this); }
private void SetupSwampinessNoise() { float freqMultiplier = FreqMultiplier; ModuleBase input = new Perlin(0.09f * freqMultiplier, 2.0, 0.40000000596046448, 6, Rand.Range(0, int.MaxValue), QualityMode.High); ModuleBase input2 = new RidgedMultifractal(0.025f * freqMultiplier, 2.0, 6, Rand.Range(0, int.MaxValue), QualityMode.High); input = new ScaleBias(0.5, 0.5, input); input2 = new ScaleBias(0.5, 0.5, input2); noiseSwampiness = new Multiply(input, input2); }
protected override ModuleBase CreateAndReadyModule() { RidgedMultifractal ridgedMulti = new RidgedMultifractal(); ridgedMulti.Quality = quality; ridgedMulti.Seed = seed; ridgedMulti.Frequency = frequency; ridgedMulti.OctaveCount = octaves; ridgedMulti.Lacunarity = lacunarity; return ridgedMulti; }
public SS_Moon(int seed, int size, float frequency, float lacunarity, int octaves, float roughness, Color[] colors, float lightAngle) { Seed = seed; Size = size; Sprite = new SS_Texture(size, size, Color.clear); gradientColors = SS_Utilities.CreateGradient(colors, 16, 32); Perlin shapeNoise = new Perlin(0.01, 2, 0.5, 8, seed, QualityMode.High); RidgedMultifractal noise = new RidgedMultifractal(frequency, lacunarity, octaves, seed, QualityMode.Low); Vector2 lightPosition = new Vector2( Sprite.Center.x + (Mathf.Cos(lightAngle * Mathf.Deg2Rad) * (Size / 4)), Sprite.Center.y + (Mathf.Sin(lightAngle * Mathf.Deg2Rad) * (Size / 4))); for (int y = 0; y < Size; y++) { for (int x = 0; x < Size; x++) { float dist = Vector2.Distance(new Vector2(x, y), new Vector2(Sprite.Center.x, Sprite.Center.y)); float edgeNoise = (float)shapeNoise.GetValue(x, y, 0); edgeNoise = (edgeNoise + 1.0f) * 0.5f; edgeNoise = Mathf.Clamp(edgeNoise, 0f, 1f); edgeNoise *= (8 * roughness); if (dist < (Size / 2) - edgeNoise) { float pixelNoise = (float)noise.GetValue(x, y, 0); pixelNoise = (pixelNoise + 1.0f) * 0.5f; pixelNoise = Mathf.Clamp(pixelNoise, 0f, 1f); float n = pixelNoise * (gradientColors.Length - 1); // Generate color and noise so land doesn't look to smooth Color pixelColor = gradientColors[(int)n]; pixelColor.a = 1.0f; Sprite.SetPixel(x, y, pixelColor); // Shadow float lightDistance = Vector2.Distance(new Vector2(x, y), lightPosition); lightDistance = 1.25f - (lightDistance / (Size / 2)); if (lightDistance < 0.025f) { lightDistance = 0.025f; } pixelColor.r *= lightDistance; pixelColor.g *= lightDistance; pixelColor.b *= lightDistance; Sprite.SetPixel(x, y, pixelColor); } } } }
private void SetupVolcanicNoise() { float freqMultiplier = FreqMultiplier; ModuleBase moduleBase = new Perlin((double)(0.09f * freqMultiplier), 2.0, 0.40000000596046448, 6, Rand.Range(0, int.MaxValue), QualityMode.High); ModuleBase moduleBase2 = new RidgedMultifractal((double)(0.005f * freqMultiplier), 2.0, 6, Rand.Range(0, int.MaxValue), QualityMode.High); moduleBase = new ScaleBias(0.5, 0.5, moduleBase); moduleBase2 = new ScaleBias(0.5, 0.5, moduleBase2); this.noiseVolcanic = new Multiply(moduleBase, moduleBase2); NoiseDebugUI.StorePlanetNoise(this.noiseVolcanic, "noiseVolcanic"); }
protected override ModuleBase CreateAndReadyModule() { RidgedMultifractal ridgedMulti = new RidgedMultifractal(); ridgedMulti.Quality = quality; ridgedMulti.Seed = seed; ridgedMulti.Frequency = frequency; ridgedMulti.OctaveCount = octaves; ridgedMulti.Lacunarity = lacunarity; return(ridgedMulti); }
//a test preset that creates a mars like planet used to figure out how to build this planet generator public static void marsPreset(out ModuleBase finalTerrain, out ModuleBase finalTexture, out List <ModuleBase> substanceNoise) { substanceNoise = new List <ModuleBase>(); ModuleBase mainControl = new Perlin(.0001, 2, .5, 4, 634234, QualityMode.High); ModuleBase edgeControl = new RidgedMultifractal(.001, 2, 3, 5723, QualityMode.High); edgeControl = new ScaleBias(.0, 0, edgeControl); ModuleBase finalControl = new Add(mainControl, edgeControl); ModuleBase text = addModule(Sub.IronDioxide, Sub.IronDioxide2, finalControl, .5); substanceNoise.Add(text); /* ModuleBase hills = new Perlin(.001, 2, 0.5, 3, 4353, QualityMode.Low, substanceNoise.Count-1); * hills = new Add(hills, new Const(1)); * hills = new Multiply(hills, new Const(100)); * * ModuleBase plains = new Perlin(.001, 2, .5, 3, 724, QualityMode.High, substanceNoise.Count-1); * plains = new Multiply(plains, new Const(3)); * * ModuleBase hpcontrol = new Perlin(.0005, 2, .5, 5, 45623, QualityMode.High); * * Select hpselector = new Select(hills, plains, hpcontrol); * hpselector.FallOff = 1;*/ ModuleBase plains = new Perlin(.001, 2, .5, 3, 724, QualityMode.High, substanceNoise.Count - 1); plains = new Multiply(plains, new Const(3)); //ModuleBase cliffthingsbase = new Perlin(.001, 2, .5, 4, 63443, QualityMode.High); ModuleBase cliffthingsbase = new RidgedMultifractal(.001, 2, 4, 63443, QualityMode.High); Terrace cliffthings = new Terrace(cliffthingsbase); cliffthings.Add(-1); cliffthings.Add(-.875); cliffthings.Add(-.75); cliffthings.Add(-.5); cliffthings.Add(0); cliffthings.Add(1); ModuleBase finalcliff = new ScaleBias(50, 50, cliffthings); ModuleBase innerControl = new Perlin(.005, 2, .4, 3, 2356, QualityMode.High); ModuleBase outerControl = new Perlin(.001, 2, .4, 3, 235, QualityMode.High); Select cliffSelector = addModule(finalcliff, plains, innerControl, .5, .1); Select cliffSelectorouter = addModule(cliffSelector, plains, outerControl, .2, .3); finalTexture = new Const(substanceNoise.Count - 1); finalTerrain = cliffSelectorouter; //finalTerrain = hpselector; //finalTerrain = new Const(0, substanceNoise.Count - 1); }
void Start() { // STEP 1 // Gradient is set directly on the object var mountainTerrain = new RidgedMultifractal(); RenderAndSetImage(mountainTerrain); // Stop rendering if we're only getting as far as this tutorial // step. It saves me from doing multiple files. if (_tutorialStep <= 1) { return; } // STEP 2 var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; RenderAndSetImage(baseFlatTerrain); if (_tutorialStep <= 2) { return; } // STEP 3 var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); RenderAndSetImage(flatTerrain); if (_tutorialStep <= 3) { return; } // STEP 4 var terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; var finalTerrain = new Select(flatTerrain, mountainTerrain, terrainType); finalTerrain.SetBounds(0, 1000); finalTerrain.FallOff = 0.125; RenderAndSetImage(finalTerrain); }
private void SetupRadiationNoise() { float freqMultiplier = FreqMultiplier; ModuleBase moduleBase = new Perlin((double)(0.09f * freqMultiplier), 2.0, 0.40000000596046448, 6, Rand.Range(0, int.MaxValue), QualityMode.High); ModuleBase moduleBase2 = new RidgedMultifractal((double)(0.025f * freqMultiplier), 2.0, 6, Rand.Range(0, int.MaxValue), QualityMode.High); moduleBase = new ScaleBias(0.5, 0.5, moduleBase); moduleBase2 = new ScaleBias(0.5, 0.5, moduleBase2); this.noiseRadiation = new Multiply(moduleBase, moduleBase2); InverseLerp rhs = new InverseLerp(this.noiseRadiation, RadMaxElevation.max, RadMaxElevation.min); this.noiseRadiation = new Multiply(this.noiseRadiation, rhs); NoiseDebugUI.StorePlanetNoise(this.noiseRadiation, "noiseRadiation"); }
public TerrainSampler(IModule module, int _seed, bool _enableCaves, float _amp, float _caveDensity, float _grassOffset) { NoiseModule = module; seed = _seed; enableCaves = _enableCaves; amp = _amp; caveDensity = _caveDensity; grassOffset = _grassOffset; RidgedMultifractal _caves = new RidgedMultifractal(); _caves.Seed = _seed; _caves.Frequency = 0.3; caveModule = _caves; }
private void backgroundProcessing() { // Create the module network ModuleBase moduleBase; switch (noise) { case NoiseType.Billow: moduleBase = new Billow(); break; case NoiseType.RidgedMultifractal: moduleBase = new RidgedMultifractal(); break; case NoiseType.Voronoi: moduleBase = new Voronoi(frequency, displacement, seed, false); break; case NoiseType.Mix: Perlin perlin = new Perlin(); var rigged = new RidgedMultifractal(); moduleBase = new Add(perlin, rigged); break; case NoiseType.Practice: var bill = new Billow(); bill.Frequency = frequency; moduleBase = new Turbulence(turbulence / 10, bill); break; default: var defPerlin = new Perlin(); defPerlin.OctaveCount = perlinOctaves; moduleBase = defPerlin; break; } // Initialize the noise map this.m_noiseMap = new Noise2D(resolution, resolution, moduleBase); m_noiseMap.GenerateSpherical(_north, _south, _west, _east); }
protected override void ConfigureProviders(int seed) { //Generate Ridged Multifractal noise RidgedMultifractal provider = new RidgedMultifractal() { OctaveCount = 1, Frequency = 0.3f, Seed = seed }; ScaleBias prov = new ScaleBias(provider) { Scale = 0.5f, //Bias = 0 }; this._baseProvider = prov; }
private void SetupSwampinessNoise() { float freqMultiplier = FreqMultiplier; ModuleBase input = new Perlin(0.09f * freqMultiplier, 2.0, 0.40000000596046448, 6, Rand.Range(0, int.MaxValue), QualityMode.High); ModuleBase input2 = new RidgedMultifractal(0.025f * freqMultiplier, 2.0, 6, Rand.Range(0, int.MaxValue), QualityMode.High); input = new ScaleBias(0.5, 0.5, input); input2 = new ScaleBias(0.5, 0.5, input2); noiseSwampiness = new Multiply(input, input2); InverseLerp rhs = new InverseLerp(noiseElevation, SwampinessMaxElevation.max, SwampinessMaxElevation.min); noiseSwampiness = new Multiply(noiseSwampiness, rhs); InverseLerp rhs2 = new InverseLerp(noiseRainfall, SwampinessMinRainfall.min, SwampinessMinRainfall.max); noiseSwampiness = new Multiply(noiseSwampiness, rhs2); NoiseDebugUI.StorePlanetNoise(noiseSwampiness, "noiseSwampiness"); }
void Start() { var mountainTerrain = new RidgedMultifractal(); var baseFlatTerrain = new Billow(); baseFlatTerrain.Frequency = 2.0; var flatTerrain = new ScaleBias(0.125, -0.75, baseFlatTerrain); var terrainType = new Perlin(); terrainType.Frequency = 0.5; terrainType.Persistence = 0.25; var terrainSelector = new Select(flatTerrain, mountainTerrain, terrainType); terrainSelector.SetBounds(0, 1000); terrainSelector.FallOff = 0.125f; /* * From the tutorial text: * * Next, you'll apply a bias of +375 to the output from the terrainSelector * noise module. This will cause its output to range from (-375 + 375) to * (+375 + 375), or in other words, 0 to 750. You'll apply this bias so * that most of the elevations in the resulting terrain height map are * above sea level. */ var terrainScaler = new ScaleBias(terrainSelector); terrainScaler.Scale = _scale; terrainScaler.Bias = _bias; var finalTerrain = new Turbulence(terrainScaler); finalTerrain.Frequency = _frequency; finalTerrain.Power = _power; RenderAndSetImage(finalTerrain); }
public static void genNoise(int channelId) { moduleBase[channelId] = new Perlin(); if (teNoiseChanTypeIndex[channelId] == 1) { int tIdx = teNoiseTypeIndex[channelId]; if (tIdx == 0) { moduleBase[channelId] = new Perlin(frequency[channelId], lacunarity[channelId], persistance[channelId], octaves[channelId], seed[channelId], QualityMode.High); } if (tIdx == 1) { moduleBase[channelId] = new Billow(frequency[channelId], lacunarity[channelId], persistance[channelId], octaves[channelId], seed[channelId], QualityMode.High); } if (tIdx == 2) { moduleBase[channelId] = new RidgedMultifractal(frequency[channelId], lacunarity[channelId], octaves[channelId], seed[channelId], QualityMode.High); } if (tIdx == 3) { moduleBase[channelId] = new Voronoi(frequency[channelId], displacement[channelId], seed[channelId], distance[channelId]); } if (tIdx == 4) { moduleBase[channelId] = new BrownianMotion(frequency[channelId], lacunarity[channelId], octaves[channelId], seed[channelId], QualityMode.High); } if (tIdx == 5) { moduleBase[channelId] = new HeterogeneousMultiFractal(frequency[channelId], lacunarity[channelId], octaves[channelId], persistance[channelId], seed[channelId], offset[channelId], QualityMode.High); } if (tIdx == 6) { moduleBase[channelId] = new HybridMulti(frequency[channelId], lacunarity[channelId], octaves[channelId], persistance[channelId], seed[channelId], offset[channelId], gain[channelId], QualityMode.High); } if (tIdx == 7) { moduleBase[channelId] = new LinearGradientNoise(frequency[channelId]); } } if (teNoiseChanTypeIndex[channelId] == 2) { int fIdx = teFunctionTypeIndex[channelId]; if (fIdx == 0) { moduleBase[channelId] = new Add(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); } if (fIdx == 1) { moduleBase[channelId] = new Subtract(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); } if (fIdx == 2) { moduleBase[channelId] = new Multiply(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); } if (fIdx == 3) { moduleBase[channelId] = new Min(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); } if (fIdx == 4) { moduleBase[channelId] = new Max(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]]); } if (fIdx == 5) { moduleBase[channelId] = new Blend(moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]], moduleBase[srcChannel3Id[channelId]]); } if (fIdx == 6) { moduleBase[channelId] = new Clamp((double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId], moduleBase[srcChannel1Id[channelId]]); } if (fIdx == 7) { moduleBase[channelId] = new Power(moduleBase[srcChannel1Id[channelId]],moduleBase[srcChannel2Id[channelId]]);} if (fIdx == 8) { Curve tmpCurve = new Curve(moduleBase[srcChannel1Id[channelId]]); double adjust = double.Parse((controlpointcount[channelId]-1).ToString())*0.5; for(int i=0;i<controlpointcount[channelId];i++){ tmpCurve.Add(double.Parse(i.ToString())-adjust,(double)cpval[channelId,i]); moduleBase[channelId] = tmpCurve; } } if(fIdx==9){Terrace tmpTerrace = new Terrace(invertTerrace[channelId],moduleBase[srcChannel1Id[channelId]]); for(int i=0;i<controlpointcount[channelId];i++){ tmpTerrace.Add((double)cpval[channelId,i]-0.5); moduleBase[channelId] = tmpTerrace; } } if (fIdx == 18) { moduleBase[channelId] = new Mask(moduleBase[srcChannel1Id[channelId]], (double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId]); } if (fIdx == 17) { moduleBase[channelId] = new WindexWarp(moduleBase[srcChannel1Id[channelId]]); } if (fIdx == 16) { moduleBase[channelId] = new TEWarp(moduleBase[srcChannel1Id[channelId]]); } if (fIdx == 15) { moduleBase[channelId] = new Select((double)noiseFuncMin[channelId], (double)noiseFuncMax[channelId], falloff[channelId], moduleBase[srcChannel1Id[channelId]], moduleBase[srcChannel2Id[channelId]], moduleBase[srcChannel3Id[channelId]]); } if (fIdx == 14) { moduleBase[channelId] = new Turbulence(power[channelId],moduleBase[srcChannel1Id[channelId]]); } if (fIdx == 13) { moduleBase[channelId] = new ScaleBias(scale[channelId],bias[channelId],moduleBase[srcChannel1Id[channelId]]); } if (fIdx == 12) { moduleBase[channelId] = new Invert(moduleBase[srcChannel1Id[channelId]]);} if (fIdx == 11) { moduleBase[channelId] = new Exponent(exponent[channelId],moduleBase[srcChannel1Id[channelId]]); } if (fIdx == 10) { moduleBase[channelId] = new Abs(moduleBase[srcChannel1Id[channelId]]);} } int resolution = 64; int xoffset = 0; int yoffset = 0; m_noiseMap[channelId] = new Noise2D(resolution, resolution, moduleBase[channelId]); float x1 = xoffset * zoom[channelId]; float x2 = (xoffset * zoom[channelId]) + ((zoom[channelId] / resolution) * (resolution + 1)); float y1 = -yoffset * zoom[channelId]; float y2 = (-yoffset * zoom[channelId]) + ((zoom[channelId] / resolution) * (resolution + 1)); m_noiseMap[channelId].GeneratePlanar(x1, x2, y1, y2); m_textures[channelId] = m_noiseMap[channelId].GetTexture(); m_textures[channelId].Apply(); }
public void Generate () { // Create the module network ModuleBase moduleBase; switch (noise) { case NoiseType.Billow: moduleBase = new Billow (); break; case NoiseType.RidgedMultifractal: moduleBase = new RidgedMultifractal (); break; case NoiseType.Voronoi: // moduleBase = new Voronoi(); seed = UnityEngine.Random.Range (0, 100); moduleBase = new Voronoi (frequency, displacement, seed, false); break; case NoiseType.Mix: Perlin perlin = new Perlin (); var rigged = new RidgedMultifractal (); moduleBase = new Add (perlin, rigged); break; case NoiseType.Practice: var bill = new Billow (); bill.Frequency = frequency; moduleBase = new Turbulence (turbulence / 10, bill); break; default: var defPerlin = new Perlin (); defPerlin.OctaveCount = perlinOctaves; moduleBase = defPerlin; break; } // Initialize the noise map this.m_noiseMap = new Noise2D (resolution, resolution, moduleBase); this.m_noiseMap.GeneratePlanar ( offset + -1 * 1 / zoom, offset + offset + 1 * 1 / zoom, offset + -1 * 1 / zoom, offset + 1 * 1 / zoom, true); // Generate the textures this.m_textures [0] = this.m_noiseMap.GetTexture (GradientPresets.Grayscale); this.m_textures [0].Apply (); this.m_textures [1] = this.m_noiseMap.GetTexture (GradientPresets.Terrain); this.m_textures [1].Apply (); this.m_textures [2] = this.m_noiseMap.GetNormalMap (3.0f); this.m_textures [2].Apply (); //display on plane renderer.material.mainTexture = this.m_textures [0]; //write images to disk File.WriteAllBytes (Application.dataPath + "/../Gray.png", m_textures [0].EncodeToPNG ()); File.WriteAllBytes (Application.dataPath + "/../Terrain.png", m_textures [1].EncodeToPNG ()); File.WriteAllBytes (Application.dataPath + "/../Normal.png", m_textures [2].EncodeToPNG ()); Debug.Log ("Wrote Textures out to " + Application.dataPath + "/../"); }
private static List<LoadedModule> GetModules(XmlNodeList moduleList) { List<LoadedModule> loadedModules = new List<LoadedModule>(); foreach (XmlNode node in moduleList) { string id = node.Attributes["guid"].Value; Point position = new Point(double.Parse(node.Attributes["position"].Value.Split(',')[0]), double.Parse(node.Attributes["position"].Value.Split(',')[1])); ModuleBase module = null; List<string> links = new List<string>(); switch (node.Attributes["type"].Value) { case "Billow": Billow billow = new Billow(); billow.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); billow.Lacunarity = double.Parse(node.SelectSingleNode("Lacunarity").InnerText); billow.OctaveCount = int.Parse(node.SelectSingleNode("OctaveCount").InnerText); billow.Persistence = double.Parse(node.SelectSingleNode("Persistence").InnerText); billow.Quality = (QualityMode)Enum.Parse(typeof(QualityMode), node.SelectSingleNode("Quality").InnerText); billow.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText); module = billow; break; case "Checker": module = new Checker(); break; case "Const": Const con = new Const(); con.Value = double.Parse(node.SelectSingleNode("Value").InnerText); module = con; break; case "Cylinders": Cylinders cylinder = new Cylinders(); cylinder.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); module = cylinder; break; case "Perlin": Perlin perlin = new Perlin(); perlin.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); perlin.Lacunarity = double.Parse(node.SelectSingleNode("Lacunarity").InnerText); perlin.OctaveCount = int.Parse(node.SelectSingleNode("OctaveCount").InnerText); perlin.Persistence = double.Parse(node.SelectSingleNode("Persistence").InnerText); perlin.Quality = (QualityMode)Enum.Parse(typeof(QualityMode), node.SelectSingleNode("Quality").InnerText); perlin.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText); module = perlin; break; case "RidgedMultifractal": RidgedMultifractal ridgedMF = new RidgedMultifractal(); ridgedMF.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); ridgedMF.Lacunarity = double.Parse(node.SelectSingleNode("Lacunarity").InnerText); ridgedMF.OctaveCount = int.Parse(node.SelectSingleNode("OctaveCount").InnerText); ridgedMF.Quality = (QualityMode)Enum.Parse(typeof(QualityMode), node.SelectSingleNode("Quality").InnerText); ridgedMF.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText); module = ridgedMF; break; case "Spheres": Spheres spheres = new Spheres(); spheres.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); module = spheres; break; case "Voronoi": Voronoi voronoi = new Voronoi(); voronoi.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); voronoi.Displacement = double.Parse(node.SelectSingleNode("Displacement").InnerText); voronoi.UseDistance = bool.Parse(node.SelectSingleNode("UseDistance").InnerText); voronoi.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText); module = voronoi; break; case "Abs": module = new Abs(); XmlNode absInputs = node.SelectSingleNode("ModuleInputs"); links.Add(absInputs.SelectSingleNode("Input").InnerText); break; case "Add": module = new Add(); XmlNode addInputs = node.SelectSingleNode("ModuleInputs"); links.Add(addInputs.SelectSingleNode("Left").InnerText); links.Add(addInputs.SelectSingleNode("Right").InnerText); break; case "Blend": module = new Blend(); XmlNode blendInputs = node.SelectSingleNode("ModuleInputs"); links.Add(blendInputs.SelectSingleNode("Left").InnerText); links.Add(blendInputs.SelectSingleNode("Right").InnerText); links.Add(blendInputs.SelectSingleNode("Operator").InnerText); break; case "Cache": module = new Cache(); XmlNode cacheInputs = node.SelectSingleNode("ModuleInputs"); links.Add(cacheInputs.SelectSingleNode("Input").InnerText); break; case "Clamp": Clamp clamp = new Clamp(); clamp.Maximum = double.Parse(node.SelectSingleNode("Maximum").InnerText); clamp.Minimum = double.Parse(node.SelectSingleNode("Minimum").InnerText); module = clamp; XmlNode clampInputs = node.SelectSingleNode("ModuleInputs"); links.Add(clampInputs.SelectSingleNode("Input").InnerText); break; case "Curve": Curve curve = new Curve(); module = curve; foreach (XmlNode cpNode in node.SelectSingleNode("ControlPoints").ChildNodes) { double x = double.Parse(cpNode.InnerText.Split(',')[0]); double y = double.Parse(cpNode.InnerText.Split(',')[1]); curve.Add(x, y); } XmlNode curveInputs = node.SelectSingleNode("ModuleInputs"); links.Add(curveInputs.SelectSingleNode("Input").InnerText); break; case "Displace": module = new Displace(); XmlNode displaceInputs = node.SelectSingleNode("ModuleInputs"); links.Add(displaceInputs.SelectSingleNode("Primary").InnerText); links.Add(displaceInputs.SelectSingleNode("X").InnerText); links.Add(displaceInputs.SelectSingleNode("Y").InnerText); links.Add(displaceInputs.SelectSingleNode("Z").InnerText); break; case "Exponent": Exponent exponent = new Exponent(); exponent.Value = double.Parse(node.SelectSingleNode("Value").InnerText); module = exponent; XmlNode exponentInputs = node.SelectSingleNode("ModuleInputs"); links.Add(exponentInputs.SelectSingleNode("Input").InnerText); break; case "Invert": module = new Invert(); XmlNode invertInputs = node.SelectSingleNode("ModuleInputs"); links.Add(invertInputs.SelectSingleNode("Input").InnerText); break; case "Max": module = new Max(); XmlNode maxInputs = node.SelectSingleNode("ModuleInputs"); links.Add(maxInputs.SelectSingleNode("Left").InnerText); links.Add(maxInputs.SelectSingleNode("Right").InnerText); break; case "Min": module = new Min(); XmlNode minInputs = node.SelectSingleNode("ModuleInputs"); links.Add(minInputs.SelectSingleNode("Left").InnerText); links.Add(minInputs.SelectSingleNode("Right").InnerText); break; case "Multiply": module = new Multiply(); XmlNode multiplyInputs = node.SelectSingleNode("ModuleInputs"); links.Add(multiplyInputs.SelectSingleNode("Left").InnerText); links.Add(multiplyInputs.SelectSingleNode("Right").InnerText); break; case "Power": module = new Power(); XmlNode powerInputs = node.SelectSingleNode("ModuleInputs"); links.Add(powerInputs.SelectSingleNode("Left").InnerText); links.Add(powerInputs.SelectSingleNode("Right").InnerText); break; case "Rotate": Rotate rotate = new Rotate(); rotate.X = double.Parse(node.SelectSingleNode("X").InnerText); rotate.Y = double.Parse(node.SelectSingleNode("Y").InnerText); rotate.Z = double.Parse(node.SelectSingleNode("Z").InnerText); module = rotate; XmlNode rotateInputs = node.SelectSingleNode("ModuleInputs"); links.Add(rotateInputs.SelectSingleNode("Input").InnerText); break; case "Scale": Scale scale = new Scale(); scale.X = double.Parse(node.SelectSingleNode("X").InnerText); scale.Y = double.Parse(node.SelectSingleNode("Y").InnerText); scale.Z = double.Parse(node.SelectSingleNode("Z").InnerText); module = scale; XmlNode scaleInputs = node.SelectSingleNode("ModuleInputs"); links.Add(scaleInputs.SelectSingleNode("Input").InnerText); break; case "ScaleBias": ScaleBias scaleBias = new ScaleBias(); scaleBias.Scale = double.Parse(node.SelectSingleNode("Scale").InnerText); scaleBias.Bias = double.Parse(node.SelectSingleNode("Bias").InnerText); module = scaleBias; XmlNode scaleBiasInputs = node.SelectSingleNode("ModuleInputs"); links.Add(scaleBiasInputs.SelectSingleNode("Input").InnerText); break; case "Select": Select select = new Select(); select.Minimum = double.Parse(node.SelectSingleNode("Minimum").InnerText); select.Maximum = double.Parse(node.SelectSingleNode("Maximum").InnerText); select.FallOff = double.Parse(node.SelectSingleNode("FallOff").InnerText); module = select; XmlNode selectInputs = node.SelectSingleNode("ModuleInputs"); links.Add(selectInputs.SelectSingleNode("Primary").InnerText); links.Add(selectInputs.SelectSingleNode("Secondary").InnerText); links.Add(selectInputs.SelectSingleNode("Controller").InnerText); break; case "Subtract": module = new Subtract(); XmlNode subtractInputs = node.SelectSingleNode("ModuleInputs"); links.Add(subtractInputs.SelectSingleNode("Left").InnerText); links.Add(subtractInputs.SelectSingleNode("Right").InnerText); break; case "Terrace": Terrace terrace = new Terrace(); module = terrace; foreach (XmlNode cpNode in node.SelectSingleNode("ControlPoints").ChildNodes) { terrace.Add(double.Parse(cpNode.InnerText)); } XmlNode terraceInputs = node.SelectSingleNode("ModuleInputs"); links.Add(terraceInputs.SelectSingleNode("Input").InnerText); break; case "Translate": Translate translate = new Translate(); translate.X = double.Parse(node.SelectSingleNode("X").InnerText); translate.Y = double.Parse(node.SelectSingleNode("Y").InnerText); translate.Z = double.Parse(node.SelectSingleNode("Z").InnerText); module = translate; XmlNode translateInputs = node.SelectSingleNode("ModuleInputs"); links.Add(translateInputs.SelectSingleNode("Input").InnerText); break; case "Turbulence": Turbulence turbulence = new Turbulence(); turbulence.Frequency = double.Parse(node.SelectSingleNode("Frequency").InnerText); turbulence.Power = double.Parse(node.SelectSingleNode("Power").InnerText); turbulence.Roughness = int.Parse(node.SelectSingleNode("Roughness").InnerText); turbulence.Seed = int.Parse(node.SelectSingleNode("Seed").InnerText); module = turbulence; XmlNode turbulenceInputs = node.SelectSingleNode("ModuleInputs"); links.Add(turbulenceInputs.SelectSingleNode("Input").InnerText); break; case "Final": module = new Final(); XmlNode finalInputs = node.SelectSingleNode("ModuleInputs"); links.Add(finalInputs.SelectSingleNode("Input").InnerText); break; default: break; } LoadedModule lm = new LoadedModule(id, module, position, links); loadedModules.Add(lm); } return loadedModules; }
void NoiseSelector() { // Requires LibNoise in your project // https://github.com/ricardojmendez/LibNoise.Unity switch (noiseType) { case NoiseMode.Billow: var billow = new Billow(); billow.Seed = seed; billow.Quality = quality; billow.OctaveCount = _octaveCount; billow.Frequency = _frecuency * 0.1; billow.Lacunarity = _lacunarity; billow.Persistence = _persistence; generate = billow; break; case NoiseMode.Perlin: var perlin = new Perlin(); perlin.Seed = seed; perlin.Quality = quality; perlin.OctaveCount = _octaveCount; perlin.Frequency = _frecuency * 0.1; perlin.Lacunarity = _lacunarity; perlin.Persistence = _persistence; generate = perlin; break; case NoiseMode.RidgedMultifractal: var multiFractal = new RidgedMultifractal(); multiFractal.Seed = seed; multiFractal.Quality = quality; multiFractal.OctaveCount = _octaveCount; multiFractal.Frequency = _frecuency * 0.1; multiFractal.Lacunarity = _lacunarity; generate = multiFractal; break; case NoiseMode.Voronoi: var voroni = new Voronoi(); voroni.Seed = seed; voroni.Frequency = _frecuency; voroni.Displacement = _displacement; generate = voroni; break; default: break; } }