Hi, I’m having trouble figuring out how to get this to work. I want to be able import a new texture and have it generate alpha from grayscale just like it would if it had the box checked in the import settings, except this would be an image uploaded to the program by the user and not included in the build… sooo, i can’t use the import settings… I know there must be a simple way to do this…
Here’s the code I’ve got so far:
var shader : Shader;
private var message = "";
private var alpha = 1.0;
private var pathChar = "/"[0];
var pixels : Color[];
var pixel : Color;
var url = "";
function LoadTex (pathToFile : String) {
var fileIndex = pathToFile.LastIndexOf(pathChar);
message = "You selected file: " + pathToFile.Substring(fileIndex+1, pathToFile.Length-fileIndex-1);
url = ("file:" + pathToFile);
renderer.material = new Material (shader);
var texture = Texture2D;
var www : WWW = new WWW (url);
yield www;
renderer.material.mainTexture = www.texture;
www.LoadImageIntoTexture(texture);
var pixels : Color[] = texture.GetPixels();
for (var i : int = 0; i<pixels.Length; ++i) {
pixel = pixels*;*
-
pixel.a = (pixel.r + pixel.g + pixel.b) / 3.0f;* -
texture.SetPixels(pixels);* -
}* -
texture.Apply();*
}