Hi, I am working on a project that uses perlin noise to generate some terrain. The thing is, perlin noise is great to when it comes to smooth shapes, but I need only one. In other words, this is a normal output from perlin noise, but I need only ONE simple “Mountain/Hill”, like this . I need my shapes to be random with the smooth transitions of perlin noise but also pretty simple. I need to be sure that I won’t get any height along the borders of the image and so on. This is a very important project and I would immensly appreciate any amount of help I can get. Thank you and have a Great Day!
Here is the code I took from an online tutorial:
using System.Collections;
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);
}
}