Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public static float CubicNoiseSample2D(CubicNoiseConfig config,
                                               float x,
                                               float y)
        {
            int   xi    = (int)Math.Floor(x / config.Octave);
            float lerpX = x / config.Octave - xi;

            int   yi    = (int)Math.Floor(y / config.Octave);
            float lerpY = y / config.Octave - yi;

            float[] xSamples = new float[4];

            for (int i = 0; i < 4; i++)
            {
                xSamples[i] = CubicNoiseInterpolate(CubicNoiseRandom(config.Seed,
                                                                     CubicNoiseTile(xi - 1, config.PeriodX),
                                                                     CubicNoiseTile(yi - 1 + i, config.PeriodY)),
                                                    CubicNoiseRandom(config.Seed,
                                                                     CubicNoiseTile(xi, config.PeriodX),
                                                                     CubicNoiseTile(yi - 1 + i, config.PeriodY)),
                                                    CubicNoiseRandom(config.Seed,
                                                                     CubicNoiseTile(xi + 1, config.PeriodX),
                                                                     CubicNoiseTile(yi - 1 + i, config.PeriodY)),
                                                    CubicNoiseRandom(config.Seed,
                                                                     CubicNoiseTile(xi + 2, config.PeriodX),
                                                                     CubicNoiseTile(yi - 1 + i, config.PeriodY)),
                                                    lerpX);
            }

            return(CubicNoiseInterpolate(xSamples[0],
                                         xSamples[1],
                                         xSamples[2],
                                         xSamples[3],
                                         lerpY) * 0.5f + 0.25f);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="config"></param>
        /// <param name="x"></param>
        /// <returns></returns>
        public static float CubicNoiseSample1D(CubicNoiseConfig config,
                                               float x)
        {
            int   xi   = (int)(x / config.Octave);
            float lerp = x / config.Octave - xi;

            return(CubicNoiseInterpolate(CubicNoiseRandom(config.Seed, CubicNoiseTile(xi - 1, config.PeriodX), 0),
                                         CubicNoiseRandom(config.Seed, CubicNoiseTile(xi, config.PeriodX), 0),
                                         CubicNoiseRandom(config.Seed, CubicNoiseTile(xi + 1, config.PeriodX), 0),
                                         CubicNoiseRandom(config.Seed, CubicNoiseTile(xi + 2, config.PeriodX), 0),
                                         lerp) * 0.5f + 0.25f);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="seed"></param>
        /// <param name="octave"></param>
        /// <param name="period"></param>
        /// <returns></returns>
        public static CubicNoiseConfig CubicNoiseConfig1D(uint seed,
                                                          int octave,
                                                          int period)
        {
            CubicNoiseConfig config = new CubicNoiseConfig();

            config.Seed    = seed;
            config.Octave  = octave;
            config.PeriodX = period / octave;

            return(config);
        }