- Home /
Question by
benfattino · Mar 25, 2016 at 11:16 AM ·
runtimenormalmap
import normal map runtime
I need to import normal map in runtime. I try use this:
public static Texture2D CreateNormalMap(string PathToFile)
{
Texture2D normaltex = null;
byte[] fileData;
if (File.Exists(PathToFile)) {
fileData = File.ReadAllBytes(PathToFile);
normaltex = new Texture2D(2, 2,TextureFormat.ARGB32, false);
normaltex.LoadImage(fileData);
}
Color theColour = new Color();
for (int x=0; x<normaltex.width; x++){
for (int y=0; y<normaltex.height; y++){
theColour.r = normaltex.GetPixel(x,y).g;
theColour.g = normaltex.GetPixel(x,y).g;
theColour.b = normaltex.GetPixel(x,y).g;
theColour.a = normaltex.GetPixel(x,y).r;
normaltex.SetPixel(x,y, theColour);
}
}
normaltex.Apply();
return normaltex;
}
No result... My normal texture is already in right color (not grayscale). Somebody help?
Comment