Well, if the first factor is GL_ONE, black will be transparent. The second factor is what shows through from the second object.
--------------------------------------
I am the master of stories.....
If only I could just write them down...
ARRRGG!!! Depth-testing and Transparency
A blending equation of GL_ONE, GL_ONE_MINUS_SRC_COLOR means that you final pixel = Rs + Rd(1 - Rs), Gs + Gd(1 - Gs), Bs + Bd(1 - Bs), where Rs, Gs and Bs = Red, Green and Blue components of the fragment you are adding to the framebuffer and Rd, Gd and Bd = Red, Green and Blue components of the pixel already in the framebuffer.
Lets test this with a black fragment blended into an arbitrary coloured pixel in the framebuffer:
final pixel = 0 + Rd(1 - 0), 0 + Gd(1 - 0), 0 + Bd(1 - 0)
final pixel = Rd, Gd, Bd
so black fragments become transparent.
And for a white fragment:
final pixel = 1 + Rd(1 - 1), 1 + Gd(1 - 1), 1 + Bd(1 - 1)
final pixel = 1, 1, 1
so white fragments are fully opaque.
People seem to get very confused about blending equations, so lets look at all the possible blending equations not involving alpha (there are 16 in total):
*There are bound to be mistakes in here somewhere - if you spot one, let me know and I''ll edit this post*
GL_ZERO, GL_ZERO:
final pixel = 0, 0, 0
final pixel is always black.
GL_ZERO, GL_ONE:
final pixel = Rd, Gd, Bd
framebuffer does not change.
GL_ZERO, GL_SRC_COLOR:
final pixel = RdRs, GdGs, BdBs
final pixel is the modulation of the two inputs. Blending in a white fragment leaves the framebuffer unchanged. Blending in a Pure green fragment removes the Red and Blue components from the framebuffer.
GL_ZERO, GL_ONE_MINUS_SRC_COLOR:
final pixel = Rd(1 - Rs), Gd(1 - Gs), Bd(1 - Bs)
pixel from frame buffer is reduced in intensity, depending on colour blended in. Blending in a white fragment will result in a black pixel output. Blending in a pure green fragment will remove the green component of the framebuffer pixel.
GL_ONE, GL_ZERO:
final pixel = Rs, Gs, Bs
framebuffer pixel is replaced by the blended fragment.
GL_ONE, GL_ONE:
final pixel = Rs + Rd, Gs + Gd, Bs + Bd
blended fragment and framebuffer pixel are added. Blending in a black fragment leaves the framebuffer unchanged. Blending in a pure green fragment makes the output pixel ''more green''.
GL_ONE, GL_SRC_COLOR:
final pixel = Rs + RdRs, Gs + GdGs, Bs + BdBs
this one is more complicated. Blending in a black fragment results in a black pixel. Blending in a pure green fragment results in a pure green pixel. Blending in a 50% blue fragment results in a blue pixel of intensity 0.5 + (framebuffer blue intensity * 0.5).
GL_ONE, GL_ONE_MINUS_SRC_COLOR:
final pixel = Rs + Rd(1 - Rs), Gs + Gd(1 - Gs), Bs + Bd(1 - Bs)
this one we''ve already seen. Blending in a pure green fragment results in a pixel with Red and Blue components from the framebuffer and pure Green component.
GL_DST_COLOR, GL_ZERO:
final pixel = RsRd, GsGd, BsBd
identical to GL_ZERO, GL_SRC_COLOR
GL_DST_COLOR, GL_ONE:
final pixel = RsRd + Rd, GsGd + Gd, BsBd + Bd
same as GL_ONE, GL_SRC_COLOR but roles of blended fragment and framebuffer pixel are reversed. Blending in a black fragment leaves the framebuffer unchanged. Blending in a pure Green fragment doubles the Green component of the framebuffer.
GL_DST_COLOR, GL_SRC_COLOR:
final pixel = RsRd + RdRs, GsGd + GdGs, BsBd + BdBs
final pixel is the double the modulation of the two inputs. Blending in a white fragment doubles the brightness of the framebuffer fragment. Blending in a Pure green fragment removes the Red and Blue components from the framebuffer and doubles the Green component.
GL_DST_COLOR, GL_ONE_MINUS_SRC_COLOR:
final pixel = RsRd + Rd(1 - Rs), GsGd + Gd(1 - Gs), BsBd + Bd(1 - Bs)
simplify the equation and you''ll see that this is exactly the same as GL_ZERO, GL_ONE.
GL_ONE_MINUS_DST_COLOR, GL_ZERO:
final pixel = Rs(1 - Rd), Gs(1 - Gd), Bs(1 - Bd)
same as GL_ZERO, GL_ONE_MINUS_SRC_COLOR but roles of blended fragment and framebuffer pixel are reversed. Blending in a black fragment results in a black pixel. Blending in a white fragment results in the inverse of the original framebuffer pixel. Blending in a pure Green fragment results in a green pixel of intensity = 1 - intensity of original framebuffer pixel.
GL_ONE_MINUS_DST_COLOR, GL_ONE:
final pixel = Rs(1 - Rd) + Rd, Gs(1 - Gd) + Gd, Bs(1 - Bd) + Bd
identical to GL_ONE, GL_ONE_MINUS_SRC_COLOR.
GL_ONE_MINUS_DST_COLOR, GL_SRC_COLOR:
final pixel = Rs(1 - Rd) + RdRs, Gs(1 - Gd) + GdGs, Bs(1 - Bd) + BdBs
identical to GL_ONE, GL_ZERO
GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR:
final pixel = Rs(1 - Rd) + Rd(1 - Rs), Gs(1 - Gd) + Gd(1 - Gs), Bs(1 - Bd) + Bd(1 - Bs)
errr... Blending in a white fragment results in the inverse of the original framebuffer pixel. Blending in a black fragment results in a black pixel. Blending in a red pixel of 40% intensity results in a red pixel of intensity = 0.4 + 0.2 * red intensity of original framebuffer pixel.
Hope this helps people to get a handle to the blending equations,
Enigma
Lets test this with a black fragment blended into an arbitrary coloured pixel in the framebuffer:
final pixel = 0 + Rd(1 - 0), 0 + Gd(1 - 0), 0 + Bd(1 - 0)
final pixel = Rd, Gd, Bd
so black fragments become transparent.
And for a white fragment:
final pixel = 1 + Rd(1 - 1), 1 + Gd(1 - 1), 1 + Bd(1 - 1)
final pixel = 1, 1, 1
so white fragments are fully opaque.
People seem to get very confused about blending equations, so lets look at all the possible blending equations not involving alpha (there are 16 in total):
*There are bound to be mistakes in here somewhere - if you spot one, let me know and I''ll edit this post*
GL_ZERO, GL_ZERO:
final pixel = 0, 0, 0
final pixel is always black.
GL_ZERO, GL_ONE:
final pixel = Rd, Gd, Bd
framebuffer does not change.
GL_ZERO, GL_SRC_COLOR:
final pixel = RdRs, GdGs, BdBs
final pixel is the modulation of the two inputs. Blending in a white fragment leaves the framebuffer unchanged. Blending in a Pure green fragment removes the Red and Blue components from the framebuffer.
GL_ZERO, GL_ONE_MINUS_SRC_COLOR:
final pixel = Rd(1 - Rs), Gd(1 - Gs), Bd(1 - Bs)
pixel from frame buffer is reduced in intensity, depending on colour blended in. Blending in a white fragment will result in a black pixel output. Blending in a pure green fragment will remove the green component of the framebuffer pixel.
GL_ONE, GL_ZERO:
final pixel = Rs, Gs, Bs
framebuffer pixel is replaced by the blended fragment.
GL_ONE, GL_ONE:
final pixel = Rs + Rd, Gs + Gd, Bs + Bd
blended fragment and framebuffer pixel are added. Blending in a black fragment leaves the framebuffer unchanged. Blending in a pure green fragment makes the output pixel ''more green''.
GL_ONE, GL_SRC_COLOR:
final pixel = Rs + RdRs, Gs + GdGs, Bs + BdBs
this one is more complicated. Blending in a black fragment results in a black pixel. Blending in a pure green fragment results in a pure green pixel. Blending in a 50% blue fragment results in a blue pixel of intensity 0.5 + (framebuffer blue intensity * 0.5).
GL_ONE, GL_ONE_MINUS_SRC_COLOR:
final pixel = Rs + Rd(1 - Rs), Gs + Gd(1 - Gs), Bs + Bd(1 - Bs)
this one we''ve already seen. Blending in a pure green fragment results in a pixel with Red and Blue components from the framebuffer and pure Green component.
GL_DST_COLOR, GL_ZERO:
final pixel = RsRd, GsGd, BsBd
identical to GL_ZERO, GL_SRC_COLOR
GL_DST_COLOR, GL_ONE:
final pixel = RsRd + Rd, GsGd + Gd, BsBd + Bd
same as GL_ONE, GL_SRC_COLOR but roles of blended fragment and framebuffer pixel are reversed. Blending in a black fragment leaves the framebuffer unchanged. Blending in a pure Green fragment doubles the Green component of the framebuffer.
GL_DST_COLOR, GL_SRC_COLOR:
final pixel = RsRd + RdRs, GsGd + GdGs, BsBd + BdBs
final pixel is the double the modulation of the two inputs. Blending in a white fragment doubles the brightness of the framebuffer fragment. Blending in a Pure green fragment removes the Red and Blue components from the framebuffer and doubles the Green component.
GL_DST_COLOR, GL_ONE_MINUS_SRC_COLOR:
final pixel = RsRd + Rd(1 - Rs), GsGd + Gd(1 - Gs), BsBd + Bd(1 - Bs)
simplify the equation and you''ll see that this is exactly the same as GL_ZERO, GL_ONE.
GL_ONE_MINUS_DST_COLOR, GL_ZERO:
final pixel = Rs(1 - Rd), Gs(1 - Gd), Bs(1 - Bd)
same as GL_ZERO, GL_ONE_MINUS_SRC_COLOR but roles of blended fragment and framebuffer pixel are reversed. Blending in a black fragment results in a black pixel. Blending in a white fragment results in the inverse of the original framebuffer pixel. Blending in a pure Green fragment results in a green pixel of intensity = 1 - intensity of original framebuffer pixel.
GL_ONE_MINUS_DST_COLOR, GL_ONE:
final pixel = Rs(1 - Rd) + Rd, Gs(1 - Gd) + Gd, Bs(1 - Bd) + Bd
identical to GL_ONE, GL_ONE_MINUS_SRC_COLOR.
GL_ONE_MINUS_DST_COLOR, GL_SRC_COLOR:
final pixel = Rs(1 - Rd) + RdRs, Gs(1 - Gd) + GdGs, Bs(1 - Bd) + BdBs
identical to GL_ONE, GL_ZERO
GL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_SRC_COLOR:
final pixel = Rs(1 - Rd) + Rd(1 - Rs), Gs(1 - Gd) + Gd(1 - Gs), Bs(1 - Bd) + Bd(1 - Bs)
errr... Blending in a white fragment results in the inverse of the original framebuffer pixel. Blending in a black fragment results in a black pixel. Blending in a red pixel of 40% intensity results in a red pixel of intensity = 0.4 + 0.2 * red intensity of original framebuffer pixel.
Hope this helps people to get a handle to the blending equations,
Enigma
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement