コード例 #1
0
ファイル: NoiseGenerator.cs プロジェクト: Shadow229/PGT
    //fractal brownian motion to create more realistic terrain
    public float FBM(Vector3 vec)
    {
        float Frequency = NoiseScale / 100f;
        float Amplitude = 1;
        float weight    = 1f;
        float noise     = 0;

        // float offsetRange = 1000;

        for (int i = 0; i < Octaves; i++)
        {
            //Passing in a seeded offset at octave level causes mesh issues not seen on the GPU - removed from both functions to match terrains up
            ///Vector3 OctaveOffset = new Vector3((float)rnd.NextDouble() * 2 - 1, (float)rnd.NextDouble() * 2 - 1, (float)rnd.NextDouble() * 2 - 1) * 1000;

            float f = PerlinNoise.CNoise(vec * Frequency + Offset);
            float v = 1 - Mathf.Abs(f);
            v         *= v;
            v         *= weight;
            weight     = Mathf.Max(Mathf.Min(v * WeightMultiplier, 1), 0);
            noise     += v * Amplitude;
            Amplitude *= Persistence;
            Frequency *= Lacunarity;
        }

        float c = -(vec.y + FloorOffset) + (noise * NoiseWeight);

        if (vec.y < HardFloor)
        {
            c += HardFloorWeight;
        }

        return(c);
    }