예제 #1
0
        static void Main(string[] args)
        {
            var noiseSource = new SimplexPerlin
            {
                Seed    = 0,
                Quality = NoiseQuality.Fast
            };

            var min = 0f;
            var max = 0f;

            for (int x = 0; x < 100; x++)
            {
                for (int z = 0; z < 100; z++)
                {
                    var val = noiseSource.GetValue(x, z);
                    if (val < min)
                    {
                        min = val;
                    }
                    if (val > max)
                    {
                        max = val;
                    }
                }
            }
            Console.Write(min + " " + max);

            Console.ReadKey();
        }
예제 #2
0
        public override void Update()
        {
            base.Update();
            Offset   += Velocity;
            Velocity += Util.AngleToVector(DriftAngle) * DriftSpeed;
            Velocity  = Velocity.ClampLength(0, VelocityMax);
            float driftAngleVelocity = Noise.GetValue(Frame.Slide, RandomOffset);

            DriftAngle += driftAngleVelocity;
        }
    public override double Execute(double x, double y, double z, CallableNode flow)
    {
        var altitude = baseAltitude + simplexAltitude.GetValue(x * frequencyAltitude, z * frequencyAltitude) * scaleAltitude;

        if (y < altitude - tunnelsHeight - HeightMargin || y > altitude + tunnelsHeight + HeightMargin)
        {
            return(-HeightMargin);
        }

        var network = Math.Min(ridgedMultiFractal.GetValue(x, z), 1.0 - (1.0 - threshold) * 0.333333);
        var tunnel  = network - threshold;
        var sign    = tunnel < 0 ? -1.0 : 1.0;

        tunnel = sign * Math.Sqrt(Math.Abs(tunnel));

        return(tunnelsHeight * tunnel - Math.Abs(y - altitude)
               + scalePerturbation * simplexPerturbation.GetValue(x * frequencyPerturbation, y * frequencyPerturbation, z * frequencyPerturbation)
               + scaleMicroPerturbation * simplexPerturbation.GetValue(x * frequencyMicroPerturbation, y * frequencyMicroPerturbation, z * frequencyMicroPerturbation));
    }
예제 #4
0
        internal GcRandom(ChunkColumn chunki, int seed)
        {
            Chunk = chunki;
            _subtractForLessThanCutoff = _amplitude1 - _cutOff;
            _f1Xz = 1.0 / _sxz;
            _f1Y  = 1.0 / _sy;

            if (_maxCaveHeight - _minCaveHeight > 128)
            {
                _caveBandBuffer = 32;
            }
            else
            {
                _caveBandBuffer = 16;
            }

            _noiseGen1 = new SimplexPerlin(seed, NoiseQuality.Fast);
            _noiseGen2 = new SimplexPerlin((int)_noiseGen1.GetValue(Chunk.X, Chunk.Z), NoiseQuality.Fast);
            _noiseGen3 = new SimplexPerlin((int)_noiseGen1.GetValue(Chunk.X, Chunk.Z), NoiseQuality.Fast);
        }
예제 #5
0
        internal GCRandom(ChunkColumn chunki, int seed)
        {
            chunk = chunki;
            subtractForLessThanCutoff = amplitude1 - CutOff;
            f1xz = 1.0 / sxz;
            f1y  = 1.0 / sy;

            if (MaxCaveHeight - MinCaveHeight > 128)
            {
                caveBandBuffer = 32;
            }
            else
            {
                caveBandBuffer = 16;
            }

            noiseGen1 = new SimplexPerlin(seed, NoiseQuality.Fast);
            noiseGen2 = new SimplexPerlin((int)noiseGen1.GetValue(chunk.X, chunk.Z), NoiseQuality.Fast);
            noiseGen3 = new SimplexPerlin((int)noiseGen1.GetValue(chunk.X, chunk.Z), NoiseQuality.Fast);
        }
예제 #6
0
        private SimplexPerlin CreateSimplexPerlin()
        {
            SimplexPerlin tmp = new SimplexPerlin(0, NoiseQuality.Best);
            int           s   = 0;

            for (int i = 0; i < Taste.Length; i++)
            {
                s += (int)tmp.GetValue((int)Taste[i], -i, NoiseRange.Byte);
            }
            tmp = null;

            return(new SimplexPerlin(s, NoiseQuality.Best));
        }
예제 #7
0
        public bool IsInCave(int x, int y, int z)
        {
            float xx = (Chunk.X << 4) | (x & 0xF);
            float yy = y;
            float zz = (Chunk.Z << 4) | (z & 0xF);

            double n1 = (_noiseGen1.GetValue((float)(xx * _f1Xz), (float)(yy * _f1Y), (float)(zz * _f1Xz)) * _amplitude1);
            double n2 = (_noiseGen2.GetValue((float)(xx * _f2Xz), (float)(yy * _f2Y), (float)(zz * _f2Xz)) * _amplitude2);
            double n3 = (_noiseGen3.GetValue((float)(xx * _f3Xz), (float)(yy * _f3Y), (float)(zz * _f3Xz)) * _amplitude3);
            var    lc = LinearCutoffCoefficient(y);

            var isInCave = n1 + n2 - n3 - lc > 62;

            return(isInCave);
        }
예제 #8
0
        public bool IsInCave(int x, int y, int z)
        {
            float xx = (chunk.X << 4) | (x & 0xF);
            float yy = y;
            float zz = (chunk.Z << 4) | (z & 0xF);

            double n1 = (noiseGen1.GetValue((float)(xx * f1xz), (float)(yy * f1y), (float)(zz * f1xz)) * amplitude1);
            double n2 = (noiseGen2.GetValue((float)(xx * f2xz), (float)(yy * f2y), (float)(zz * f2xz)) * amplitude2);
            double n3 = (noiseGen3.GetValue((float)(xx * f3xz), (float)(yy * f3y), (float)(zz * f3xz)) * amplitude3);
            var    lc = LinearCutoffCoefficient(y);

            var isInCave = n1 + n2 - n3 - lc > 62;

            return(isInCave);
        }
        private float GetNoise2D(int octaves, float persistence, float scale, int x, int y)
        {
            float total     = 0;
            float frequency = scale;
            float amplitude = 1;

            // We have to keep track of the largest possible amplitude,
            // because each octave adds more, and we need a value in [-1, 1].
            float maxAmplitude = 0;

            for (int i = 0; i < octaves; i++)
            {
                total += moistureNoise.GetValue(x * frequency, y * frequency) * amplitude;

                frequency    *= 2;
                maxAmplitude += amplitude;
                amplitude    *= persistence;
            }

            return(total / maxAmplitude);
        }
예제 #10
0
파일: Chunk.cs 프로젝트: DrSmCraft/Tiles
        private Tile GenerateTile(int x, int y)
        {
            var z = (simplexPerlin.GetValue(x * Constants.generatorZoom, y * Constants.generatorZoom) + 1) / 2;

            var vec = new Vector2(x, y);

            if (z < 0.05)
            {
                return(new WaterTile(vec));
            }
            if (z > 0.05 && z < 0.8)
            {
                return(new GrassTile(vec));
            }
            if (z > 0.8)
            {
                return(new StoneTile(vec));
            }

            return(new DirtTile(vec));
        }
예제 #11
0
        public INoiseMap <float> GenerateMap(int mapWidth = 512, int mapHeight = 512, float scale = 1, int seed = 0)
        {
            if (mapWidth <= 0)
            {
                throw new ArgumentException("mapWidth should be greater than 0");
            }
            if (mapHeight <= 0)
            {
                throw new ArgumentException("mapHeight should be greater than 0");
            }
            if (scale <= 0)
            {
                throw new ArgumentException("scale should be greater than 0");
            }

            var perlineNoiseSource = new SimplexPerlin
            {
                Seed    = seed,
                Quality = NoiseQuality.Fast
            };

            var noiseMap = new float[mapWidth, mapHeight];

            for (int y = 0; y < mapHeight; y++)
            {
                for (int x = 0; x < mapWidth; x++)
                {
                    var sampleX = x / scale;
                    var sampleY = y / scale;

                    var perlinValue = perlineNoiseSource.GetValue(sampleX, sampleY);
                    noiseMap[x, y] = perlinValue;
                }
            }
            return(new NoiseMap(MapWidth: mapWidth, MapHeight: mapHeight, Data: noiseMap));
        }
예제 #12
0
        private static float getRawNoise(ivec2 chunkPos, ivec2 blockPos, float scale, float frequency = 1f, float amplitude = 1f)
        {
            vec2 noisePos = (new vec2(chunkPos) + new vec2(blockPos) / 16f) * frequency / scale;

            return(glm.Clamp(_noiseGen.GetValue(noisePos.x, noisePos.y), -1, 1) * amplitude);
        }
예제 #13
0
 public override double Execute(double x, double y, double z, CallableNode flow)
 {
     return(simplex.GetValue(x * frequency, y * frequency, z * frequency) * scale);
 }