浏览代码

Fixed an ImageAsset Blending Issue

Fixed a white artifacts that were appearing around the edge of images when using Bilinear blending and layered images by setting fulling transparent pixels to the base blend color.
Peter Robinson 3 年之前
父节点
当前提交
42b50d8984

+ 1 - 1
engine/source/2d/assets/ImageAsset.cc

@@ -1430,7 +1430,7 @@ void ImageAsset::redrawImage()
                 return;
             }
         }
-        map->clearImage();
+        map->clearImage(mBlendColor);
         for (auto &layer : mImageLayers)
         {
             map->mergeLayer(layer.mPosition, layer.mBitmap, layer.mBlendColor);

+ 2 - 2
engine/source/graphics/gBitmap.cc

@@ -121,9 +121,9 @@ void GBitmap::deleteImage()
    SAFE_DELETE(pPalette);
 }
 
-void GBitmap::clearImage()
+void GBitmap::clearImage(const ColorF blendColor)
 {
-    ColorI clearColor(255, 255, 255, 0);
+    ColorI clearColor(blendColor.red, blendColor.green, blendColor.blue, 0);
     for (U32 h = 0; h < getHeight(); h++)
     {
         for (U32 w = 0; w < getWidth(); w++)

+ 1 - 1
engine/source/graphics/gBitmap.h

@@ -130,7 +130,7 @@ class GBitmap: public ResourceInstance
    static U32 sBitmapIdSource;
 
    void deleteImage();
-   void clearImage();
+   void clearImage(const ColorF blendColor);
 
    BitmapFormat internalFormat;
   public:

+ 12 - 0
test/BlankGame/sprites/grad.image.taml

@@ -0,0 +1,12 @@
+<ImageAsset
+    AssetName="grad"
+    ImageFile="@assetFile=grad.png"
+    FilterMode="BILINEAR"
+    BlendColor="0.1 0.1 0.1 1">
+    <ImageAsset.ImageLayers>
+        <ImageLayer
+            ImageFile="grad.png"
+            Position="0 1"
+            BlendColor="TransparentWhite" />
+    </ImageAsset.ImageLayers>
+</ImageAsset>

二进制
test/BlankGame/sprites/grad.png