This has been getting longer than I thought in the first place... Hope this is of some help to you.
On Apr 21, 06 12:28:59 +0300, Jaakko Hyvätti wrote: > If OpenGL is used for creating images with transparency, and images and > drawing primitives are rendered on transparent background, the OpenGL If drawing using the over operator, you can either draw front-to-back or back-to-front. For back-to-front you use glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for nonweighted source, or glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA); for weighted source. Weighting means that the color (rgb) is already multiplied with alpha (in the visualization community this is sometimes called premultiplied alpha. There have been endless debates whether working with premultiplied alpha is better or not due to rounding issues. Nothing to be concerned if you're not rendering several dozen semintransparent layers for volume rendering). For front-to-back you need a color buffer with alpha channel, and you draw with glBlendFunc (GL_ONE_MINUS_DST_ALPHA, GL_ONE) AFAIR correctly, but who renders front-to-back anyway? Note that front-to-back does not work with nonweighted source, because you would need two factors for source color. Both variants implement the over operator and are thus correct. And no, you cannot mix render direction, semitransparent surfaces haved to be ordered to be rendered correctly, as the over operator is not commutative. Now please define 'drawn on transparent background'. Colors in the framebuffer are always weighted. If you're rendering front-to-back, there even is no destination alpha in the frame buffer at all. If you draw *on* another surface (i.e. front-to-back), the transparency of that surface is irrelevant. Heck, it isn't even known any more (no destination alpha). > The extended version of this common function fixes the problem with > incorrect Alpha values in the resulting image, but fails to fix the > color channels: glBlendFuncSeparateEXT is only need for exotic composite operators, not for the over operator. > glBlendFuncSeparateEXT (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, > GL_ONE, GL_ONE_MINUS_SRC_ALPHA); > > The color channels are mixed with these settings with this formula: > (Example for Red) > > Rd = destination Red > Ad = destination Alpha > Rs = source Red > As = source Alpha > R' = result destination Red > A' = result destination Alpha > > A' = As + (1 - As) * Ad > R' = As * Rs + (1 - As) * Ad This is incorrect. Correct is R' = As * Rs + (1 - As) * Rd I guess this was a typo. > Example: > As = 0.5 > Rs = 0.8 > Ad = 0 > Rd = 0.2 > > R' = As * Rs + (1 - As) * Ad = 0.5 * 0.8 + 0.5 * 0.2 > = 0.5 > > This is incorrect, the correct R' is obviously 0.8, because Ad = 0, and Rd > should not affect the resulting colour at all! The solution is to compute Colors in the framebuffer are always weighted, that is alpha is already included in the color value. You can see R=0.8 / A=0 as some translucent self-luminescent red color. I repeat: If you're rendering front-to-back, there is no destination alpha in the frame buffer at all. Ad will always be 1 AFAIR. But that is irrelevant in this case, because A' is not calculated at all (because it is not stored). If you're having a framebuffer with alpha, it might be calculated, but again, it is never used because DST_ALPHA isn't used anywhere. I think you should read a 3D programming book (e.g. Foley/Van Damm 'Computer Graphics) to understand these issues better. > This is correct. These patches create extension GL_FORECA_blend_relative > that introduces Blending Functions GL_SRC_ALPHA_RELATIVE_FORECA and > GL_ONE_MINUS_SRC_ALPHA_RELATIVE_FORECA that can be used to implement > the latter formula: The ideas about these patches are wrong AFAICS. Matthias -- Matthias Hopf <[EMAIL PROTECTED]> __ __ __ Maxfeldstr. 5 / 90409 Nuernberg (_ | | (_ |__ [EMAIL PROTECTED] Phone +49-911-74053-715 __) |_| __) |__ labs www.mshopf.de ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642 _______________________________________________ Mesa3d-dev mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/mesa3d-dev
