Need an alpha blend which relates to something in the background
The subject might seem a bit cryptic. I could not find a short description.
I am developing an application where various more or less transparent objects are rendered in such a way that the resulting graphics can be blended with a videosignal, based on the alpha values.
The videosignal will allways be located deeper in the scene than the other elements. Therefore I need the final framebuffer alpha to represent how "solid" the other elements are and how much the obscure the videosignal.
If I have two surfaces, one in front of the other, and both are 50% opague, then the two together would be 75% opague, and the videosignal should be blended into the scene with a 25% strength. but... if I render those two objects, then the result will end out being 50% for the both of them.
destinatio*invSourceAlpha + Source*sourceAlpha will give me a correct color, but the alpha will be blended to 0.5*(1-0.5)+0.5*0.5=0.5 and not the desired 0.75.
If this is not too unclear, how can I go about making that blend? The graphics card does not support seperate alpha blend.
Hi,
supposing you have n textures (D3DFMT_A8R8G8B8) to blend. Then you can setup 2 textures (D3DFMT_A8R8G8B8, Render Targets) as temporary result buffers, we call they ResTexture and ResTexture2.
So use a pixel shader to blend texture1 with texture2 storing the result in ResTexture.
Then reuse the pixel shader to blend ResTexture with texture3 storing result in ResTexture2.
Then reuse the pixel shader to blend ResTexture2 with texture4 storing result in ResTexture.
Then reuse the pixel shader to blend ResTexture with texture5 storing result in ResTexture2.
...
until you blend all the textures together (the result is in the last temporary texture used: ResTexture or ResTexture2).
With a pixel shader you can use your own custom blending function for all the 4 channels independently. Also, if you need more precision (AND if your video card permit it!), you can use floating point textures to have a great blending accuracy.
My 2 cents,
AGPX
You want to use destination blending, and the separate alpha blend function.
You want the alpha blend factor to be INVDSTALPHA, ONE, so that the destination alpha value is preserved, and then the source alpha is added to that, scaled by how much there's left of the range to blend.