在类似Minecraft的游戏中悬崖地形生成

Vla*_*lad 8 c# procedural-generation perlin-noise

我想生成这样的东西: 悬崖
我使用锐利曲线的Perlin Noise,我的代码产生了那些悬崖: 我的悬崖 .

    for (int x = 0; x < sizeX; x++)
    {
        for (int z = 0; z < sizeZ; z++)
        {
            int floorY = map.GetMaxYNotWater(x, z);
            float n = hillsNoise.Noise(x, z);
            int hillY = (int)(curveHills.Evaluate(n) * 80f);
            if (hillY > floorY + 5)
            {
                for (int y = hillY; y > floorY; y--)
                {
                    map.SetBlock(GetBlock(y), new Vector3i(x, y, z));
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我如何"剪切"它们以制作挂件?

我尝试用额外的曲线这样做:

    for (int x = 0; x < sizeX; x++)
    {
        for (int z = 0; z < sizeZ; z++)
        {
            int floorY = map.GetMaxYNotWater(x, z);
            float n = hillsNoise.Noise(x, z);
            int hillY = (int)(curveHills.Evaluate(n) * 80f);
            if (hillY > floorY + 5)
            {
                int c = 0;
                int max = hillY - floorY;
                max = (int)(max * curveHillsFull.Evaluate(n)) + 1;
                for (int y = hillY; y > floorY && c < max; y--, c++)
                {
                    map.SetBlock(GetBlock(y), new Vector3i(x, y, z));
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

但它会产生飞行岛屿. 飞岛 那么我该怎么做才能实现第一个截图结果呢?

Qua*_*sar 2

我不能说 Minecraft 是如何做到的,但根据我自己对体素地形的经验,处理它的最佳方法是将体素网格视为像云一样的东西:每个体素都有一个密度,当密度很高时足够了,它成为云的“可见”部分,并且您填充体素。

因此,不要计算最小和最大 Y 级别,而是计算密度值,如下所示:

    for (int x = 0; x < sizeX; x++)
    {
        for (int y = 0; y > sizeY; y--)
        {
            for (int z = 0; z < sizeZ; z++)
            {
                //This means less density at higher elevations, great for turning 
                //a uniform cloud into a terrain. Multiply this for flatter worlds
                float flatWorldDensity = y;

                //This calculates 3d Noise: you will probably have to tweak this 
                //heavily. Multiplying input co-ordinates will allow you to scale 
                //terrain features, while multiplying the noise itself will make the 
                //features stronger and more or less apparent
                float xNoise = hillsNoise.Noise(x, y);
                float yNoise = hillsNoise.Noise(x, z);
                float zNoise = hillsNoise.Noise(y, z);
                float 3dNoiseDensity = (xNoise + yNoise + zNoise) / 3;

                //And this adds them together. Change the constant "1" to get more or
                //less land material. Simple!
                float ActualDensity = flatWorldDensity + 3dNoiseDensity;
                if (ActualDensity > 1)
                {
                    map.SetBlock(GetBlock(y), new Vector3i(x, y, z));
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)