From 768fd4adee0c91ae951156d9fedf1a3e35a5fb86 Mon Sep 17 00:00:00 2001 From: DS Date: Mon, 22 Jul 2024 16:35:36 +0200 Subject: [PATCH] Restore buggy texture overlay modifier (#14852) Required because of backwards compatibility. --- doc/lua_api.md | 4 ++++ src/client/imagesource.cpp | 11 +++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index efe05e5d9..e7498ff04 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -456,6 +456,10 @@ i.e. without gamma-correction. Textures can be overlaid by putting a `^` between them. +Warning: If the lower and upper pixels are both semi-transparent, this operation +does *not* do alpha blending, and it is *not* associative. Otherwise it does +alpha blending in srgb color space. + Example: default_dirt.png^default_grass_side.png diff --git a/src/client/imagesource.cpp b/src/client/imagesource.cpp index 4bcfb9804..696159408 100644 --- a/src/client/imagesource.cpp +++ b/src/client/imagesource.cpp @@ -420,12 +420,11 @@ void blit_pixel(video::SColor src_col, video::SColor &dst_col) return; } // A semi-transparent pixel is on top of a - // semi-transparent pixel -> general alpha compositing - u16 a_new_255 = src_a * 255 + (255 - src_a) * dst_a; - dst.r = (dst.r * (255 - src_a) * dst_a + src.r * src_a * 255) / a_new_255; - dst.g = (dst.g * (255 - src_a) * dst_a + src.g * src_a * 255) / a_new_255; - dst.b = (dst.b * (255 - src_a) * dst_a + src.b * src_a * 255) / a_new_255; - dst_a = (a_new_255 + 127) / 255; + // semi-transparent pixel -> weird overlaying + dst.r = (dst.r * (255 - src_a) + src.r * src_a) / 255; + dst.g = (dst.g * (255 - src_a) + src.g * src_a) / 255; + dst.b = (dst.b * (255 - src_a) + src.b * src_a) / 255; + dst_a = dst_a + (255 - dst_a) * src_a * src_a / (255 * 255); dst_col.set(dst_a, dst.r, dst.g, dst.b); }