【问题标题】:How to modify perlin noise to generate a simple shape?如何修改柏林噪声以生成简单的形状?
【发布时间】:2020-05-04 14:38:15
【问题描述】:

我正在使用 Unity 进行一个项目,该项目需要生成一些简单的 3D 山脉/山丘。由于我的要求是创建一个“简单”的形状,我似乎没有找到答案,我想也许我可以从这里得到一些帮助。无论如何,this 是柏林噪声的正常输出,虽然它很平滑,但输出仍然很复杂,有很多山丘/山脉。我正在寻找类似 @​​987654322@ 的东西。我需要确保输出图像的边界周围没有任何高度。我想你已经明白了。祝你有美好的一天!

这是我现在使用的在线教程中的代码:

using UnityEngine;

public class PerlinNoise : MonoBehaviour
{
    private static int width = 256;
    private static int height = 128;
    public float scale = 20f;

    public float offsetX = 100f;
    public float offsetY = 100f;
    private int xcont = 0, ycont = 0;
    public float[,] array = new float[width,height];

    private void Start()
    {
        offsetX = Random.Range(0f, 99999f);
        offsetY = Random.Range(0f, 99999f);
    }
    void Update()
    {
        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = GenerateTexture();
    }



    Texture2D GenerateTexture()
    {
        Texture2D texture = new Texture2D(width, height);

        //GENERATE A PERLIN NOISE MAP FOR THE TEXTURE

        for(int x=0;x<width;x++)
        {
            for(int y=0;y<height;y++)
            {
                Color color = CalculateColor(x,y);
                texture.SetPixel(x, y, color);
            }
        }

        texture.Apply();

        return texture;
    }

    Color CalculateColor(int x, int y)
    {
        float xCoord = (float)x / width * scale + offsetX;
        float yCoord = (float)y / height * scale + offsetY;
        float sample = Mathf.PerlinNoise(xCoord,yCoord);
        if (xcont == width - 1)
        {
            xcont = 0;
            ycont++;
        } 
        else xcont++;

        if (ycont == height - 1 ) ycont = 0;

        array[xcont,ycont] = sample;
        return new Color(sample, sample, sample);
    }
}

【问题讨论】:

    标签: c# unity3d random shapes perlin-noise


    【解决方案1】:

    您可以使用元胞自动机过滤该纹理。 此播放列表可能会帮助您了解如何以及何时使用 Perlin Noise 来生成地图:https://www.youtube.com/playlist?list=PLFt_AvWsXl0eZgMK_DT5_biRkWXftAOf9

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-30
      • 2021-04-29
      • 2012-01-29
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 2017-11-04
      • 1970-01-01
      相关资源
      最近更新 更多