Я работаю над проектом в Unity, который должен создать несколько простых 3D-гор/холмов. Поскольку мои требования заключаются в создании «простой» формы, я, похоже, не нашел ответа и подумал, что, может быть, мне здесь помогут. В любом случае, это нормальный вывод шума перлина , хотя он и гладкий, вывод по-прежнему сложен из-за большого количества холмов/гор. Я ищу что-то вроде это . Мне нужно быть уверенным, что у меня не будет высоты вокруг границ выходного изображения. Я думаю, у вас есть идея. Хорошего дня!
Вот код, который я использую прямо сейчас из онлайн-учебника:
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);
}
}