Semi-transparent images render test

Description: General discussion regarding the current engine development.
Moderator: Moderators

Wohlstand M
Topic author, Lead Developer
Lead Developer
Avatar
Wohlstand M
Topic author, Lead Developer
Lead Developer
Age: 25
Reputation: 317
Posts: 1292
Joined: 15 Feb 2014
Location: Moscow, Russia
Website Skype YouTube

Post #1by Wohlstand » 21 Jun 2014, 10:23

To check SMBX's image renderer method, I made this little comparing of SMBX's blitting and PGE's alpha-blending. Masks giving to use semi-transparent for image formats which are not supports internal transparency (examples: BMP, JPG, or GIF which have only 1 bit of transparency) (PNG support 255 grades of semi-transparency - alpha-channel).

This is a Luigifan's little test of both transparency methods:
left - alpha-blending algorithm,
middle - AND->OR blitting algorithm.
right - Source image and it's mask.
Image

Test #1
I made vertical gradient background image:
Spoiler
Image
And gray-grade masks:
Spoiler
Image Image
Image Image

And run this interesting test:
ImageImage

Result:
- SMBX uses masks always in the render process by AND->OR bit blitting algorithm, result have a lot of color glitches.
- The PGE using masks once in the loading process which merging image and mask into RGBA-image which rendering by alpha-bleding algorithm.

Get this test


Test #2
Will be made test with horizontal gradient:
Spoiler
Image
And graded masks of same sprite, but saved in npc-1, npc-2,...,npc-20:
Spoiler
ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage

And ran this test:
ImageImage

Result:
- SMBX uses AND->OR bit blitting algorithm which is not support true transparency and makes garbled colors.
- PGE uses the alpha-channel to generate target sprites from masks, and renders them with real semi-transparency by alpha-blending algorithm.

Get this test


Test #3
Little programming examples:
For make real test, I got THIS example for Visual Basic 6 (Language, used for made SMBX) which implementing AND->OR bit blitting algorithm:
http://www.vbexplorer.com/VBExplorer/gdi1.asp

And I replaced images to my SMBX's sprites:
Image
And build them.

I take this result:
Image
As you see, result is same, what displayed in SMBX.

VisualBasic 6 source which creating this mask (And I think, this is same method, what uses in SMBX for render sprites)

Code: Select all

Private Sub cmdDrawMask_Click()

'Draws the mask with vbSrcAnd raster operation
BitBlt Me.hDC, 0, 0, picMask.ScaleWidth, picMask.ScaleHeight, picMask.hDC, 0, 0, vbSrcAnd

End Sub

Private Sub cmdDrawSprite_Click()

'Draws the sprite witht the vbSrcPaint raster operation
BitBlt Me.hDC, 0, 0, picSprite.ScaleWidth, picSprite.ScaleHeight, picSprite.hDC, 0, 0, vbSrcPaint

End Sub


All sources and test EXE of this you can get here: VB6 Mask Example.zip

In C++ with Qt I using mask once to define alpha-channel of target image:
https://github.com/Wohlhabend-Networks/PlatGEnWohl/blob/master/Editor/common_features/graphics_funcs.cpp#L24

Code: Select all


QPixmap setAlphaMask(QPixmap image, QPixmap mask)
{
    if(mask.isNull())
        return image;

    if(image.isNull())
        return image;

    QImage target = image.toImage();
    QImage newmask = mask.toImage();

    if(target.size()!= newmask.size())
    {
        newmask = newmask.copy(0,0, target.width(), target.height());
    }

    newmask.invertPixels();

    target.setAlphaChannel(newmask);

    return QPixmap::fromImage(target);
}


This allow using of any grades of semi-transparency.

But you should fix all lazy-made sprites (What is this?) which sometimes using in the SMBX's custom stuff

Luigifan2010 M
Contributor
Contributor
Avatar
Luigifan2010 M
Contributor
Contributor
Reputation: 5
Posts: 31
Joined: 29 Mar 2014

Post #2by Luigifan2010 » 8 Aug 2014, 21:56

So have we figured out if SMBX is just a bunch of moving (whatever the equivalent of NET's PictureBox) yet?


Return to “Engine Development”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest