So, i have made a script to generate perlinnoise, randomly. But what i need is for it to be able to loop on a sphere, and not go small at the top. Here is the script:
using UnityEngine;
using System.Collections;
public class Planet : MonoBehaviour
{
public int width = 256;
public int height = 256;
public float scale = 20f;
public float offsetX = 100f;
public float offsetY = 100f;
private void Start()
{
offsetX = Random.Range(0f, 10000f);
offsetY = Random.Range(0f, 10000f);
}
void Update()
{
Renderer renderer = GetComponent<Renderer>();
renderer.material.mainTexture = GenerateTexture();
}
Texture2D GenerateTexture()
{
Texture2D texture = new Texture2D(width, height);
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);
return new Color(sample, sample, sample);
}
}
Problem is, i dont know how to approach this.