|
-
Dec 28th, 2003, 04:37 AM
#1
Thread Starter
So Unbanned
alpha blend math
Alpha blending isn't that hard for me except when the destination also has an alpha channel.
I've tried multiplying with the destination alpha channel into the RGB calculation.
My problem currently is semi-transparent pixels, either opaque or transparent destination alpha works ok.
VB Code:
' RGBA = destination
'c(r,g,b) = source
'Opacity = source opacity
Sa(0) = Opacity / 255
Sa(1) = A / 255
clsDIB.Red = cR * Sa(0) + cR * (1 - Sa(1)) + R * (1 - Sa(0)) * Sa(1)
clsDIB.Green = cG * Sa(0) + cG * (1 - Sa(1)) + G * (1 - Sa(0)) * Sa(1)
clsDIB.Blue = cB * Sa(0) + cB * (1 - Sa(1)) + B * (1 - Sa(0)) * Sa(1)
clsDIB.Alpha = Opacity * (1 - Sa(1)) + A
-
Dec 29th, 2003, 04:52 AM
#2
Frenzied Member
Let me see if I understand the question. You have a semi transparent object, which you want to move under another semi-transparent object. You want to find how transparent the 1st object will be under the 2nd. right?
Well, if you could convert the two objects transparencies to 0 to 1 (50% would be 0.5) then I would think you could simply multiply the numbers together to get the transparency of the bottom object.
Or is that what you've already tried?
Have I helped you? Please Rate my posts. 
-
Dec 29th, 2003, 04:58 AM
#3
transcendental analytic
you should just add R1*alpha2 to R2, R2 being the top layer red channel and R1 the bottom layer red channel and alpha2 the top layer alpha channel, similar for the other channels, alpha2 should be multiplid by alpha1
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 29th, 2003, 06:04 AM
#4
Thread Starter
So Unbanned
Originally posted by kedaman
you should just add R1*alpha2 to R2, R2 being the top layer red channel and R1 the bottom layer red channel and alpha2 the top layer alpha channel, similar for the other channels, alpha2 should be multiplid by alpha1
R2 can be transparent though.
-
Dec 29th, 2003, 04:40 PM
#5
transcendental analytic
ok these equations should do, where layer 2 is on top of layer 1 and R any colour channel, A alpha channel:
Anew=A1A2
Rnew=((R1(1-A1)-1)A2 +1)/(1-Anew)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Dec 29th, 2003, 09:03 PM
#6
Thread Starter
So Unbanned
Originally posted by kedaman
ok these equations should do, where layer 2 is on top of layer 1 and R any colour channel, A alpha channel:
Anew=A1A2
Rnew=((R1(1-A1)-1)A2 +1)/(1-Anew)
Anew isn't right, because if the old alpha is 0, and the new is 255, it becomes 0.
-
Dec 30th, 2003, 05:26 AM
#7
Thread Starter
So Unbanned
Ok... so I'm thinking...
ConstAlpha = SourceOpacity * (1 - Sa(1)) + A
And then...
FinalR = Sr * (SourceOpacity/ConstAlpha) + Dr * (A/ConstAlpha)
Yea... I don't see any problems with that.
Except Alpha is actually 1-256.
Oh well, minor detail!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|