Alpha channel in Unity is different from one in Photoshop

Hi everyone,
I’m trying to create image effect and store some values in different channels of the texture. The thing is that the values in alpha channel are different in Photoshop and in Unity.

Straight lines with flat color look like this:

Vertical gradient like this:


I tried different file formats (psd, png, targa) - result always the same. Import setting also don’t solve the problem (tried Auto and 32bit RGBA).

Does anyone know how to fix it? This thing drives me crazy…

Thanks!

How are you making the images above? Are you capturing them using a Windows/MacOS screen capture?

Just PrtScr (Windows) and then cropped and put them side by side in Photoshop. To get image from Unity I output alpha values from shader like this:

fixed4 t = tex2D(_MyTex, i.uv);
return t.a;

But you can also see the same result on the texture preview if you select alpha channel (“A” button at the top of the preview).

This is because by default Photoshop lies, or rather, it’s not showing you the data you think it is. When you paint a color into an alpha channel or grayscale image, it’s doing a color conversion to that color before painting and back again when picking and displaying. So while it’ll show you “R : 128, G : 128, B : 128” in the info window for the 8-bit RGB, if you switch the info over to show you “Actual Color, 32-bit (0.0-1.0)” it’ll show the value of “0.412”.

255 * 0.412 = __*105.06*__

That look familiar?

The fix is go into your color settings and change the Working Spaces for Gray from “Dot Gain 20%” to “sGray”. Now it’ll show you the RGB values for you thought you were painting and seeing.

3 Likes

Thanks, bgolus!!! It works perfectly! You saved my day :slight_smile: