8 ms·
My mental model of how alpha opacity works is wrong (2020)
- pavlov 5y agoLight is additive (in a linear colorspace). But the opacity of a layer means blocking part of the light, and such light absorbers are multiplicative.
- Synaesthesia 5y agoYeah I realised this one day after thinking about it. This is a very elegant explanation of the correct way to think about it.
- ruined 5y agosometimes i read things like this, and i'm astounded that anyone could have developed a mental model so incorrect and unintuitive but close enough to persist for a while. then i remind myself that i probably have a few situations like that in my own mind and i should remain vigilant. edit: and then i get just a little more frustrated next time someone resists a correction that i provide.
- gs17 5y ago> incorrect and unintuitive The thing that you might be missing is that "incorrect" is (usually) objective, but "unintuitive" isn't necessarily so. I can see how someone else would think additive opacity is intuitive, even if it's very easy to show that it isn't correct.
- marcosdumay 5y agoEvery one of those things limited to [0; 1] combine multiplicativelly. (Mostly because they are some kind of probability or vectorial projection - what are the same thing, by the way.) You are right that "intuitive" is a subjective property. But I'm completely lost trying to imagine what kind of life experiences can lead on to expect them to be additive.
- nerdponx 5y agoI also thought that opacity was additive and clamped to 0,1 until right now. Seem intuitive to me. Half + half = whole. When I make a chart in R and set the color to alpha 0.5, the result looks more or less like an opaque point if I plot 2 of them on top of each other. Apparently that's wrong, but it's consistent with my not-very-precise observations, and I have never had a need or desire to learn more about how opacity works. One cannot be an expert in all things. What intuition should a layperson have to suggest that obviously opacity/transmissivity is multiplicative? I don't see the value in deriding the incorrect intuition of uneducated people. In statistics at least we accept that statistics is hard specifically because it can be unintuitive.
- marcosdumay 5y agoOut of curiosity, did you have any rationalization for why clamping it made sense, or you just didn't think about it?
- nerdponx 5y ago"How can something be more opaque than fully opaque?" was my intuition (and probably many other people's). Also RGBA numbers are generally clamped to 0,255.
- marcosdumay 5y agoOk, I guess the repulsiveness of a clamping operation is something we learn. If one doesn't learn to fear it, it's an operation like any other. Should have been obvious, but I never thought about it.
- Agentlien 5y agoWhy do you call it repulsive? It's a very common operation in graphics. Even so that certain graphics processors have a flag for floating point operations which allow the results to be saturated (clamped to [0,1]) at no extra cost. I know I prefer to avoid it and design equations so it isn't necessary. That often helps make the math cleaner and more well behaved. But repulsion sounds stronger than what I feel. I would say there are plenty of cases where things do act additively yet we wish to clamp their values to a specific range (often valid colours).
- rebuilder 5y agoIt depends on what your experience is with. If you've done any digital painting, you're probably all too familiar with low-opacity strokes seeming to never add up to full opacity, and will have concluded the opacities are not simply added together.
- dahart 5y agoI immediately assumed the author might have been pretending a bit in order to motivate the article. Self deprecation sometimes makes things more relatable. I bet there’s even a name for using self deprecation initially as an excuse or motivation to make a point, but I don’t know what it is. That said, I’m well aware that opacity is multiplicative, and yet it still caught me off guard before to realize that the commonly used lerp blending mode (SRC_ALPHA, ONE_MINUS_SRC_ALPHA) is incorrect in the alpha channel. Pre-multiplied alpha can also be unintuitive at first, even with a decent mental model.
- ryanschneider 5y ago> but I don’t know what it is Or are you just pretending not to know to seem more relatable?
- dahart 5y ago:) hehe, well now I have to admit I actually tried to look it up, ended up on the Wikipedia list of rhetorical device names, and only got halfway through the A’s before giving up.
- Diggsey 5y agoWell... if we're trying to model how a translucent pane would work in the real world, then this is correct for one particular interpretation of alpha. However, if we're talking about how alpha blending actually works in software, then it can vary a lot. For example, in Direct3D you would typically use the `D3DBLEND_SRCALPHA` and `D3DBLEND_INVSRCALPHA` for the source and destination blend modes respectively. In that case, the combined alpha is actually `src_alpha^2 + (1 - src_alpha) * dst_alpha` which is different again from the two calculations in the article. There are even other ways to achieve a physically realistic result that use a different interpretation of the alpha channel. Or maybe you want to solve for something else (eg. order-independent blending)
- Animats 5y agoHe hasn't found the hard problem yet. If you have two translucent objects, how do you combine the colors? This is hard to do with Z-buffer rendering. The obvious coloring operation is not commutative, and in a Z-buffer system, you don't know which face gets rendered first. This is a huge pain. You can't just dump everything into the GPU and let it draw in parallel, which is what GPUs do fast. You usually have to depth-sort triangles, so the front triangle gets rendered last. This delays rendering while the CPU does the sort. There's a GPU-based solution to this, but it involves some compromises in quality.[1] [1] https://developer.nvidia.com/content/transparency-or-translucency-rendering https://developer.nvidia.com/content/transparency-or-translu...
- pcwalton 5y agoThe "right" solution with no quality compromises is per-pixel linked lists (PPLLs) that are then sorted afterward. This is straightforwardly implementable on GPU, but it remains to be seen whether the technique will take off, given the overhead.
- Jasper_ 5y agoPixel Shader Interlock (or Raster Ordered Views in D3D12 terminology) is effectively the same thing but without a resolve step, but the overhead is massive and basically too slow in practice. To be honest, the game developer way of solving this is to just not use transparency. Too many things rely on the G-buffer / depth buffer these days, and transparency is usually limited to a lower quality render anyway.
- deleted 5y ago[deleted]
- zokier 5y agoInvolving colors is much more complicated than that; in theory if you shine white light through stack a red filter on top of blue filter, I'd expect the intersecting area to be closer to black than purple. You can see that in for example this picture: https://www.walmart.com/ip/Sightmark-32mm-Filters/31197086 https://www.walmart.com/ip/Sightmark-32mm-Filters/31197086 This is just the tip of the iceberg when it comes to the complexity of translucent objects. To get truly convincing results spectral rendering is needed, but of course that is prohibitively expensive for real-time use.
- cjdell 5y agoRelevant video about cross-fades in CSS which I definitely learned something from: https://youtu.be/PYSOnC2CrD8?list=PLNYkxOF6rcIAKIQFsNbV0JDws_G_bnNo9 https://youtu.be/PYSOnC2CrD8?list=PLNYkxOF6rcIAKIQFsNbV0JDws...
- deleted 5y ago[deleted]
- klodolph 5y agoAlpha is also multiplicative, not just transmissivity. You just pick the right operation to think about it. https://en.wikipedia.org/wiki/Alpha_compositing https://en.wikipedia.org/wiki/Alpha_compositing If your compositing operation is A over B, then transmissivity is multiplicative for the A&B region. If your compositing mode is A in B, then opacity (alpha) is multiplicative. This has the same structure, mathematically, as thinking about logical operations like AND and OR, which are complementary to each other. If you think of AND as multiplication, well, you can think of OR as multiplication as well, just with the values flipped around.
- boulos 5y agoIf the original author is here, I find that the original paper [1] still remains one of the better discussions of what is trying to be represented with alpha blending operations. It's all just an approximation. Don't lose sight of that! [1] https://graphics.pixar.com/library/Compositing/paper.pdf https://graphics.pixar.com/library/Compositing/paper.pdf
- sdfsfgsdfadf 5y agoAlvy Ray Smith wrote a good paper which might help to set things straight for people: http://alvyray.com/Memos/MemosCG.htm#ImageCompositing http://alvyray.com/Memos/MemosCG.htm#ImageCompositing
- amelius 5y agoFor more fun, draw a filled circle in Inkscape. Then copy and paste it in the same place, and again, and again ... and watch the edges get more and more jagged. Try to explain that to an average user.
- whatshisface 5y ago"The pixels on the edge are supposed to be halfway between white and black to indicate being half-covered by the circle, but if you pile them up on top of each other anything with a little black adds up with its duplicates to complete black."
- heartbeats 5y agoBut if you zoom in, it looks the same.
- nocturnial 5y agoThat's because people, including me when I started programming, confuse alpha with coverage. Most people use the alpha value for coverage. Most of the time it doesn't really matter visually but there some edge cases where it does matter. The best docs I could find in a short amount of time, are those from anti-grain[1] where the author describes it as a "second alpha channel. [1] http://agg.sourceforge.net/antigrain.com/doc/basic_renderers/basic_renderers.agdoc.html http://agg.sourceforge.net/antigrain.com/doc/basic_renderers...
- iainmerrick 5y agoI find this usage of “mental model” to be really strange -- it implies you’re intentionally simplifying or abstracting something. Alpha blending is well-defined mathematically, so why would you need to abstract it? It’s perfectly OK not to know how it works, or to think you know and then realize you’re mistaken; but thinking in terms of “mental model” implies it can’t be fully understood, which isn’t the case. When you know how it works, you don’t have a more refined mental model, you just know! (Or think you know...)
- deleted 5y ago[deleted]
- asveikau 5y agoI think they're saying they thought they knew how it works, but were wrong.
- mLuby 5y agoYour mental model of mental model doesn't match mine. I have a mental model of how an elevator works from using them many times, but it's absolutely a simplified understanding of the real mechanisms at work. I believe elevators are fully understandable but I don't need that level of detail to operate one. If it became important to know more about them (say I was in an elevator that malfunctioned) then I'd invest more in making my mental model more correct. So to me, mental models aren't necessarily intentionally or consciously formed and they can certainly be used for quick simplified reasoning about things that may be in fact well-understood.
- twelvechairs 5y agoWhy oh why can't we just settle on 'transparency' as the best word to use in this space? Its more mentally simple than 'opacity' ('transparent' is a more common word than 'opaque' to hear used in the real world - as 'opaque' is the default of most objects/surfaces, having 'transparency' is a special property that needs to be described), more correct than 'translucency' (also used commonly including in this thread but in real definition means an object that passes light but not a clear image of what is behind, like a frosted window - light is not travelling in a straight line but is being bent) or 'transmissivity' which the author uses (needlessly making it more technical and opaque to the end user - and actually less specific as transmissivity could be translucency also)
- idle_zealot 5y agoWe use “opacity” when referring to the alpha channel because that’s what the alpha channel measures. A high alpha value makes the pixel more opaque, a low value makes it more transparent (less opaque). Saying that a pixel with “transparency 0” is transparent and one with “transparency 255” is opaque would be far more confusing.
- twelvechairs 5y agoYes and no. Yes opacity is what is in the alpha channel. But all im saying is that it would be easiest for all to think of as inverse of transparency, and this is how documentation should describe it, otherwise people make weird assumptions like OPs. Its stored as opacity rather than transparency for minor performant reasons not because its a different concept or better way to think of it
- deleted 5y ago[deleted]
- deleted 5y ago[deleted]
- Hokusai 5y agoThis is a common problem with statistics. Ask someone to answer "if Saturday has 25% of rain and Sunday another 25% what is the probability of rain during the weekend?" The intuitive, but wrong, answer is to add probabilities capping them at 100%. So, this mental model seems quite natural for humans.
- pishpash 5y agoWell that was a dumb mental model. I thought it would reveal something unintuitive.
- abram 5y agoDiscussions of photographic materials usually use density instead of opacity. Density is a logarithmic value equal to -log10(transmission), where transmission is the amount of light passed through (or reflected) on a scale of 0 to 1. So to give some examples, a material with 100% transmission would have a density of 0, a material with 10% transmission would have a density of 1.0, and a material with 1% transmission would have a density of 2.0. Density values have some advantages, including: - They can be combined with simple addition - Compared to transmission or opacity values, they correspond more closely to human visual perception
- magicalhippo 5y agoThis is more generally called absorbance[1] and stems from the Beer-Lambert law[2]. Been too long since I've done computer graphics, but you made me think about implementing transparency pass using absorbance instead. [1]: https://en.wikipedia.org/wiki/Absorbance#Absorbance_of_a_material https://en.wikipedia.org/wiki/Absorbance#Absorbance_of_a_mat... [2]: https://en.wikipedia.org/wiki/Transmittance#Beer%E2%80%93Lambert_law https://en.wikipedia.org/wiki/Transmittance#Beer%E2%80%93Lam...
- w0mbat 5y agoHe still hasn’t got it. Assets can have straight alpha or alpha premultiplied with a color.
- ilammy 5y agoWant to break your mental model about the real world? Try overlapping polarization filters, get puzzled why the center spot stays brighter than surroundings as you add more filters.
- floatingatoll 5y agoOn the topic of color mixing in realtime, we talked about pigments previously this week: Rebelle: Experimental online paint software https://news.ycombinator.com/item?id=30191520 https://news.ycombinator.com/item?id=30191520 (3 days ago, 22 comments)
- deleted 5y ago[deleted]
- layer8 5y agoNext: learn about premultiplied alpha. https://en.wikipedia.org/wiki/Alpha_compositing#Straight_versus_premultiplied https://en.wikipedia.org/wiki/Alpha_compositing#Straight_ver...