/// <summary>
        /// Builds a noise texture
        /// </summary>
        /// <param name="parameters">Noise texture build parameters</param>
        public static unsafe Bitmap Build( NoiseBitmapBuilderParameters parameters )
        {
            if ( parameters == null )
            {
                throw new ArgumentNullException( "parameters" );
            }
            Bitmap bmp = new Bitmap( parameters.BitmapWidth, parameters.BitmapHeight, PixelFormat.Format24bppRgb );

            FastNoise noise = new FastNoise( );

            BitmapData bmpData = bmp.LockBits( new Rectangle( 0, 0, bmp.Width, bmp.Height ), ImageLockMode.WriteOnly, bmp.PixelFormat );

            byte* pixels = ( byte* )bmpData.Scan0;

            if ( parameters.GenerationType == NoiseGenerationType.Grayscale )
            {
                noise.GenerateTiledBitmap( bmp.Width, bmp.Height, 3, pixels, parameters.NoiseX, parameters.NoiseY, parameters.NoiseWidth, parameters.NoiseHeight );
                noise.GenerateTiledBitmap( bmp.Width, bmp.Height, 3, pixels + 1, parameters.NoiseX, parameters.NoiseY, parameters.NoiseWidth, parameters.NoiseHeight );
                noise.GenerateTiledBitmap( bmp.Width, bmp.Height, 3, pixels + 2, parameters.NoiseX, parameters.NoiseY, parameters.NoiseWidth, parameters.NoiseHeight );
            }
            else if ( parameters.GenerationType == NoiseGenerationType.MultiChannel )
            {
                noise.GenerateTiledBitmap( bmp.Width, bmp.Height, 3, pixels, parameters.NoiseX, parameters.NoiseY, parameters.NoiseWidth, parameters.NoiseHeight );
                noise.GenerateTiledBitmap( bmp.Width, bmp.Height, 3, pixels + 1, parameters.NoiseX + parameters.NoiseWidth, parameters.NoiseY, parameters.NoiseWidth, parameters.NoiseHeight );
                noise.GenerateTiledBitmap( bmp.Width, bmp.Height, 3, pixels + 2, parameters.NoiseX + parameters.NoiseWidth * 2, parameters.NoiseY, parameters.NoiseWidth, parameters.NoiseHeight );
            }
            else
            {
                throw new NotImplementedException( "Unsupported generation type " + parameters.GenerationType );
            }

            bmp.UnlockBits( bmpData );
            return bmp;
        }
    void Start()
    {
        _flowFieldDirection = new Vector3[_gridSize.x, _gridSize.y, _gridSize.z];
        _fastNoise          = new FastNoise();
        _particles          = new List <FlowFieldParticle>();

        for (int i = 0; i < _amountOfParticles; i++)
        {
            int attempt = 0;

            while (attempt < 100)
            {
                Vector3 randomPos = new Vector3(
                    Random.Range(this.transform.position.x, this.transform.position.x + _gridSize.x * _cellSize),
                    Random.Range(this.transform.position.y, this.transform.position.y + _gridSize.y * _cellSize),
                    Random.Range(this.transform.position.z, this.transform.position.z + _gridSize.z * _cellSize));

                bool isValid = _particleSpwanValidation(randomPos);

                if (isValid)
                {
                    GameObject particleInstance = (GameObject)Instantiate(_particlePrefab);
                    particleInstance.transform.position   = randomPos;
                    particleInstance.transform.parent     = this.transform;
                    particleInstance.transform.localScale = new Vector3(_particleScale, _particleScale, _particleScale);
                    _particles.Add(particleInstance.GetComponent <FlowFieldParticle>());
                    break;
                }
                if (!isValid)
                {
                    attempt++;
                }
            }
        }
        Debug.Log(_particles.Count);
    }
Ejemplo n.º 3
0
 public OpenSimplex2() : base()
 {
     _genID = FastNoise.API_CreateOpenSimplex2();
 }
