diff --git a/CHANGELOG.md b/CHANGELOG.md index bdafc7d..7d3cbf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,10 @@ Removals - Marked old Draw and DrawTransformed overloads as obsolete in favor of SpriteBatchContext ones - Marked Tooltip.Paragraph as obsolete in favor of new Paragraphs collection +### MLEM.Data +Improvements +- Premultiply textures when using RawContentManager + ## 5.3.0 ### MLEM Additions diff --git a/MLEM.Data/Content/Texture2DReader.cs b/MLEM.Data/Content/Texture2DReader.cs index 275a019..89ec323 100644 --- a/MLEM.Data/Content/Texture2DReader.cs +++ b/MLEM.Data/Content/Texture2DReader.cs @@ -1,5 +1,7 @@ using System.IO; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; +using MLEM.Extensions; namespace MLEM.Data.Content { /// @@ -11,7 +13,20 @@ namespace MLEM.Data.Content { existing.Reload(stream); return existing; } else { - return Texture2D.FromStream(manager.GraphicsDevice, stream); + // premultiply the texture's color to be in line with the pipeline's texture reader + // TODO this can be converted to use https://github.com/MonoGame/MonoGame/pull/7369 in the future + using (var texture = Texture2D.FromStream(manager.GraphicsDevice, stream)) { + var ret = new Texture2D(manager.GraphicsDevice, texture.Width, texture.Height); + using (var textureData = texture.GetTextureData()) { + using (var retData = ret.GetTextureData()) { + for (var x = 0; x < ret.Width; x++) { + for (var y = 0; y < ret.Height; y++) + retData[x, y] = Color.FromNonPremultiplied(textureData[x, y].ToVector4()); + } + } + } + return ret; + } } } diff --git a/Sandbox/Content/Textures/Test.png b/Sandbox/Content/Textures/Test.png index 7d88c33..6bf0e3b 100644 Binary files a/Sandbox/Content/Textures/Test.png and b/Sandbox/Content/Textures/Test.png differ