Page 1 of 1

Discussion: BlendFuncs theory

Posted: Mon Jul 01, 2013 9:15 am
by cityy
So I am trying to get my head around the topic of what blendfuncs actually do, how they work.

I started off the shader manual and this article.
From what I understand blendfuncs define how a polygon of a surface covered with your shader gets projected onto what is already on screen.
ShaderManual wrote:[Source * <srcBlend>] + [Destination * <dstBlend>]
Now I am trying to figure how to put the blendfuncs in words

1) gl_one (source) gl_one (screen) ||| result = 1 (polygon) + 1 (screen) = addition (blendfunc add)
2) gl_one gl_zero ||| result = 1 (polygon) + 0 (screen) = polygon is fully opaque

3) dl_dst_color gl_zero
This is where I start to struggle, technically, this blendfunc is supposed to multiply the source (polygon) rgb values with the screen below it. What I don't get is why the destination value is gl_zero and not gl_one since in my mind gl_zero implies 0 and a multiplication with 0 remains 0 or in other words black.

4) gl_zero gl_src_color
Is this equivalent to 3) since it is also a multiplication?

5) dst_color src_color
How does this work?

Would appreciate if you guys could help me get in on this.

Re: Discussion: BlendFuncs theory

Posted: Mon Jul 01, 2013 9:24 am
by cityy
More stuff describing the src and dst blends: http://www.opengl.org/sdk/docs/man/xhtm ... ndFunc.xml

Re: Discussion: BlendFuncs theory

Posted: Mon Jul 01, 2013 5:30 pm
by obsidian
Why aren't you linking to the new shader manual?

The source is the texture's pixels.
The destination is whatever is currently in the frame buffer, whether it be a texture or a polygon in the distance.

You're getting the idea with gl_one and gl_zero, they fill in one or zero values. When it comes to gl_dst_color and gl_src_color, these mean that it copies the destination and source colour pixels. What you're getting confused is that you're thinking of the two halves of the equation to mean explicitly source on one side and destination on the other, when really they are more like channels and what is important is the result. While you may have one half of the equation equal zero, you still haven't calculated the other half to determine the resulting value.


  1. gl_one gl_one means...

    Code: Select all

    source * 1 + destination * 1
    We call this an additive effect because the source (as it appears) is added to the values of the destination (as it appears) and the result is written to the frame buffer.
  2. gl_one gl_zero is the default for most surfaces because it means...

    Code: Select all

    source * 1 + destination * 0
    You are right in that the source is 100% opaque and will overwrite whatever was previously in the frame buffer since that now has a zero value.
  3. gl_dst_color gl_zero means...

    Code: Select all

    source * copy of destination color + destination * zero
    While the right side of the "+" results in zero, the left side still results in something... it is "multiplicative" because it is the source * copy of destination color
  4. The same is true for the reverse of this equation, gl_zero gl_src_color...

    Code: Select all

    source * zero + destination * copy of source color
    Now the left size is zero, but the right side is the destination multiplied with the copy of the source colour, which results in the exact same thing as the equation above, it is just flipped.
  5. So... gl_dst_color gl_src_color means...

    Code: Select all

    source * copy of destination color + destination * copy of source color
    This would be like two multiply blends added together.

/roflmath

Re: Discussion: BlendFuncs theory

Posted: Mon Jul 01, 2013 7:01 pm
by GONNAFISTYA
Image

Re: Discussion: BlendFuncs theory

Posted: Mon Jul 01, 2013 9:17 pm
by obsidian
Image

Re: Discussion: BlendFuncs theory

Posted: Thu Jul 04, 2013 11:33 am
by CZghost
Dr. Frinkenstein :olo:
Simpsons lives!