Created
January 28, 2018 20:16
-
-
Save paniq/e8dc61231e4ec3513a5b9e52dc9915a7 to your computer and use it in GitHub Desktop.
alpha blending: order independence and reversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a0 = 0.3 | |
a1 = 0.7 | |
a2 = 0.9 | |
a3 = 0.1 | |
c0 = 0.1 | |
c1 = 0.2 | |
c2 = 0.3 | |
c3 = 0.4 | |
# forward alpha blending | |
x = c0*a0 | |
x = x*(1 - a1) + c1*a1 | |
x = x*(1 - a2) + c2*a2 | |
x = x*(1 - a3) + c3*a3 | |
# backward alpha blending | |
y = 0 | |
k = 1 | |
y = y + a3*c3*k | |
k = k*(1 - a3) | |
y = y + a2*c2*k | |
k = k*(1 - a2) | |
y = y + a1*c1*k | |
k = k*(1 - a1) | |
y = y + a0*c0*k | |
k = k*(1 - a0) | |
assert(abs(x - y) < 1e-5) | |
print(x, y) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment