Exemple #1
0
    /// <summary>
    /// Generates a Biome at a given position
    /// </summary>
    /// <param name="pos">The position to sample the biome field, in world space.</param>
    /// <returns>A Biome object with data about which biome inhabits this space.</returns>
    public static Biome AtLocation(Vector3 pos)
    {
        pos /= VoxelUniverse.main.biomeScaling;

        // SAMPLE 1 noisefield at 3 arbitrary locations:
        Vector3 offsetR = new Vector3(123, 456, 789);
        Vector3 offsetG = new Vector3(-99, 999, 300);
        Vector3 offsetB = new Vector3(900, 500, -99);
        float   r       = Noise.Sample(pos + offsetR);
        float   g       = Noise.Sample(pos + offsetG);
        float   b       = Noise.Sample(pos + offsetB);

        // TODO: redo/improve the calculations below

        // convert values from approx. (-.2 to .2) to (-1.1 to 1.1):
        r *= 5.5f;
        g *= 5.5f;
        b *= 5.5f;
        // redistribute values non-linearly:
        r *= r;
        g *= g;
        b *= b;
        // shift range from (+- 1.21) to (+- .5):
        r /= 2.4f;
        g /= 2.4f;
        b /= 2.4f;
        // shift from range from (+- .5) to (0 to 1):
        r += .5f;
        g += .5f;
        b += .5f;

        // Convert from RGB to HSV:
        Color.RGBToHSV(new Color(r, g, b), out float h, out float s, out float v);

        //posterize the hue value:
        h = Mathf.Round(h * Biome.COUNT);
        int biome_num = (int)h;

        // create and return the biome:
        return(Biome.FromInt(biome_num));
    }