Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additive and substractive picture support #1068

Open
gadesx opened this issue Oct 29, 2016 · 10 comments
Open

Additive and substractive picture support #1068

gadesx opened this issue Oct 29, 2016 · 10 comments

Comments

@gadesx
Copy link

gadesx commented Oct 29, 2016

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
Copy link
Member

Ghabry commented Oct 29, 2016

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 Ghabry added the Bitmaps label Oct 29, 2016
@Ghabry
Copy link
Member

Ghabry commented Oct 29, 2016

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
Copy link
Member

Ghabry commented Oct 29, 2016

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

@gadesx
Copy link
Author

gadesx commented Oct 30, 2016

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

@carstene1ns carstene1ns changed the title Additive and substractive picture support (enhancement) Additive and substractive picture support Apr 17, 2017
@carstene1ns carstene1ns added this to the 0.6.0 milestone Apr 17, 2017
@Ghabry Ghabry removed this from the 0.6.1 milestone May 5, 2019
@fdelapena
Copy link
Contributor

fdelapena commented May 28, 2021

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: ff64fd8

@Ghabry
Copy link
Member

Ghabry commented May 29, 2021

Maniac patch has also support for some of the blend modes

@Ghabry
Copy link
Member

Ghabry commented Sep 1, 2021

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)

@fdelapena fdelapena added this to the 0.7.0 milestone Sep 1, 2021
@cremno
Copy link

cremno commented Sep 7, 2021

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

@Ghabry
Copy link
Member

Ghabry commented Sep 7, 2021

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

@Ghabry Ghabry modified the milestones: 0.7.0, 0.7.1 Sep 9, 2021
@Ghabry
Copy link
Member

Ghabry commented Sep 9, 2021

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 Ghabry removed this from the 0.7.1 milestone May 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants