4 ms·
Read the article again. You've completely misinterpreted it.
by moron4hire 11y ago
Read the article again. You've completely misinterpreted it.
- Dylan16807 11y agoI have not. When your number is already 0, multiplying it by 0 does not change anything. That's just a fact. So in the case of this specific color, invisible black, you only need to change a shader to fix the problem. This, plus the author constantly talking about 'premultiplying' as the fix, made it harder for me to understand that the fix is equal parts the texture change and the shader change.
- moron4hire 11y agoNo, it's not about the black pixel at all. Of course zero times anything is zero. It's actually about the red pixel next to it. The method the article details is the correct implementation for a variety of reasons that it goes into. Yes, there are different ways you can handle 100% transparent pixels on the edges, but only premultiplied alpha handles all edge cases that we're concerned about.
- Dylan16807 11y agoThe red pixel is (255, 0, 0, 255). Premultiplying it by alpha makes it (255, 0, 0, 255). It's not that the article says anything wrong, it's that it uses an example texture where there are no translucent pixels and no hidden colors. In a texture like that, premultiplying by alpha does nothing. In a texture like that, you only need to add a division by alpha to your shader. The combination of using premultiplied textures and altered shaders solve the general case. Using only altered shaders solves only an edge case. But the article only shows that edge case. That made it harder to follow.
- erich666 11y agoThe author of the article here. I know what you mean about my example. I in fact started with an example of red (255,0,0,255) texel next to fully transparent (0,0,0,0) texel, but found that example unconvincing - you don't really see the effect of premultiplication directly, as both texel values look exactly the same whether you premultiply or not. Really, another way to write the article would be to say, "whether or not you want it, the GPU will return premultiplied-looking values when you bilinear interpolate or mipmap." The interpolated value for (255,0,0,255) and (0,0,0,0) is (127.5,0,0,127.5). The only logical way to interpret this value is as a premultiplied value. I hope this helps. I'll add a sentence or two to the article along these lines, as it might help others to get what I'm trying to describe. Thanks for pointing out the confusion.
- dahart 11y agoEric, I've had this point in my head, but I missed that you were making it, and furthermore I missed the true meaning of your post's title! It is true, and interesting, that whether you use unassociated colors and blending functions or you use premultiplied colors & blending functions, either way, what comes out is a premultiplied color! This is true of any software compositor or renderer too, right? It's a fact of rendering, not just of GPUs, that output colors are premultiplied. The over operator multiplies colors by the source alpha values while you blend - that is where "premultiplication" happens when you render or composite something. Some software renderers have an "un-premultiply" flag to do a divide right at the end, so you can spit out files with unassociated colors in them, but otherwise anything rendered comes out premultiplied. I believe this is exactly why WebGL defaults your canvas to premultiplied compositing over the rest of the page. Your output is premultiplied even when your input isn't. It is also a good reason to think in pre-multiplied colors and use the blending functions that assume pre-multiplied colors, and pay attention to, and convert/premultiply on the fly, when you need to accept unassociated color sources like hand-painted textures.