【问题标题】:Calculation island error with perlin noise使用 perlin 噪声计算孤岛误差
【发布时间】:2019-05-26 13:58:10
【问题描述】:

我正在开发一个小项目,它是一个由 100 x 100 六边形组成的网格。 在下面的脚本中,我用柏林噪声绘制了我的六边形,但我想要孤岛的格式并没有消失。 我会留下我的代码和 2 个示例,因为我的地图会保留以及我希望它保留的方式。

我的岛

My Island

根据需要

Im Need

int getColor(float x, float z)
{
    xTO = (int)x / terrainWidth - 30;
    zTO = (int)z / terrainHeight - 30;

    float v = Mathf.PerlinNoise((xTO + x + seed) * freq, (zTO + z) * freq);
    //  v += 0.001f;

    float form = formWorld(x, z);


    if (v < 0.25f)
    {
        //water
        return 0;
    }
    else if (v < 0.5f)
    {
        //sand
        return 1;
    }

    else if (v < 0.75f)
    {
        //grass
        return 2;
    }
    else
    {
        //Trees / Forest
        MakeNewTree(new Vector3(xx, 0, z * 7.5f));
        return 2;
    }
}

【问题讨论】:

    标签: c# unity3d perlin-noise


    【解决方案1】:

    如果您希望您的图像看起来更像第二张,最好的选择是添加一个圆形渐变来抵消您的 Perlin Noise。

    最简单的方法是测量到中心的距离并将其与柏林噪声相结合。

    这是一些未经测试的代码。

        int getColor(float x, float z)
        {
            xTO = (int)x / terrainWidth - 30;
            zTO = (int)z / terrainHeight - 30;
    
            float v = Mathf.PerlinNoise((xTO + x + seed) * freq, (zTO + z) * freq);
            //  v += 0.001f;
            v -= CircleOffset(x,z)/2; //Change the two to make the island bigger.
    
            float form = formWorld(x, z);
    
    
            if (v < 0.25f)
            {
                //water
                return 0;
            }
            else if (v < 0.5f)
            {
                //sand
                return 1;
            }
    
            else if (v < 0.75f)
            {
                //grass
                return 2;
            }
            else
            {
                //Trees / Forest
                MakeNewTree(new Vector3(xx, 0, z * 7.5f));
                return 2;
            }
        }
    
        float CircleOffset(float x, float y)
        {
            Vector2 center = new Vector2(terrainWidth/2,terrainHeight/2);
            float distance = Mathf.Sqrt((center.x - x)*(center.x - x) + (center.y - y) * (center.y - y));
            return distance/terrainWidth;
        }
    

    希望这会有所帮助!

    【讨论】:

    • 不幸的是结果不如预期,我留下了一个链接显示发生了什么。 imgur.com/a/D5kzrnZ
    猜你喜欢
    • 2011-03-19
    • 2018-02-14
    • 1970-01-01
    • 2014-02-15
    • 2020-06-06
    • 2011-09-20
    • 2021-06-30
    • 2013-07-23
    • 2020-06-22
    相关资源
    最近更新 更多