如何修改perlin噪声来生成一个简单的形状?

问题描述 投票:-1回答:1

我正在Unity中做一个项目,需要生成一些简单的3D MountainsHills。由于我的要求是创建一个 "简单 "的形状,我似乎没有找到答案,我想也许我可以从这里得到一些帮助。不管怎么说,我的要求是创建一个 "简单 "的形状,我似乎没有找到答案,我想也许我可以从这里得到一些帮助。这个 是perlin噪声的正常输出,虽然很流畅,但输出的内容还是很复杂,有很多山丘。我正在寻找类似 这个 . 我需要确保输出图像的边框不会有任何高度。我想你已经明白了。祝你有一个美好的一天

这是我现在使用的代码,来自一个在线教程。

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个回答
0
投票

你可以使用蜂窝自动机将该纹理过滤下来.这个播放列表可能会帮助你了解如何以及何时使用Perlin Noise来生成地图。https:/www.youtube.complaylist?list=PLFt_AvWsXl0eZgMK_DT5_biRkWXftAOf9

© www.soinside.com 2019 - 2024. All rights reserved.