Archived
Private
Public Access
1
0
This repository has been archived on 2026-02-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ProjectBackup/Unity/Landmass Generation/Assets/Scripts/Utils/TextureGenerator.cs
2022-11-12 13:10:03 +01:00

29 lines
993 B
C#

using UnityEngine;
namespace Utils {
public static class TextureGenerator {
public static Texture2D TextureFromColorMap(Color[] colorMap, int width, int height) {
Texture2D texture = new Texture2D(width, height);
texture.filterMode = FilterMode.Point;
texture.wrapMode = TextureWrapMode.Clamp;
texture.SetPixels(colorMap);
texture.Apply();
return texture;
}
public static Texture2D TextureFromHeightMap(float[,] heightMap) {
int width = heightMap.GetLength(0);
int height = heightMap.GetLength(1);
Color[] colorMap = new Color[width * height];
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++) {
colorMap[y * width + x] = Color.Lerp(Color.black, Color.white, heightMap[x, y]);
}
return TextureFromColorMap(colorMap, width, height);
}
}
}