[HN Gopher] My mental model of how alpha opacity works is wrong
___________________________________________________________________
My mental model of how alpha opacity works is wrong
Author : sebg
Score : 47 points
Date : 2022-02-03 17:11 UTC (2 days ago)
(HTM) web link (coolbutuseless.github.io)
(TXT) w3m dump (coolbutuseless.github.io)
| [deleted]
| cjdell wrote:
| Relevant video about cross-fades in CSS which I definitely
| learned something from:
| https://youtu.be/PYSOnC2CrD8?list=PLNYkxOF6rcIAKIQFsNbV0JDws...
| klodolph wrote:
| Alpha is also multiplicative, not just transmissivity. You just
| pick the right operation to think about it.
|
| 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.
| Animats wrote:
| He 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-
| translu...
| zokier wrote:
| Involving 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
|
| 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.
| boulos wrote:
| The (stochastic) order-independent transparency and k-buffer
| line of work is definitely cool for what it was. I get the
| sense that RTX will finally make it so that folks are going to
| end up just ray tracing the transparent volumes (even if you
| first did a rasterization pass of the "non transparent stuff").
| nyanpasu64 wrote:
| The hard problem in 2D rendering (where objects are drawn in a
| user-determined order) isn't translucent blending of unsorted
| polygons, but conflation artifacts. If you have two adjacent
| squares where the first covers the left half of a pixel and the
| second covers the right half, and both are drawn with alpha
| blending, there will be background showing through which
| shouldn't exist, and too little influence from the first
| square's color. Similarly if you drawn two identical squares on
| top of each other, which both cover the left half of a pixel,
| the first square will have some influence over the background
| which shouldn't happen at all.
| pcwalton wrote:
| The "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.
| pavlov wrote:
| Light 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 wrote:
| Yeah I realised this one day after thinking about it. This is a
| very elegant explanation of the correct way to think about it.
| ruined wrote:
| sometimes 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.
| rebuilder wrote:
| It 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.
| gs17 wrote:
| > 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 wrote:
| Every 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 wrote:
| I 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 wrote:
| Out of curiosity, did you have any rationalization for
| why clamping it made sense, or you just didn't think
| about it?
| nerdponx wrote:
| "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.
| riversflow wrote:
| > What intuition should a layperson have to suggest that
| obviously opacity/transmissivity is multiplicative?
|
| My intuition is that if I put on dark sunglasses I can
| still see through other dark things (like a CD or welders
| glass) if I look at something bright enough (like the
| sun). If opacity/transmissivity is modeled like it works
| in real life, given this example, it follows that it
| wouldn't be additive.
| nerdponx wrote:
| That's a great point, and it illustrates the problem with
| the mental models of uneducated people. It's difficult to
| know what information should and shouldn't be part of the
| model! I figured it just didn't work like real life,
| because RGBA numbers are clamped.
| teawrecks wrote:
| > What intuition should a layperson have to suggest that
| obviously opacity/transmissivity is multiplicative?
|
| Tinted windows and sunglasses come to mind. Intuitively,
| if you put translucent things back to back, you expect
| light to still pass through, albeit less of it, but
| always some. A noteworthy exception is when using
| polarized filters, which can unintuitively block out 100%
| of light depending on the angle between the filters.
| boulos wrote:
| If 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
| amelius wrote:
| For 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.
| Diggsey wrote:
| Well... 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)
___________________________________________________________________
(page generated 2022-02-05 23:00 UTC)