14 public static Texture2D
ToGray(Texture texture){
15 Texture2D tex2D = (Texture2D)texture;
16 Texture2D grayTex =
new Texture2D(tex2D.width, tex2D.height);
19 for (
int y = 0; y < tex2D.height; ++y) {
20 for (
int x = 0; x < tex2D.width; ++x) {
21 grayScale = tex2D.GetPixel(x, y).r * 0.21f + tex2D.GetPixel(x, y).g * 0.71f + tex2D.GetPixel(x, y).b * 0.07f;
22 alpha = tex2D.GetPixel(x, y).a;
23 grayTex.SetPixel (x, y,
new Color(grayScale, grayScale, grayScale, alpha));
39 public static Texture2D
ToGray(
string resource_name){
40 Texture text2D = (Texture)Resources.Load(resource_name);
static Texture2D ToGray(string resource_name)
Return the grayscale version of a texture
static Texture2D ToGray(Texture texture)
Return the grayscale version of a texture