Discussion: BlendFuncs theory

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Post Reply
cityy
Posts: 1020
Joined: Mon Aug 10, 2009 8:23 am

Discussion: BlendFuncs theory

Post 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.
www.ferdinandlist.de/leveldesign
cityy
Posts: 1020
Joined: Mon Aug 10, 2009 8:23 am

Re: Discussion: BlendFuncs theory

Post by cityy »

More stuff describing the src and dst blends: http://www.opengl.org/sdk/docs/man/xhtm ... ndFunc.xml
www.ferdinandlist.de/leveldesign
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Discussion: BlendFuncs theory

Post 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
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
User avatar
GONNAFISTYA
Posts: 13369
Joined: Sun Jan 23, 2005 8:20 pm

Re: Discussion: BlendFuncs theory

Post by GONNAFISTYA »

Image
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Re: Discussion: BlendFuncs theory

Post by obsidian »

Image
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
User avatar
CZghost
Posts: 1943
Joined: Wed Jun 22, 2011 1:45 pm
Location: Czechia
Contact:

Re: Discussion: BlendFuncs theory

Post by CZghost »

Dr. Frinkenstein :olo:
Simpsons lives!
[ Linktree | Twitch | YouTube | Instagram | Websites ]
When you feel the worst, turn to the sun and all the shadows will fall behind you.” - John Lennon
Post Reply