예제 #1
0
    public void UpdateNoise()
    {
        if (generators == null || generators.Length != Octaves)
        {
            generators = new SgtSimplex[Octaves];
        }

        var weight = 1.0f;
        var total  = 0.0f;

        for (var i = 0; i < Octaves; i++)
        {
            var generator = generators[i];

            if (generator == null)
            {
                generator = generators[i] = new SgtSimplex();
            }

            generator.SetSeed(Seed + i * 999);

            total  += weight;
            weight *= 0.5f;
        }

        if (total > 0.0f)
        {
            scale = 1.0f / total;
        }
        else
        {
            scale = 1.0f;
        }
    }
    private void OnCalculateHeight(Vector3 localPosition, ref float height)
    {
        localPosition = localPosition.normalized * Scale;

        height += SgtSimplex.Generate(localPosition.x, localPosition.y, localPosition.z) * Strength;
    }