Player icon indicating copy to clipboard operation
Player copied to clipboard

Additive and substractive picture support

Open gadesx opened this issue 8 years ago • 10 comments

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

gadesx avatar Oct 29 '16 18:10 gadesx

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 avatar Oct 29 '16 21:10 Ghabry

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 avatar Oct 29 '16 21:10 Ghabry

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

Ghabry avatar Oct 29 '16 21:10 Ghabry

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

gadesx avatar Oct 30 '16 21:10 gadesx

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

fdelapena avatar May 28 '21 17:05 fdelapena

Maniac patch has also support for some of the blend modes

Ghabry avatar May 29 '21 00:05 Ghabry

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)

Ghabry avatar Sep 01 '21 15:09 Ghabry

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

cremno avatar Sep 07 '21 16:09 cremno

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

Ghabry avatar Sep 07 '21 16:09 Ghabry

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);
 }
-- 

Ghabry avatar Sep 09 '21 18:09 Ghabry