TextureGenerator.cs 956 B

1234567891011121314151617181920212223242526272829303132333435
  1. using UnityEngine;
  2. using System.Collections;
  3. public static class TextureGenerator
  4. {
  5. public static Texture2D TextureFromColourMap(Color[] colourMap, int width, int height)
  6. {
  7. Texture2D texture = new Texture2D(width, height);
  8. texture.filterMode = FilterMode.Point;
  9. texture.wrapMode = TextureWrapMode.Clamp;
  10. texture.SetPixels(colourMap);
  11. texture.Apply();
  12. return texture;
  13. }
  14. public static Texture2D TextureFromHeightMap(float[,] heightMap)
  15. {
  16. int width = heightMap.GetLength(0);
  17. int height = heightMap.GetLength(1);
  18. Color[] colourMap = new Color[width * height];
  19. for (int y = 0; y < height; y++)
  20. {
  21. for (int x = 0; x < width; x++)
  22. {
  23. colourMap[y * width + x] = Color.Lerp(Color.black, Color.white, heightMap[x, y]);
  24. }
  25. }
  26. return TextureFromColourMap(colourMap, width, height);
  27. }
  28. }