![]() |
|
al_set_separate_blender() help |
thebignic
Member #14,419
July 2012
|
I've attached an image of the problem I'm having with blend modes in 5.0.10 (mingw, codeblocks) I have two images that I'm drawing to scene. The source image I'm drawing are tiny blood splatters as they move through the air. The destination image is the concrete and wood parts of the background with alpha=0 for the air. I then draw that destination image to screen. The blood splatter shouldn't be drawn in the air (alpha 0 where it appears pink) but only when the destination layer's alpha is 1. I've been banging my head on this for a day now, and cannot simply do a masked draw to a bitmap. Relevant code when drawing splatter to background image: al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); From my understanding (based solely on the documentation of al_set_blender, why is there no thorough documentation for al_set_separate_blender?) the colour component will be additive, where the source colour is multiplied by the source alpha (1 or 0) and the destination colour will be multiplied by (1-source alpha, so 0 or 1) which seems to be fine. But the alpha channel, as far as I can tell, I'm saying I want to add them, but I only want to use the destination pixels alpha, ever. So if destination alpha is 0, then alpha of drawn pixel should be zero, and if destination alpha is 1, then the alpha of drawn pixel should be one. And that does not appear to be what I'm getting. This blender stuff has vexed me since day one, and I swear I have a handle on it now, but the function doesn't appear to be doing what I think I'm telling it to do. Is this a bug or am I still confused ? I draw this stuff to background and then set blending back to the default state (that works fine for everything else) before I draw the background image to screen: al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); I don't imagine this is a problem since the alpha on the intermediate background image shouldn't be getting anything but zero written to it where there are already zeros... Help?!
|
Elias
Member #358
May 2000
|
Well, just take an example pixel and see what happens applying the formulas from the documentation. Let's say a blood source pixel is 1,0,0,1. Let's say the air pixel in the intermediate bitmap is 0,0,0,0. You do this: al_set_separate_blender(ALLEGRO_ADD, ALLEGRO_ALPHA,ALLEGRO_INVERSE_ALPHA, ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_ONE); So the result is: red = 1 * 1 + 0 * 0 = 1 green = 0 * 1 + 0 * 0 = 0 blue = 0 * 1 + 0 * 0 = 0 alpha = 1 * 0 + 0 * 1 = 0 That means the color in the intermediate bitmap now is 1,0,0,0. Now let's assume the destination is black 0,0,0,1 and you say you draw with: al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); This means: red = 1 * 1 + 0 * 1 = 1 green = 0 * 1 + 0 * 1 = 0 blue = 0 * 1 + 0 * 1 = 0 alpha = 0 * 1 + 1 * 1 = 1 You could try drawing the final picture with: al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA); That way all pixels where alpha is zero (there was air) never get drawn at all. -- |
thebignic
Member #14,419
July 2012
|
Ok, so it was drawing the intermediate to the screen which was the problem. I thought it might be but I couldn't visualize it. I think the hangup was that I assumed since the alpha was zero, the colour information wouldn't be written to the intermediate bitmap. The alpha is applied AFTER the fact, not modifying the sourceAlpha and 1-sourceAlpha. Thanks!
|
|