Restore buggy texture overlay modifier (#14852)

Required because of backwards compatibility.
This commit is contained in:
DS 2024-07-22 16:35:36 +02:00 committed by GitHub
parent 682b789dd5
commit 768fd4adee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

@ -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

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