Android weird alpha on textures

Hi guys!
I’ve created a game using MonoGame and have come across a weird issue. Somehow when I add .png files to the Content folder and load them and the alpha channel gets distorted, the issue is solved by precompiling the assets to .xnb format. I also noticed that this does only happen to alpha values which are not 0. This does not happen on UWP nor on Windows desktop projects. Below are a few examples.

UWP: This gives the proper result
Content/file.png
Build Action: Content
Copy to output: Copy if newer

Android: ERROR Alpha channel seems to be maxed
Content/file.png
Build Action: AndroidAsset
Copy to output: Copy if newer

Android: Gives proper result. Note the file is already in .xnb format.
Content/file.xnb
Build Action: AndroidAsset
Copy to output: Copy if newer

The .xnb files were built from another content.mgcb, not the one in the project. Also I haven’t touched the content.mgcb in the project in anyway. This isn’t a huge problem, but one that still annoys me.

Note: The files do have a gradient alpha channel. If the alpha channel is 0, the pixel does not get distorted.

Thanks in advance!

Looks like nonpremultiplied alpha, either make sure that images are complied with premult alpha or render it with blendstate.Nonpremultiplied or Multiply it at output of shader.

Yeah probably. But how do I set that the project imports them with alpha premultiplied?

My content folder looks somewhat like this:
Content
–image.png
–Content.mgcb

in mgcb, open monogame pipeline, not sure if there is another way.

Loading PNGs and other raw assets directly through ContentManager has been removed. Assets loaded through ContentManager must now be processed using the content build pipeline. Raw assets such as PNG files must now be loaded through Texture2D.FromStream().

In XNA, Texture2D.FromStream() did not do any premultiply alpha step, so neither should we. If a platform is doing premultiply in Texture2D.FromStream(), it should be fixed. From your description, it looks like UWP might be doing a premultiply when it shouldn’t be.

I haven’t been using Texture2D.FromStream(), unless if the ContentManager uses it internally. Also the UWP is functioning exactly like the old XNA, I did never paste any .xnb files to the Content folder, in the XNA project, before either and the alpha was still premultiplied.

BTW the desktop project gives the same output as the UWP project, so the Android project is the inconsistent one.

Hope that this made the issue somewhat clearer, as it is quite difficult explaining it :slight_smile:

In XNA, you never had to deal with XNB files directly because adding them to the Content project automatically built them into XNB files. We use a separate tool to build the XNB files, and the latest project templates have custom build steps that build the content for you when the solution is built on Visual Studio.

I believe the current official release still used Texture2D. FromStream() internally if it couldn’t find a XNB file with that name. This was an interim feature while we were building our content pipeline. It has since been removed.

You’re probably right. I still find it quite weird that the same code gives different results. However as this isn’t a huge problem I can manage :smiley: