EasyRPG / Player

RPG Maker 2000/2003 and EasyRPG games interpreter
https://easyrpg.org/player/
GNU General Public License v3.0
966 stars 183 forks source link

Additive and substractive picture support #1068

Open gadesx opened 7 years ago

gadesx commented 7 years ago

With RPG Maker XP & Vx ace there was an added to show pictures additives and substractives.

vxace

In Rpg maker 2003 with dynrpg there's a plugin that support it: https://rpgmaker.net/engines/rt2k3/utilities/11/

Actual comparison of a light in player using alpha channel (that looks like similar to the own rpg maker pictures with transparency) and additive light of blending plugin with dynrpg comparativa

Ghabry commented 7 years ago

Looks like thie Enhancement has unlikely conflicts with existing games (is file ending based, .xxx.png).

And is fast because is only required once on load. Related pixman ops: OP_ADD, OP_SATURATE, OP_MULTIPLY

Ghabry commented 7 years ago

Can @gadesx explain why the pictures are displayed with 50% transparency and faded out in RPG_RT? EasyRPG starts with 100% transparency and the editor shows it the same way.

Ghabry commented 7 years ago

Looks DynRPG specific, doesn't happen when I replace the RPG_RT m(

gadesx commented 7 years ago

Added a image here with the light I used as example, the plugin ignore the colours like black, adding only brighter colours of below. map_fx2 add

fdelapena commented 3 years ago

Last year @elsemieni tried to implement this feature but had some differences in behavior (layering, etc.) that could require diving deeper to match existing RPG_RT patches, however looks great to start with: https://github.com/EasyRPG/Player/commit/ff64fd8c6033a73b64d6e02b5c23930e14118504

Ghabry commented 3 years ago

Maniac patch has also support for some of the blend modes

Ghabry commented 2 years ago

Fixed by #2628

Because this is powered by Pixman it also supports 32 bit PNGs with Alpha channel properly (Contrary to Maniac Patch which only has limited alpha channel support)

cremno commented 2 years ago

Pixman doesn't support the (odd) subtract blend mode though.

Ghabry commented 2 years ago

yeah it only supports "Difference". Defined as abs(xB−xA), so the behaviour is different (wraparound)

Ghabry commented 2 years ago

Potential patch:

diff --git a/src/sprite.cpp b/src/sprite.cpp
index 16203e9fc..377c03819 100644
--- a/src/sprite.cpp
+++ b/src/sprite.cpp
@@ -114,11 +114,43 @@ BitmapRef Sprite::Refresh(Rect& rect) {
 }

 void Sprite::SetBitmap(BitmapRef const& nbitmap) {
+   if (nbitmap == bitmap) {
+       return;
+   }
+
    bitmap = nbitmap;
    if (!bitmap) {
        src_rect = Rect();
    } else {
        src_rect = bitmap->GetRect();
+
+       // EasyRPG Extension: Set the Blend Mode based on the filename, e.g. ".add.png" for "Additive"
+       SetBlendType(0);
+       StringView filename = bitmap->GetFilename();
+       if (filename.size() >= 8 && filename[filename.size() - 4] == '.' && filename[filename.size() - 8] == '.') {
+           filename = filename.substr(filename.size() - 7, 3);
+           constexpr std::array<std::pair<StringView, Bitmap::BlendMode>, 13> exts = {{
+               {"add", Bitmap::BlendMode::Additive},
+               {"clb", Bitmap::BlendMode::ColorBurn},
+               {"cld", Bitmap::BlendMode::ColorDodge},
+               {"dif", Bitmap::BlendMode::Difference},
+               {"drk", Bitmap::BlendMode::Darken},
+               {"exc", Bitmap::BlendMode::Exclusion},
+               {"hlg", Bitmap::BlendMode::HardLight},
+               {"lgh", Bitmap::BlendMode::Lighten},
+               {"mul", Bitmap::BlendMode::Multiply},
+               {"ove", Bitmap::BlendMode::Overlay},
+               {"sat", Bitmap::BlendMode::Saturate},
+               {"slg", Bitmap::BlendMode::SoftLight},
+               {"xor", Bitmap::BlendMode::XOR}
+           }};
+           auto it = std::lower_bound(exts.begin(), exts.end(), filename, [](const auto& e, const auto& fname) {
+               return e.first < fname;
+           });
+           if (it != exts.end() && it->first == filename) {
+               SetBlendType((int)it->second);
+           }
+       }
    }

    src_rect_effect = src_rect;
diff --git a/src/sprite_picture.cpp b/src/sprite_picture.cpp
index 58f094132..8c005c371 100644
--- a/src/sprite_picture.cpp
+++ b/src/sprite_picture.cpp
@@ -144,7 +144,9 @@ void Sprite_Picture::Draw(Bitmap& dst) {

    SetFlipX(data.easyrpg_flip_horizontal);
    SetFlipY(data.easyrpg_flip_vertical);
-   SetBlendType(data.easyrpg_blend_mode);
+   if (static_cast<Bitmap::BlendMode>(data.easyrpg_blend_mode) != Bitmap::BlendMode::Default) {
+       SetBlendType(data.easyrpg_blend_mode);
+   }

    Sprite::Draw(dst);
 }
--