Ejemplo n.º 4
0
        private bool GenerateOres(int x, int y, int z, FastNoise noise)
        {
            int worldX = PositionX + x;
            int worldZ = PositionZ + z;

            float ore1 = noise.GetPerlin(worldX * 15f, y * 15f, worldZ * 15f + 300);
            float ore2 = noise.GetPerlin(worldX * 15f, y * 15f, worldZ * 15f + 400);


            if (ore1 > 0.3 && ore2 > 0.4)
            {
                m_Data.SetBlockType(x, y, z, BlockType.Diorite);
                return(true);
            }
            if (ore1 < -0.3 && ore2 < -0.4)
            {
                m_Data.SetBlockType(x, y, z, BlockType.Granite);
                return(true);
            }

            if (ore1 > 0.3 && ore2 < -0.4)
            {
                m_Data.SetBlockType(x, y, z, BlockType.Dirt);
                return(true);
            }


            float ore3 = noise.GetPerlin(worldX * 20f, y * 20f, worldZ * 20f + 500);

            if (ore1 < -0.3 && ore3 > 0.4)
            {
                m_Data.SetBlockType(x, y, z, BlockType.Coal);
                return(true);
            }

            float ore4 = noise.GetPerlin(worldX * 21f, y * 21f, worldZ * 21f - 300);

            if (ore4 > 0.6)
            {
                m_Data.SetBlockType(x, y, z, BlockType.Iron);
                return(true);
            }

            if (y < 32)
            {
                float ore5 = noise.GetPerlin(worldX * 22f, y * 22f, worldZ * 22f - 400);

                if (ore5 > 0.7)
                {
                    m_Data.SetBlockType(x, y, z, BlockType.Gold);
                    return(true);
                }
                if (y < 16)
                {
                    if (ore5 < -0.7)
                    {
                        m_Data.SetBlockType(x, y, z, BlockType.Diamond);
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        public void Init(int posX, int posZ, int seed, WorldType type)
        {
            PositionX = posX;
            PositionZ = posZ;

            Random    random     = new Random(seed);
            FastNoise noise      = new FastNoise(seed);
            int       waterLevel = 66;

            // 地形生成代码借用 https://github.com/bodhid/MineClone-Unity

            for (int dx = 0; dx < ChunkWidth; dx++)
            {
                for (int dz = 0; dz < ChunkWidth; dz++)
                {
                    switch (type)
                    {
                    case WorldType.Normal:
                    case WorldType.Fixed:
                    {
                        int x = posX + dx;
                        int z = posZ + dz;

                        int   bottomHeight = 0;
                        float hills        = noise.GetPerlin(x * 4f + 500, z * 4f) * 0.5f + 0.5f;

                        int   hillHeight    = (int)(BaseHeight + (hills * 16));
                        float bedrock       = noise.GetPerlin(x * 64f, z * 64f) * 0.5f + 0.5f;
                        int   bedrockHeight = (int)(1 + bedrock * 4);

                        for (int y = 0; y < WorldHeight; y++)
                        {
                            if (y > hillHeight || y < bottomHeight)
                            {
                                if (y < waterLevel)
                                {
                                    m_Data.SetBlockType(dx, y, dz, BlockType.Water);
                                }
                                else
                                {
                                    m_Data.SetBlockType(dx, y, dz, BlockType.Air);

                                    if (y == hillHeight + 1 && m_Data.GetBlockType(dx, y - 1, dz) == BlockType.Grass)
                                    {
                                        int r = random.Next(0, 50);

                                        if (r == 1)
                                        {
                                            m_Data.SetBlockType(dx, y, dz, BlockType.Plant_Grass);
                                        }
                                        else
                                        {
                                            r = random.Next(0, 150);

                                            if (r == 1)
                                            {
                                                m_Data.SetBlockType(dx, y, dz, BlockType.Flower_Rose_Blue);
                                            }
                                        }
                                    }
                                }
                                continue;
                            }

                            if (y < bedrockHeight)
                            {
                                m_Data.SetBlockType(dx, y, dz, BlockType.Bedrock);
                                continue;
                            }

                            if (y > hillHeight - 4)
                            {
                                if (GenerateCaves(dx, y, dz, x, z, 0.2f, noise))
                                {
                                    continue;
                                }

                                if (y == hillHeight)
                                {
                                    if (y < waterLevel - 1)
                                    {
                                        int r = random.Next(0, 100);

                                        if (r == 1)
                                        {
                                            m_Data.SetBlockType(dx, y, dz, BlockType.Dirt);
                                        }
                                        else
                                        {
                                            m_Data.SetBlockType(dx, y, dz, BlockType.Sand);
                                        }
                                    }
                                    else
                                    {
                                        m_Data.SetBlockType(dx, y, dz, BlockType.Grass);
                                    }
                                }
                                else
                                {
                                    m_Data.SetBlockType(dx, y, dz, BlockType.Dirt);
                                }

                                continue;
                            }
                            else
                            {
                                if (GenerateCaves(dx, y, dz, x, z, 0f, noise))
                                {
                                    continue;
                                }

                                if (GenerateOres(dx, y, dz, noise))
                                {
                                    continue;
                                }

                                m_Data.SetBlockType(dx, y, dz, BlockType.Stone);
                                continue;
                            }
                        }
                    }
                    break;

                    case WorldType.Plain:
                    {
                        for (int y = 0; y < WorldHeight; y++)
                        {
                            switch (y)
                            {
                            case 0:
                                m_Data.SetBlockType(dx, y, dz, BlockType.Bedrock);
                                break;

                            case 1:
                            case 2:
                                m_Data.SetBlockType(dx, y, dz, BlockType.Dirt);
                                break;

                            case 3:
                                m_Data.SetBlockType(dx, y, dz, BlockType.Grass);
                                break;

                            default:
                                m_Data.SetBlockType(dx, y, dz, BlockType.Air);
                                break;
                            }
                        }
                    }
                    break;
                    }
                }
            }

            if (type != WorldType.Plain)
            {
                bool[,] spotsTaken = new bool[16, 16];

                //cave entrances
                if (random.Next() < (int.MaxValue / 20))
                {
                    int h = WorldHeight - 1;

                    while (h-- > 0)
                    {
                        if (m_Data.GetBlockType(8, h, 8) != BlockType.Air)
                        {
                            Queue <Vector3Int> path = new Queue <Vector3Int>();
                            int depth = random.Next(5, 11);

                            for (int i = 0; i < depth; i++)
                            {
                                path.Enqueue(new Vector3Int(random.Next(2, 13), 44 - (i * 4), random.Next(2, 13)));
                            }

                            float      d       = 0;
                            Vector3Int nextPos = path.Dequeue();

                            while (path.Count > 0)
                            {
                                Vector3Int currentPos = nextPos;
                                nextPos = path.Dequeue();
                                float size = Mathf.Lerp(2, 0.75f, d / depth);

                                for (int i = 0; i < 16; ++i)
                                {
                                    float      lerpPos = i / 15f;
                                    Vector3    lerped  = Vector3.Lerp(currentPos, nextPos, lerpPos);
                                    Vector3Int p       = new Vector3Int((int)lerped.x, (int)lerped.y, (int)lerped.z);

                                    for (int z = -2; z < 3; ++z)
                                    {
                                        for (int y = -2; y < 3; ++y)
                                        {
                                            for (int x = -2; x < 3; ++x)
                                            {
                                                Vector3Int b = new Vector3Int(p.x + x, p.y + y, p.z + z);

                                                if (Vector3Int.Distance(p, b) > size)
                                                {
                                                    continue;
                                                }

                                                if (b.x < 0 || b.x > ChunkWidth - 1)
                                                {
                                                    continue;
                                                }

                                                if (b.y < 0 || b.y > 47)
                                                {
                                                    continue;
                                                }

                                                if (b.z < 0 || b.z > ChunkWidth - 1)
                                                {
                                                    continue;
                                                }

                                                int ry = b.y + h + 6 - 48;

                                                if (ry < 0 || ry > ChunkWidth - 1)
                                                {
                                                    continue;
                                                }

                                                m_Data.SetBlockType(b.x, ry, b.z, BlockType.Air);
                                            }
                                        }
                                    }
                                }
                                d++;
                            }
                            break;
                        }
                    }
                }

                //trees
                for (int y = 2; y < 14; ++y)
                {
                    for (int x = 2; x < 14; ++x)
                    {
                        if (random.Next() < (int.MaxValue / 100))
                        {
                            if (IsSpotFree(spotsTaken, new Vector2Int(x, y), 2))
                            {
                                spotsTaken[x, y] = true;
                                int h = WorldHeight - 1;

                                while (h-- > 0)
                                {
                                    if (m_Data.GetBlockType(x, h, y) == BlockType.Grass)
                                    {
                                        Vector3Int p = new Vector3Int(x, h + 1, y);

                                        m_Data.SetBlockType(p.x, p.y - 1, p.z, BlockType.Dirt);
                                        bool cutOff = random.Next(100) == 0;

                                        if (cutOff)
                                        {
                                            m_Data.SetBlockType(p.x, p.y, p.z, BlockType.Log_Oak);
                                            goto End;
                                        }

                                        int  height    = (byte)random.Next(4, 7);
                                        bool superHigh = random.Next(100) == 0;
                                        if (superHigh)
                                        {
                                            height = 10;
                                        }

                                        for (int i = 0; i < height; ++i)
                                        {
                                            m_Data.SetBlockType(p.x, p.y + i, p.z, BlockType.Log_Oak);
                                        }
                                        m_Data.SetBlockType(p.x, p.y + height, p.z, BlockType.Leaves_Oak);

                                        for (int i = 0; i < 4; ++i)
                                        {
                                            m_Data.SetBlockType(p.x + 1, p.y + height - i, p.z, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x, p.y + height - i, p.z + 1, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x - 1, p.y + height - i, p.z, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x, p.y + height - i, p.z - 1, BlockType.Leaves_Oak);
                                        }

                                        if (random.Next(0, 2) == 0)
                                        {
                                            m_Data.SetBlockType(p.x + 1, p.y + height - 1, p.z + 1, BlockType.Leaves_Oak);
                                        }
                                        if (random.Next(0, 2) == 0)
                                        {
                                            m_Data.SetBlockType(p.x - 1, p.y + height - 1, p.z + 1, BlockType.Leaves_Oak);
                                        }
                                        if (random.Next(0, 2) == 0)
                                        {
                                            m_Data.SetBlockType(p.x + 1, p.y + height - 1, p.z - 1, BlockType.Leaves_Oak);
                                        }
                                        if (random.Next(0, 2) == 0)
                                        {
                                            m_Data.SetBlockType(p.x - 1, p.y + height - 1, p.z - 1, BlockType.Leaves_Oak);
                                        }

                                        for (int i = 2; i < 4; ++i)
                                        {
                                            m_Data.SetBlockType(p.x + 2, p.y + height - i, p.z - 1, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 2, p.y + height - i, p.z + 0, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 2, p.y + height - i, p.z + 1, BlockType.Leaves_Oak);

                                            m_Data.SetBlockType(p.x - 2, p.y + height - i, p.z - 1, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x - 2, p.y + height - i, p.z + 0, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x - 2, p.y + height - i, p.z + 1, BlockType.Leaves_Oak);

                                            m_Data.SetBlockType(p.x - 1, p.y + height - i, p.z + 2, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 0, p.y + height - i, p.z + 2, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 1, p.y + height - i, p.z + 2, BlockType.Leaves_Oak);

                                            m_Data.SetBlockType(p.x - 1, p.y + height - i, p.z - 2, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 0, p.y + height - i, p.z - 2, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 1, p.y + height - i, p.z - 2, BlockType.Leaves_Oak);

                                            m_Data.SetBlockType(p.x + 1, p.y + height - i, p.z + 1, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x - 1, p.y + height - i, p.z + 1, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x + 1, p.y + height - i, p.z - 1, BlockType.Leaves_Oak);
                                            m_Data.SetBlockType(p.x - 1, p.y + height - i, p.z - 1, BlockType.Leaves_Oak);

                                            if (random.Next(0, 2) == 0)
                                            {
                                                m_Data.SetBlockType(p.x + 2, p.y + height - i, p.z + 2, BlockType.Leaves_Oak);
                                            }
                                            if (random.Next(0, 2) == 0)
                                            {
                                                m_Data.SetBlockType(p.x - 2, p.y + height - i, p.z + 2, BlockType.Leaves_Oak);
                                            }
                                            if (random.Next(0, 2) == 0)
                                            {
                                                m_Data.SetBlockType(p.x + 2, p.y + height - i, p.z - 2, BlockType.Leaves_Oak);
                                            }
                                            if (random.Next(0, 2) == 0)
                                            {
                                                m_Data.SetBlockType(p.x - 2, p.y + height - i, p.z - 2, BlockType.Leaves_Oak);
                                            }
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }

End:
            GenerateOtherInitialDataAndLightBlocks();
            GenerateSkyLightData();
        }
Ejemplo n.º 6
0
 public MaxSmooth() : base()
 {
     _generator = new FastNoise("MaxSmooth");
 }
 private FastNoise InitalizeNoise()
 {
     noise = new FastNoise(Random.Range(-77777, 77777));
     noise.SetNoiseType(type);
 }
        public override void OnInspectorGUI()
        {
            EditorGUI.BeginChangeCheck();
            isolevel     = EditorGUILayout.FloatField("Iso Level", isolevel);
            automatic    = EditorGUILayout.Toggle("Automatic", automatic);
            terrainShape = GUILayout.Toolbar(terrainShape, terrainShapes);
            switch (terrainShape)
            {
            case 0:
                noiseScale = EditorGUILayout.FloatField("Noise Scale", noiseScale);
                seed       = EditorGUILayout.IntField("Seed", seed);
                height     = EditorGUILayout.FloatField("Height", height);
                center     = EditorGUILayout.Vector3Field("Offset", center);
                if (GUILayout.Button(terrain.initialized ? "Update" : "Initialize") || (EditorGUI.EndChangeCheck() && automatic))
                {
                    if (!terrain.initialized)
                    {
                        terrain.Initialize(new Vector3Int(5, 5, 5), 8, isolevel);
                    }
                    FastNoise noise = new FastNoise(seed);
                    terrain.Generate(x => GenerateNoise(x, noise), true);
                }
                break;

            case 1:
                center = EditorGUILayout.Vector3Field("Center", center);
                radius = EditorGUILayout.FloatField("Radius", radius);
                if (GUILayout.Button(terrain.initialized ? "Update" : "Initialize") || (EditorGUI.EndChangeCheck() && automatic))
                {
                    if (!terrain.initialized)
                    {
                        terrain.Initialize(new Vector3Int(5, 5, 5), 8, isolevel);
                    }
                    terrain.Generate(GenerateSphere, true);
                }
                break;

            case 2:
                height = EditorGUILayout.FloatField("Height", height);
                if (GUILayout.Button(terrain.initialized ? "Update" : "Initialize") || (EditorGUI.EndChangeCheck() && automatic))
                {
                    if (!terrain.initialized)
                    {
                        terrain.Initialize(new Vector3Int(5, 5, 5), 8, isolevel);
                    }
                    terrain.Generate(GenerateFlat, true);
                }
                break;

            case 3:
                center = EditorGUILayout.Vector3Field("Center", center);
                radius = EditorGUILayout.FloatField("Radius", radius);
                if (GUILayout.Button(terrain.initialized ? "Update" : "Initialize") || (EditorGUI.EndChangeCheck() && automatic))
                {
                    if (!terrain.initialized)
                    {
                        terrain.Initialize(new Vector3Int(5, 5, 5), 8, isolevel);
                    }
                    terrain.Generate(GenerateCube, true);
                }
                break;
            }
            if (terrain.initialized)
            {
                if (GUILayout.Button("Deinitialize"))
                {
                    terrain.Deinitialize();
                }
            }
        }
Ejemplo n.º 9
0
 public CellularValue() : base()
 {
     _genID = FastNoise.API_CreateCellularValue();
 }
Ejemplo n.º 10
0
        public static float GetFractalWarpedRiversNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            float   sum = 0f;
            float   freq = 1.0f, amp = 1.0f;
            Vector2 sum_warp = new Vector2(0, 0);
            Vector2 dsum     = new Vector2(0, 0);

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                Vector3 n = GetDerivativePerlinNoise(position * freq + sum_warp, noise, seed + i);
                dsum     += new Vector2(n.y, n.z);
                sum      += amp * n.x / (1 + Vector2.Dot(dsum, dsum));
                sum_warp += new Vector2(dsum.x * (1 / freq), dsum.y * (0.7f / freq));
                freq     *= noiseParameters.lacunarity;
                amp      *= noiseParameters.gain;
            }
            return(sum);
        }
Ejemplo n.º 11
0
 public static float GetFractalInverseErosionNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
 {
     return(1f - GetFractalErosionNoise(position, noiseParameters, noise, seed) - 1f);
 }
Ejemplo n.º 12
0
        public static float GetFractalErosionRidgedNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            float   sum = 0f;
            float   freq = 1.0f, amp = 1.0f;
            Vector2 dsum = new Vector2(0, 0);

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                Vector3 n = GetDerivativePerlinNoise(position * freq, noise, seed + i);
                n.x = ((1f - MathFunc.Abs(n.x)) * 2f - 1);
                n.y = ((1f - MathFunc.Abs(n.y)) * 2f - 1);
                n.z = ((1f - MathFunc.Abs(n.z)) * 2f - 1);
                //n.x = 1f-MathFunc.PingPong(n.x,0.5f)*2f;
                //n.y = 1f-MathFunc.PingPong(n.y,0.5f)*2f;
                //n.z = 1f-MathFunc.PingPong(n.z,0.5f)*2f;
                //n.x = MathFunc.Pow(n.x,2);

                dsum += new Vector2(n.y, n.z);
                sum  += amp * n.x / (1 + Vector2.Dot(dsum, dsum));
                freq *= noiseParameters.lacunarity;
                amp  *= noiseParameters.gain;
            }
            return(sum);
        }
Ejemplo n.º 13
0
        public static float GetFractalRidgedNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            float sum = 0f;
            float freq = 1.0f, amp = 1.0f;

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                float n = GetNoise(position * freq, noise, seed + i);
                n = ((1f - MathFunc.Abs(n)) * 2f - 1);
                //n = MathFunc.PingPong(n,0.5f)*2f;
                sum  += amp * n;
                freq *= noiseParameters.lacunarity;
                amp  *= noiseParameters.gain;
            }
            return(sum);
        }
Ejemplo n.º 14
0
        public static float GetFractalNoise(Vector2 p, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            noise.SetSeed(seed);
            float sum = 0f;
            float amp = 1.0f;

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                noise.SetSeed(seed + i);
                float n = noise.GetPerlin(p.x, p.y);

                sum += n * amp;
                p   *= noiseParameters.lacunarity;
                amp *= noiseParameters.gain;
            }
            return(sum);
        }
Ejemplo n.º 15
0
        public static float GetLunarNoise(Vector2 p, float CraterSize, float CraterHeight, float CraterDepth, FastNoise noise, int seed = 0)                                                          //crater size: 0.86, crater height: 0.2, crater depth: 2.5
        {
            float n = MathFunc.InverseLerp(CraterSize, 1f, MathFunc.Clamp((1f - OTNM.Tools.Accessing.GetCellularNoise(new XnaGeometry.Vector2(p.x, p.y), CraterSize, noise, seed)), CraterSize, 1f)); //0.36

            if (n > CraterHeight)
            {
                n += (CraterHeight - n) * CraterDepth;
            }
            return(n);
        }
Ejemplo n.º 16
0
 public Noise()
 {
     fastNoise = new FastNoise();
 }
Ejemplo n.º 17
0
        public static float GetFractalPlainNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            float   sum = 0f;
            float   freq = 1.0f, amp = 1.0f;
            float   derivative_sum = 1.0f;
            Vector2 dsum           = new Vector2(0, 0);

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                Vector3 n = GetDerivativePerlinNoise(position * freq, noise, seed + i);
                derivative_sum = (1f - ((Math.Abs(n.y) + Math.Abs(n.z)) * 0.5f)) * sum;
                dsum          += new Vector2(n.y, n.z) * (derivative_sum * 5f);
                sum           += amp * n.x / (1 + Vector2.Dot(dsum, dsum));
                freq          *= noiseParameters.lacunarity;
                amp           *= noiseParameters.gain;
            }
            return(sum);
        }
Ejemplo n.º 18
0
    public override object GetValue(NodeSocket socket)
    {
        FastNoise noiseGenerator = new FastNoise();

        return(noiseGenerator.GetWhiteNoise(GetInputValue <float>("x"), GetInputValue <float>("y"), GetInputValue <float>("z")));
    }
Ejemplo n.º 19
0
        public static float GetFractalAlpsNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, int seed = 0)
        {
            float   warp = 1.5f;
            float   sum = 0f;
            float   freq = 1.0f, amp = 1.0f;
            Vector2 dsum = new Vector2(0, 0);

            for (int i = 0; i < noiseParameters.octaves; i++)
            {
                Vector3 n = GetDerivativePerlinNoise(position * freq, noise, seed + i);
                sum  += amp * (1 - MathFunc.Abs(n.x));
                dsum += amp * new Vector2(n.y, n.z) * -n.x;
                freq *= noiseParameters.lacunarity;
                amp  *= noiseParameters.gain * MathFunc.Clamp01(sum);
            }
            return(sum);
        }
 public float GenerateNoise(Vector3Int pos, FastNoise noise)
 {
     return((center.y - pos.y) + noise.GetPerlin((center.x - pos.x) / noiseScale, (center.z - pos.z) / noiseScale) * height);
 }
Ejemplo n.º 21
0
        public static float GetCanyonNoise(Vector2 position, NoiseParameters noiseParameters, FastNoise noise, CanyonParameters canyonParameters, int seed = 0)
        {
            //Noise Height, Value bettween CayonParameters's limits, Results
            float n  = 1.0f - GetFractalErosionNoise(position, noiseParameters, noise, seed);
            float n2 = MathFunc.Clamp01(MathFunc.Lerp(0f, 1f, MathFunc.InverseLerp(canyonParameters.minCanyonHeight, canyonParameters.canyonPlateauHeight, n)));
            float h  = 0f;
            float t  = (canyonParameters.canyonPlateauHeight - canyonParameters.minCanyonHeight);

            if (n <= canyonParameters.canyonPlateauHeight)
            {
                if (n >= canyonParameters.minCanyonHeight)
                {
                    h = canyonParameters.GetValueAtHeight(n2);
                    return(h);
                }
                else
                {
                    return(canyonParameters.minCanyonHeight - n * -3f);
                }
            }
            else
            {
                //h = (n*(canyonParameters.canyonPlateauHeight-canyonParameters.minCanyonHeight)/2f)+1f;
                //h = (n-t)*0.2f+t;
                float x = 1f;
                //h = (n)*x+(t*(x*2)+0);
                h = 1 + (n - canyonParameters.canyonPlateauHeight) * 0.2f;
                return(h);
            }
        }
 public DomainWarpFractalIndependent() : base()
 {
     _generator = new FastNoise("DomainWarpFractalIndependant");
 }
Ejemplo n.º 23
0
 public CellularDistance() : base()
 {
     _generator = new FastNoise("CellularDistance");
 }
Ejemplo n.º 24
0
 public Elevation(int seed = 0)
 {
     Noise = new FastNoise(seed);
 }
Ejemplo n.º 25
0
 public White() : base()
 {
     _genID = FastNoise.API_CreateWhite();
 }
Ejemplo n.º 26
0
        private bool GenerateCaves(int x, int y, int z, int rx, int rz, float threshold, FastNoise noise)
        {
            float cave1 = noise.GetPerlin(rx * 10f - 400, y * 10f, rz * 10f);
            float cave2 = noise.GetPerlin(rx * 20f - 600, y * 20f, rz * 20f);
            float cave3 = noise.GetPerlin(rx * 5f - 200, y * 5f, rz * 5f);
            float cave4 = noise.GetPerlin(rx * 2f - 300, y * 2f, rz * 2f);
            float cave  = Mathf.Min(Mathf.Min(cave1, cave4), Mathf.Min(cave2, cave3));

            if (cave > threshold)
            {
                m_Data.SetBlockType(x, y, z, BlockType.Air);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 27
0
 public DomainWarpGradient() : base()
 {
     _generator = new FastNoise("DomainWarpGradient");
 }
Ejemplo n.º 28
0
 public CellularLookup() : base()
 {
     _generator = new FastNoise("CellularLookup");
 }
Ejemplo n.º 29
0
 public Divide() : base()
 {
     _generator = new FastNoise("Divide");
 }
Ejemplo n.º 30
0
 public DomainWarpFractalIndependent() : base()
 {
     _type  = FractalTypes.DomainWarpIndependent;
     _genID = FastNoise.API_CreateDomainWarpFractalIndependent();
 }
Ejemplo n.º 31
0
 public AddDimension() : base()
 {
     _genID = FastNoise.API_CreateAddDimension();
 }