Exemple #1
0
    public void Generate()
    {
        // Create the module network
            ModuleBase moduleBase;
            switch(noise) {
                case NoiseType.Billow:
                moduleBase = new Billow();
                break;

                case NoiseType.RiggedMultifractal:
                moduleBase = new RiggedMultifractal();
                break;

                case NoiseType.Voronoi:
                moduleBase = new Voronoi();
                break;

              	case NoiseType.Mix:
                Perlin perlin = new Perlin();
                RiggedMultifractal rigged = new RiggedMultifractal();
                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);

        Debug.Log (moduleBase.GetValue (0, 0, UnityEngine.Random.value));

            // Generate the textures
            this.m_textures[0] = this.m_noiseMap.GetTexture(LibNoise.Unity.Gradient.Grayscale);
            this.m_textures[0].Apply();

            this.m_textures[1] = this.m_noiseMap.GetTexture(LibNoise.Unity.Gradient.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 + "/../");
    }
Exemple #2
0
    public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset)
    {
        LibNoise.Unity.Generator.RiggedMultifractal Noise = new LibNoise.Unity.Generator.RiggedMultifractal(scale, lacunarity, octaves, seed, LibNoise.Unity.QualityMode.High);
        float[,] noiseMap = new float[mapWidth, mapHeight];

        System.Random prng = new System.Random(seed);

        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                noiseMap[x, y] = (float)Noise.GetValue((float)x, 0f, (float)y);
                //noiseMap[x,y] = noiseMap[x,y];
            }
        }

        return(noiseMap);
    }
	public override void GenerateNoise ()
	{
		noiseModule = new RiggedMultifractal (noiseSettings.frequency, noiseSettings.lacunarity, noiseSettings.octaves, seed, noiseSettings.quality);
	}
    public void Initialize()
    {
        billow = new Billow();
        billow.Seed = Seed;
        fractal = new RiggedMultifractal();
        fractal.Seed = Seed;
        UnityEngine.Random.seed = Seed;
        billow.Frequency = UnityEngine.Random.value + 0.5;
        fractal.Frequency = UnityEngine.Random.value + 0.5;

        //int x,y,z;
        //Utils.LongToVoxelCoord(38655688717L, out x, out y, out z);
        //Debug.LogWarning("" + x + " " + y + " " + z);

        generables.Add(new GenTree());
    }
Exemple #5
0
				public bool StartGame (double max, double min, int seed, int numberOfSites, 
		                       double ParsedContinentFrequency, double ParsedBiomeFrequency, int ParsedOctaves, double ParsedLacunarity, double ParsedPersistence)
				{
						Debug.Log ("Starting the game, Max is:" + max);
						Max = max;
						Min = min;
						Seed = seed;
						NumberOfSites = numberOfSites;
						baseContinentNoise = new Perlin (ParsedContinentFrequency, ParsedLacunarity, ParsedPersistence, ParsedOctaves, seed, LibNoise.Unity.QualityMode.Medium);
						baseContinentSubtractNoise = new Scale (3, 1, 3, baseContinentNoise);
						Subtract sub = new Subtract (baseContinentNoise, baseContinentSubtractNoise);
						perturbedContinentNoise = new Turbulence (1, sub);			


						mountainNoise = new RiggedMultifractal (ParsedBiomeFrequency, ParsedLacunarity, ParsedOctaves, seed, LibNoise.Unity.QualityMode.Medium);
						baseFlatTerrainNoise = new Billow (ParsedBiomeFrequency, ParsedLacunarity, ParsedPersistence, ParsedOctaves, seed, LibNoise.Unity.QualityMode.Medium);
						flatTerrainNoise = new ScaleBias (0.25, -0.75, baseFlatTerrainNoise);
						terrainTypeNoise = new Perlin (ParsedBiomeFrequency, ParsedLacunarity, ParsedPersistence, ParsedOctaves, seed, LibNoise.Unity.QualityMode.Low);
						finalTerrainNoise = new Select (flatTerrainNoise, mountainNoise, terrainTypeNoise);
						finalTerrainNoise.SetBounds (0, 1000);
						finalTerrainNoise.FallOff = .5;

						finalTerrainNoiseMinusContinentNoise = new Subtract(finalTerrainNoise,perturbedContinentNoise);

						heatNoise = new Perlin (ParsedBiomeFrequency, ParsedLacunarity, ParsedPersistence, ParsedOctaves, seed, LibNoise.Unity.QualityMode.Medium);
						moistureNoise = new Perlin (ParsedBiomeFrequency, ParsedLacunarity, ParsedPersistence, ParsedOctaves, -seed, LibNoise.Unity.QualityMode.Medium);

						return BuildGraph ();
				}
 public void PostApply(ConfigNode node)
 {
     switch (type)
     {
     case NoiseType.Perlin:
         var perlin = new Perlin ();
         perlin.Quality = QualityMode.High;
         perlin.Seed = seed;
         perlin.OctaveCount = octaves;
         perlin.Frequency = frequency;
         perlin.Lacunarity = lacunarity;
         perlin.Persistence = persistence;
         Module = perlin;
         break;
     case NoiseType.ExDistPerlin:
         var exDistPerlin = new ExDistPerlin ();
         exDistPerlin.Quality = QualityMode.High;
         exDistPerlin.Seed = seed;
         exDistPerlin.OctaveCount = octaves;
         exDistPerlin.Frequency = frequency;
         exDistPerlin.Lacunarity = lacunarity;
         exDistPerlin.Persistence = persistence;
         exDistPerlin.Mu = mu;
         Module = exDistPerlin;
         break;
     case NoiseType.Billow:
         var billow = new Billow ();
         billow.Quality = QualityMode.High;
         billow.Seed = seed;
         billow.OctaveCount = octaves;
         billow.Frequency = frequency;
         billow.Lacunarity = lacunarity;
         billow.Persistence = persistence;
         Module = billow;
         break;
     case NoiseType.RidgedMultiFractal:
         var ridgedMultiFractal = new RiggedMultifractal ();
         ridgedMultiFractal.Quality = QualityMode.High;
         ridgedMultiFractal.Seed = seed;
         ridgedMultiFractal.OctaveCount = octaves;
         ridgedMultiFractal.Frequency = frequency;
         ridgedMultiFractal.Lacunarity = lacunarity;
         Module = ridgedMultiFractal;
         break;
     case NoiseType.Voronoi:
         var voronoi = new Voronoi ();
         voronoi.Seed = seed;
         voronoi.UseDistance = voronoiUseDistance;
         voronoi.Displacement = displacement;
         voronoi.Frequency = frequency;
         Module = voronoi;
         break;
     case NoiseType.Const:
         var constant = new Const ();
         constant.Value = constantValue;
         Module = constant;
         break;
     }
 }