Ancestors

Toot

Written by pglpm on 2024-09-13 at 06:32

Question on combination of semi-transparent colours in plots:

If I plot a line or rectangle, say in blue, and then another one on top in red, then I'll only see the red one.

If I use transparent colours, then I'll be partly able to see the blue line beneath.

My question: which opacity (alpha) value should one use so that the result is "commutative"? that is, so that visually I see the same if I first plot the transparent-blue and then the transparent-red, or vice versa? Would an alpha=0.5 achieve this?

And what if I have three colours? Is there an alpha that would give the same visual result regardless of the permutation?

I'll do some visual experiments to check this, but I'm grateful to anyone who could point me to some work where the mechanics behind this and its result are explained :)

Cheers!

[#]rstats

=> More informations about this toot | More toots from pglpm@c.im

Descendants

Written by Thomas Lumley on 2024-09-13 at 06:59

@pglpm you can't get it commutative for any single alpha. If you use alpha on the first layer and alpha/(1+alpha) on the second layer they will be equally represented, if that helps

=> More informations about this toot | More toots from tslumley@fediscience.org

Written by pglpm on 2024-09-13 at 07:08

@tslumley Thank you, didn't know about that! I'd like to understand the why of that formula; if you have time, please feel free to refer me to some reading resources for that :)

=> More informations about this toot | More toots from pglpm@c.im

Written by Thomas Lumley on 2024-09-13 at 07:38

@pglpm the Description section of this Wikipedia page is good: it has the compositing algorithm

https://en.m.wikipedia.org/wiki/Alpha_compositing

=> More informations about this toot | More toots from tslumley@fediscience.org

Written by Jez 🍞🌹 on 2024-09-13 at 07:44

@pglpm

OK, so alpha blending is straight linear interpretation, so an alpha of 0.5 leads to an equal contribution of each input colour to the output colour. If you then add a third layer with alpha 0.5, you get 50% colour 3 and 50% previous blend. But that previous blend is 50% colour 1 and 50% colour 2, so the final colour after three layers will be 25% colour 1, 25% colour 2 and 50% colour 3. The top colour always contributes the most. 1/n

=> More informations about this toot | More toots from petrichor@digipres.club

Written by Jez 🍞🌹 on 2024-09-13 at 07:54

@pglpm This essentially happens with any fixed value of alpha. To get an equal blend, each layer needs to be applied with a smaller alpha, specifically layer n needs an alpha of 1/n.

Layer 1, alpha 1 (ie opaque)

Layer 2, alpha ½, gives ½c2 + (1-½)c1 = ½c1 + ½c2

Layer 3, alpha ⅓, gives ⅓c3 + ⅔(½c1 + ½c2) = ⅓c1 + ⅓c2 + ⅓c3

... and so on.

That's my understanding of the maths anyway, but colour perception is not linear so there's probably more to it

2/2

=> More informations about this toot | More toots from petrichor@digipres.club

Written by Jez 🍞🌹 on 2024-09-13 at 07:59

@pglpm So now I'm interested to know if that's right or not 😂

I learnt this algorithm as a way of picking a random line from a large file, with an equal chance of picking any line, only storing one line at any one time and passing through the file only once: store the first line, then reading line by line replace the stored line with line n with probability 1/n.

=> More informations about this toot | More toots from petrichor@digipres.club

Written by pglpm on 2024-09-13 at 13:00

@petrichor Yes it makes sense indeed! Then they all keep on contributing with the same opacity, where they overlap. What's sad is that where they don't overlap they get more and more transparent, but one can't have both...

=> More informations about this toot | More toots from pglpm@c.im

Written by Jez 🍞🌹 on 2024-09-13 at 14:34

@pglpm Huh, yeah, you'd probably need to track the number of layers being rendered on a pixel-by-pixel basis to avoid that. But we're getting into areas of computer graphics where I really don't know what I'm talking about (as opposed to mostly not-knowing)...

=> More informations about this toot | More toots from petrichor@digipres.club

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113128842552308595
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
319.92394 milliseconds
Gemini-to-HTML Time
4.121163 milliseconds

This content has been proxied by September (3851b).