public static Texture2D Get_Gradient_Texture(int pixels, GRADIENT_DIR dir, float shade1, float shade2, bool exponential = false, float exponent = 1f) { var clr1 = new Color(shade1, shade1, shade1); var clr2 = new Color(shade2, shade2, shade2); return(Get_Gradient_Texture(pixels, dir, clr1, clr2, exponential, exponent)); }
public static Texture2D Get_Gradient_Texture(int pixels, GRADIENT_DIR dir, Color clr1, Color clr2, bool exponential = false, float exponent = 1f) { var xsz = 1; var ysz = 1; if (dir == GRADIENT_DIR.TOP_BOTTOM) { ysz = pixels; } else { xsz = pixels; } var texture = new Texture2D(xsz, ysz, TextureFormat.RGBA32, true); for (var i = 0; i < pixels; i++) { var t = ((float)i / (float)pixels); if (exponential) { t = (float)Math.Pow((double)t, exponent); } if (dir == GRADIENT_DIR.TOP_BOTTOM) { t = (1f - t); } var clr = Color.Lerp(clr1, clr2, t); /* * float R = Lerp(clr1.r, clr2.r, t); * float G = Lerp(clr1.g, clr2.g, t); * float B = Lerp(clr1.b, clr2.b, t); * float A = Lerp(clr1.a, clr2.a, t); */ var x = 0; var y = 0; if (dir == GRADIENT_DIR.TOP_BOTTOM) { y = i; } else { x = i; } texture.SetPixel(x, y, clr); //texture.SetPixel(x, y, new Color(R, G, B, A)); } texture.anisoLevel = 4; texture.filterMode = FilterMode.Trilinear; texture.Apply(true, false); return(texture); }