Noticeable difference between XNB and PNG FromStream Texture2Ds.

The character is made from a spritesheet of body parts and each part is drawn on the screen as a quadrilateral.
Why is there a difference and what would I need to change to get the PNG to look like the XNB?

Hi @Kazo Hajimemashite, Welcome to the Forums!

Can you share one slice of the model – say the leg section – to show how you have it created? say a colour key or what kind of transparency you are using.

Happy Coding!

It may be textures with alpha.

When you load a texture from a stream it has a block of code that can be turned off by a setting when loaded from the content manager.

This code was added because it was thought to be in XNA

Basically if a pixel has alpha equal to 0, the pixel colour is replaced with black.

For me this was a killer and I removed it from my version of monogame.

I am not 100% sure that this is what it is, but it is a possibility

What happens if you change BlendState?

spriteBatch.Begin (blendState: BlendState.NonPremultiplied);

The default I think is AlphaBlend.

1 Like

This would be my guess as well. I think the content pipeline does the pre multiply step values when it loads it in to speed up rendering, but when you load from a file, this isn’t done.

Someone PM’d me the solution. Apparently you need to modify the colors?

Color[] data = new Color[_img.Width * _img.Height];
            for (int i = 0; i < data.Length; i++)
                data[i] = Color.FromNonPremultiplied(data[i].ToVector4());

Why would loading a PNG FromStream skip this? Why are they different? Shouldn’t they both give the same result? Is this skipped to save time on generating the texture in real time?

It is one of several OPTIONS when using the content manager.

Those options are not exposed to the FromStream system, so which set of OPTIONS should FromStream support?

Maybe the interface could be extended to allow you to specify those options, but then that requires someone to actually do the work.

If you really need it, then add it. The source to Monogame is available.