Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class PerlinNoise : MonoBehaviour
- {
- public int width = 256;
- public int height = 256;
- public float scale = 20f;
- private 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; x < 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;
- float yCoord = (float)y / height * scale;
- float sample = Mathf.PerlinNoise(xCoord, yCoord);
- return new Color(sample, sample, sample);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement