Files
PrincessLandVR/Assets/Procedural Worlds/Gaia/Scripts/Unity/Terrain Tools/Erosion/TerrainToolUtility.cs
T
2021-01-11 22:20:43 -08:00

31 lines
940 B
C#

using UnityEngine;
namespace Gaia {
#region Utility
public static class TerrainToolsUtility {
//assume this a 1D texture that has already been created
public static Vector2 AnimationCurveToRenderTexture(AnimationCurve curve, ref Texture2D tex) {
tex.wrapMode = TextureWrapMode.Clamp;
tex.filterMode = FilterMode.Bilinear;
float val = curve.Evaluate(0.0f);
Vector2 range = new Vector2(val, val);
Color[] pixels = new Color[tex.width];
for (int i = 1; i < tex.width; i++) {
float pct = (float)i / (float)tex.width;
pixels[i].r = curve.Evaluate(pct);
range[0] = Mathf.Min(range[0], pixels[i].r);
range[1] = Mathf.Max(range[1], pixels[i].r);
}
tex.SetPixels(pixels);
tex.Apply();
return range;
}
}
#endregion
}