Handmade Hero»Forums»Code
69 posts / 1 project
Alpha Blend cool observation
I just wanted to point out my cool observation i had when watching the friday stream.
if you save to memory InverseAlpha:=(1-alpha) instead of alpha, you can get 2 things:

1. all of your alpha usage in the color section is done by InverseAlpha because of the premultiplied alpha, so it makes things nicer to read i think.

2. by following the mathematical derivetion casey did, the alpha section has the cool feature that (1-Abuffer)=(1-Asource)*(1-Adest),or:
InverseAlphaBuffer=InverseAlphaSource*InverseAlphaDest and this is really nicer to see.

i know it does no good to try to optimize things now, but i think that it's cool enough to write on the forums.
Andrew Bromage
183 posts / 1 project
Research engineer, resident maths nerd (Erdős number 3).
Alpha Blend cool observation
That doesn't really save memory, but it's a good observation. If alpha is the "coverage" of a pixel, then 1-alpha is the "stuff that is let through".

However, it doesn't realistically save any work, especially given that the world has standardised on alpha, not 1-alpha. I'm also not of the opinion that just because something is a little shorter, that makes it nicer to read. It's possible to make code so concise that the intent is lost.