Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }