As example, lets say we have a red opaque and a blue transparent pixel next to each other: rgba(1,0,0,1) and rgba(0,0,1,0). With linear sampling halfway through (50% of each) we get:
- Code: Select all • Expand view
sampled.r = p0.r * 0.5 + p1.r * 0.5 = 0.5
sampled.g = p0.g * 0.5 + p1.g * 0.5 = 0
sampled.b = p0.b * 0.5 + p1.b * 0.5 = 0.5
sampled.a = p0.a * 0.5 + p1.a * 0.5 = 0.5
If the colors are premultiplied, the textures will contain rgba(1,0,0,0) and rgba(0,0,0,0). That will give this sampling:
- Code: Select all • Expand view
sampled.r = p0.r * 0.5 + p1.r * 0.5 = 0.5
sampled.g = p0.g * 0.5 + p1.g * 0.5 = 0
sampled.b = p0.b * 0.5 + p1.b * 0.5 = 0
sampled.a = p0.a * 0.5 + p1.a * 0.5 = 0.5
Which results in a clean blend to transparent without any artifacts. That is the main reason that premultiplied alpha is so widespread rather than speed.
Btw. I wasn't aware that zdoom sometimes discarded the alpha channel. Under what conditions does this happen - always with one sided walls? Maybe I just haven't seen a map yet where there was transparent pixels in such a one-sided wall. You're right that in such a situation premultiplied alpha wouldn't work.