How can we convert the Texture2D type to "Sprite" using the script (not in Editor)? It seems that the Texture2D retrieved from file is by default Normal Map. I need to convert the TextureType to "Sprite".
Texture2D texture = LoadPNG("D:/download.jpg");
testPlaneRenderer.material.SetTexture("_source",texture);
LoadPNG method code:
public static Texture2D LoadPNG(string filePath)
{
Texture2D tex = null;
byte[] fileData;
if (File.Exists(filePath))
{
fileData = File.ReadAllBytes(filePath);
tex = new Texture2D(2, 2);
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
Debug.Log("File Exists!");
}
else
{
Debug.LogError("File not exists!");
}
return tex;
}
It seems that this texture is set as "Default" or "Normal" Type when imported from file and then assigned to Material dynamically. As the particular shader I'm using, works best if the Texture Type is set to Sprite (I tested it by manually placing the texture file in Project and then assigning the texture to Material).
I need to change Type of Texture to Sprite before assigning it to the material. I've seen options like "AssetImporter" but it only works in Editor.
The effect of the shader (which takes two texture types
a) Inverted & Blurred Texture
b) GrayScale Texture
And then returns a Sketch Effect to the object. I convert the original image to inverted & blurred, grayscale texture using some image processing code (C#, Unity -> working around with GetPixels and SetPixels)...