I’m new to unity so please forgive any stupidity I’m doing or saying
We want to tint one of the characters of our game based on alpha values of the texture. Say, if the pixel values are
R, G, B, A
255, 255, 255, 0 → this will be tinted
255, 255, 255, 255 → this will not be tinted
255, 255, 255, 127 → this will be blended with the tint value
I was looking at the docs, and I saw the Texture2D class. I noticed that it allows loading from a .png file, so, loading the file and processing the image and calling the Apply method seems to be a way of achieving the desired effect.
Questions:
Is this the best way of achieving what we want?
How about powervr texture compression? Will we lose on performance because the texture is a .png?
I don’t think so. I think you’d be better off scripting values that will be sent to the shader. (Try using the shader called “Diffuse”, that comes with Unity, and choose a “Main Color”, for example. It’s possible that you will get a performance benefit from modifying the shader to only take a grayscale value for “Main Color” instead of RGB, but I’m not sure about that.)
Format doesn’t matter once you get it into Unity. Right-click on your texture in the Project pane, and select “Import Settings…” to find out what’s really going on.
Okay, wouldn’t that tint the entire material (we want only the parts of the texture marked with alpha values < 1.0 to be tinted)?
I thought about using a lightmap, or self ilumination material, but doesn’t that combine two textures, and wouldn’t that be less efficient performance wise?
Format doesn’t matter once you get it into Unity. Right-click on your texture in the Project pane, and select “Import Settings…” to find out what’s really going on.[/quote]
Okay, so do you mean that once I Apply() my texture changes Unity will convert the texture to use pvrt texture compression automatically? Or will it keep it as just plain texture data in memory?
No problem. You may want to check out this other thread, which explains why I think it might make more sense to use an a variant of this shader that takes an inverted alpha channel: