UnityMol  0.9.6-875
UnityMol viewer / In developement
TextureGray.cs
Go to the documentation of this file.
1 
2 using UnityEngine;
3 
4 public class TextureGray {
14  public static Texture2D ToGray(Texture texture){ // Should be moved out of HBallManager since it's also used for Surface Textures
15  Texture2D tex2D = (Texture2D)texture;
16  Texture2D grayTex = new Texture2D(tex2D.width, tex2D.height);
17  float grayScale;
18  float alpha;
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));
24  }
25  }
26  grayTex.Apply();
27  return grayTex;
28  }
29 
39  public static Texture2D ToGray(string resource_name){
40  Texture text2D = (Texture)Resources.Load(resource_name);
41  return(ToGray(text2D));
42  }
43 }
44 
static Texture2D ToGray(string resource_name)
Return the grayscale version of a texture
Definition: TextureGray.cs:39
static Texture2D ToGray(Texture texture)
Return the grayscale version of a texture
Definition: TextureGray.cs:14