Example #1
0
    //a feature is either some noise with a texture or a composition of two features
    //the final terrain of a planet is a very complex feature made up of many features
    //this is funny: a feature is a composition of features; recursive logic and the function is recursive!
    //What the heck? that's not funny
    //noiseScale is the max scale of noise from the inner iterations to prevent large mountains from being selected on small scales
    public static void buildFeature(System.Random rand, out ModuleBase terrain, out ModuleBase texture, out float noiseScale, int lev, Dictionary <Sub, double> subList, out float abundance, bool needsTexture)
    {
        //Debug.Log("level " + lev);
        if (rand.NextDouble() < 1.3 / lev && lev < 4)
        {
            ModuleBase terrain1, terrain2, texture1, texture2;
            float      nScale1, nScale2;
            float      ab1, ab2;       //the relative abundance of the substances of each feature


            /*bool textureThis = false;
             * //possibly create a mulitfeature texture
             * if(needsTexture && Random.value<.2)
             * {
             *      textureThis = true;
             *      needsTexture = false;
             * }*/



            buildFeature(rand, out terrain1, out texture1, out nScale1, lev + 1, subList, out ab1, needsTexture);
            buildFeature(rand, out terrain2, out texture2, out nScale2, lev + 1, subList, out ab2, needsTexture);

            noiseScale = Mathf.Max(nScale1, nScale2);

            //TODO: some probability that edist lower bound is lower than noisescale
            double controlScale = eDist(Mathf.Max(noiseScale, 100), 1000000, rand.NextDouble());
            //the base control for the selector that adds two new features
            ModuleBase baseControl = getGradientNoise(hnProb, rand.NextDouble(), controlScale, rand);
            //baseControl = new Scale(50, 1, 1, baseControl);
            //create a cache module because this value will be calculated twice (once for terrain and once for texture)(possibly)
            baseControl = new Cache(baseControl);
            //make possible edge controller
            //loop and make inner controllers


            //the amount to add of this feature to the biome(0 is add none, 1 is completely cover)
            //NOTE: later amount will be somewhat dependant on the feature number(feature #6 will have an average lower amount than feature #2)
            double amount  = getAmount(ab1, ab2, rand.NextDouble());
            double falloff = rand.NextDouble();


            terrain = addModule(terrain1, terrain2, baseControl, amount, falloff);

            //if(textureThis)
            //	texture = buildTexture(subList,
            texture = addModule(texture1, texture2, baseControl, amount, 0);

            //the abundance of this final feature is that of the most abundand substance within it
            abundance = Mathf.Max(ab1, ab2);
        }
        else
        {
            //scale is the inverse of the frequency and is used to influence amplitude
            //float scale = eDist(80, 20000, rand.NextDouble());
            float scale = (float)baseNoiseScale.getValue(rand.NextDouble());
            //scale = 100;
            //the starting noise for the final feature that will be modified

            terrain = getGradientNoise(hnProb, rand.NextDouble(), scale, rand);

            //apply some random modification to the primordial noise
            //possibly in the future multiple mods can be applied
            int numPreMods = (int)preModAmount.getValue(rand.NextDouble());
            for (int i = 0; i < numPreMods; i++)
            {
                terrain = modMod(terrain, (int)preModType.getValue(rand.NextDouble()), rand);
            }


            //the amplidude or max height of the terrain
            //NOTE: later will be related to the frequency
            double amplitude = eDist(1, scale * amplitudeProb.getValue(rand.NextDouble()), rand.NextDouble());         //randDoub(2, 100);
            //bias is the number added to the noise before multiplying
            //-1 makes canyons/indentions, 1 makes all feautures above sea level
            //NOTE: later make a greater chance to be 1 or -1
            double bias = biasProb.getValue(rand.NextDouble());            //.1;//randDoub(-1, 1);


            //now apply the bias and amplitude
            terrain = new ScaleBias(amplitude, bias * amplitude, terrain);

            //apply some random post modifications
            int numMods = (int)postModAmount.getValue(rand.NextDouble());
            for (int i = 0; i < numMods; i++)
            {
                terrain = modMod(terrain, (int)postModType.getValue(rand.NextDouble()), rand);
            }

            //texture = Random.value<.7 ? buildTexture(subList, out abundance, 1) : null;
            //build a texture if it still needs one
            //texture = needsTexture ? buildTexture(subList, out abundance, 1, rand) : null;
            texture    = buildTexture(subList, out abundance, 1, rand);
            noiseScale = scale;
        }
    }
Example #2
0
    //TODO: paramatize all other properties
    /// <summary>
    /// get a random gradient noise function(perlin, billow, ridged, maybe voronoi later)
    /// </summary>
    /// <returns>The gradient noise.</returns>
    /// <param name="prob">Prob.</param>
    /// <param name="val">Value.</param>
    /// <param name="scale">Scale.</param>
    private static ModuleBase getGradientNoise(ProbItems prob, double val, double scale, System.Random rand)
    {
        //FastNoise fn = new FastNoise (Random.Range (0, int.MaxValue));
        //fn.Frequency = 1 / scale;
        //fn.OctaveCount = Random.Range (2, 6);
        //return fn;
        switch ((int)prob.getValue(rand.NextDouble()))
        {
        case 0:
            /*return new Perlin(1/scale,//randDoub(.00001, 0.1),
             *      randDoub(1.8, 2.2, rand.NextDouble()),
             *      randDoub(.4, .6, rand.NextDouble()),
             *      rand.Next(2, 6),
             *      rand.Next(int.MinValue, int.MaxValue),
             *      QualityMode.High);*/
            return(new FastNoise(rand.Next(0, int.MaxValue))
            {
                Frequency = 1 / scale,
                Lacunarity = randDoub(1.8, 2.2, rand.NextDouble()),
                Persistence = randDoub(.4, .6, rand.NextDouble()),
                OctaveCount = rand.Next(2, 6),
            });

            break;

        case 1:
            /*return new Billow(1/scale,
             *      randDoub(1.8, 2.2, rand.NextDouble()),
             *      randDoub(.4, .6, rand.NextDouble()),
             *      rand.Next(2, 6),
             *      rand.Next(int.MinValue, int.MaxValue),
             *      QualityMode.High);*/
            return(new FastBillow(rand.Next(0, int.MaxValue))
            {
                Frequency = 1 / scale,
                Lacunarity = randDoub(1.8, 2.2, rand.NextDouble()),
                Persistence = randDoub(.4, .6, rand.NextDouble()),
                OctaveCount = rand.Next(2, 6),
            });

            break;

        case 2:
            return(new FastRidgedMultifractal(rand.Next(0, int.MaxValue))
            {
                Frequency = 1 / scale,
                Lacunarity = randDoub(1.8, 2.2, rand.NextDouble()),
                //Persistence = randDoub(.4, .6, rand.NextDouble()),
                OctaveCount = rand.Next(2, 6),
            });

            /*return new RidgedMultifractal(1/scale,
             *      randDoub(1.8, 2.2, rand.NextDouble()),
             *      rand.Next(2, 6),
             *      rand.Next(int.MinValue, int.MaxValue),
             *      QualityMode.High);*/
            break;

        default:
            return(new Const(0.0));

            break;
        }
    }