PDA

View Full Version : Doubt in Blending in red book example

glBomb
09-30-2006, 04:11 AM
The given blend eqn is

One way to draw a picture composed half of one image and half of another, equally blended, is to set the source factor to GL_ONE and the destination factor to GL_ZERO, and draw the first image. Then set the source factor to GL_SRC_ALPHA and destination factor to GL_ONE_MINUS_SRC_ALPHA, and draw the second image with alpha equal to 0.5. This pair of factors probably represents the most commonly used blending operation. If the picture is supposed to be blended with 0.75 of the first image and 0.25 of the second, draw the first image as before, and draw the second with an alpha of 0.25.

So when i draw 1st image
(Sr,Sg,Sb,Sa) = (1,1,1,1)
(Dr,Dg,Db,Da) = (0,0,0,0)
Assumin A1=1=As here for 1st pic & a black backround initially i.e. (Rd,Gd,Bd,Ad) = (0,0,0,0)
we get the followin pixel value after 1st picture as been drawn
(R1+0,G1+0,B1+0,A1+0) = (R1,G1,B1,1) i.e. the solid 1st picture pixels where 1 represents 1st pic

now on to second image we have
alpha = 0.5,so
(Sr,Sg,Sb,Sa) = GL_SRC_ALPHA = (0.5,0.5,0.5,0.5)
(Dr,Dg,Db,Da) = GL_ONE_MINUS_SRC_ALPHA = (0.5,0.5,0.5,0.5)
we also already have destination pixel in buffer as
iven A2=0.5=As here
we get
( R2*0.5 + R1*0.5,G2*0.5 + G1*0.5,B2*0.5 + B1*0.5, 0.5*0.5 + 1*0.5) =
( R2*0.5 + R1*0.5,G2*0.5 + G1*0.5,B2*0.5 + B1*0.5, 0.75)
^
So we get what we want finally : the color intensities from both pics equally weighed for final pixel color

I would like someone to confirm that the above calculations are correct & this is in fact te way opengl alpa blends
ESP IS MY FINAL ALPHA VALUE OF 0.75 CORRECT? SHOULDNT IT TOTAL TO ONE ?

If this is the case then why is the problem that i asked about in this thread occurring ?

glBomb
10-01-2006, 12:25 AM
Will someone plz elp me out

Komat
10-01-2006, 03:35 AM
Originally posted by glBomb:
I would like someone to confirm that the above calculations are correct & this is in fact te way opengl alpa blends
ESP IS MY FINAL ALPHA VALUE OF 0.75 CORRECT? SHOULDNT IT TOTAL TO ONE ?
It should be the 0.75 however if the pixel format you are using for rendering does not contain alpha channel, the calculated alpha value will be lost and will be equal to 1 for all further blends.

glBomb
10-01-2006, 05:09 AM
Oh ok thanks a lot Komat. :)