Open Brian0255 opened 2 hours ago
This is something of a tricky situation, the code currently was some kind of approximate to mimic GDI+'s blending based on some other lua scripts, but it seems to be very wrong in various cases.
Some stack overflow threads seem to indicate the formula is something much more complicated and evil: https://stackoverflow.com/a/2223241 https://stackoverflow.com/a/34131698
These seem to indicate GDI+ uses a very odd custom blending formula, something not representable with typical blending modes. Mimicking this in a shader necessitates knowing the color of the destination pixel before writing it, which is typically not possible. I think the only way I can really end up correctly mimicing the blending here is to have 2 passes, 1 pass to copy the destination pixels to another render target, and another doing the actual blending using those copied pixels.
Summary
This is a bit hard to describe, but when one rectangle is drawn over another, the overlapped area will draw with full opacity instead of "blending" like previously if the opacity is less than 0xFF.
Repro
gui.drawRectangle(257, 50, 150, 100, 0xFF606060, 0xFF606060) gui.drawRectangle(270, 40, 100, 50, 0x80FF0000, 0x80FF0000)