OpenGL Subtract Blend Functions?
by Chase Webb · in Torque 2D Professional · 08/12/2013 (6:59 am) · 10 replies
So, I've been spending a lot of time in the Beginner forum lately working on this: www.garagegames.com/community/forums/viewthread/134697
I've been searching the source code trying to find any reference to the subtract function. The following two pages are what led me to look for it:
www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml
www.opengl.org/sdk/docs/man/xhtml/glBlendEquation.xml
My biggest stumbling block is probably not knowing what the memory address things are, like this:
As far as I can tell that's the only place the subtract option is mentioned.
With that all said, does anyone have any suggestions for what to do next? I would REALLY like to be able to get a proper blending subtraction going on so I can fake a lighting system.
I've been searching the source code trying to find any reference to the subtract function. The following two pages are what led me to look for it:
www.opengl.org/sdk/docs/man/xhtml/glBlendFunc.xml
www.opengl.org/sdk/docs/man/xhtml/glBlendEquation.xml
My biggest stumbling block is probably not knowing what the memory address things are, like this:
#define GL_FUNC_ADD 0x8006 #define GL_FUNC_SUBTRACT 0x800A #define GL_FUNC_REVERSE_SUBTRACT 0x800B #define GL_BLEND_COLOR 0x8005
As far as I can tell that's the only place the subtract option is mentioned.
With that all said, does anyone have any suggestions for what to do next? I would REALLY like to be able to get a proper blending subtraction going on so I can fake a lighting system.
#2
Additionally, I don't think you're looking specifically for a "subtract" function, probably should be looking for a "blend" function that takes that GL_FUNC_SUBTRACT value as a parameter. At least it's not T3D so you don't have to dig through piles of shaders too!
08/12/2013 (10:40 am)
And, just to be a jerk I'll point out that these are not addresses, just values:#define GL_FUNC_ADD 0x8006 #define GL_FUNC_SUBTRACT 0x800A #define GL_FUNC_REVERSE_SUBTRACT 0x800B #define GL_BLEND_COLOR 0x8005They're really just mnemonic devices so that when you call OpenGL functions you can use GL_FUNC_ADD instead of trying to remember what 0x8006 means. This might have been better implemented as an enumeration, but I guess there was some reason for this method instead.
Additionally, I don't think you're looking specifically for a "subtract" function, probably should be looking for a "blend" function that takes that GL_FUNC_SUBTRACT value as a parameter. At least it's not T3D so you don't have to dig through piles of shaders too!
#3
If you search through all files in the solution, you'll see that such variables are used throughout the code, mainly nestled into important rendering functions.
For instance, in Torque2D/graphics/ImageAsset.h :
As long as you know the OpenGL call you wish to make, you'll "simply" have to dig around the code to see where that function makes sense.
I am by no means an OpenGL expert and the windows implementation can get quite confusing.
08/12/2013 (12:21 pm)
All exposed GL functions are simply the address of the function within the OpenGL.dll or library.If you search through all files in the solution, you'll see that such variables are used throughout the code, mainly nestled into important rendering functions.
For instance, in Torque2D/graphics/ImageAsset.h :
inline const void bindImageTexture( void){ glBindTexture( GL_TEXTURE_2D, getImageTexture().getGLName() ); };As long as you know the OpenGL call you wish to make, you'll "simply" have to dig around the code to see where that function makes sense.
I am by no means an OpenGL expert and the windows implementation can get quite confusing.
#4
www.andersriggelsen.dk/glblendfunc.php
08/12/2013 (12:44 pm)
Found this nifty little tool to test all OpenGL blending functions!www.andersriggelsen.dk/glblendfunc.php
#5
08/12/2013 (1:11 pm)
Nice find Simon, I'll add that to the blending guide.
#6
Going back to the 'fog-of-war' problem, the method you have found (Mike) works well, until you add more sprites to different layers, as they all get modulated by the colors of items beneath(father away from) them!
The Substract functionality that Chase has been after really tickles me, I will definitely try to investigate this issue.
08/12/2013 (1:15 pm)
Can't believe I never found this before.Going back to the 'fog-of-war' problem, the method you have found (Mike) works well, until you add more sprites to different layers, as they all get modulated by the colors of items beneath(father away from) them!
The Substract functionality that Chase has been after really tickles me, I will definitely try to investigate this issue.
#7
Richard: Thanks for clearing that up for me. I have no experience working with dlls :/
Simon: That page looks really good as an example of what I've been looking for! For my own example in the other thread, I'm hoping to have the top two layers of my scene be darkness and the layer that creates the holes in the darkness to show what's underneath. And you are right, the problem with Mike's solution is that everything underneath gets affected. Hopefully you will have better luck than I have on figuring out what to do next.
Edit: A good example of what I mean in Simon's link:
foreground: ONE_MINUS_SOURCE_ALPHA
Background: Gl_SRC_ALPHA
Blend Equation: GL_FUNC_REVERSE_SUBTRACT
I'm not sure how that will work with more layers, but at the moment it seems like a good example.
08/12/2013 (6:09 pm)
practicing: That's the first place I started looking :P I had hoped some combination of layers and values would allow for the transparency effect I wanted, but it was not so.Richard: Thanks for clearing that up for me. I have no experience working with dlls :/
Simon: That page looks really good as an example of what I've been looking for! For my own example in the other thread, I'm hoping to have the top two layers of my scene be darkness and the layer that creates the holes in the darkness to show what's underneath. And you are right, the problem with Mike's solution is that everything underneath gets affected. Hopefully you will have better luck than I have on figuring out what to do next.
Edit: A good example of what I mean in Simon's link:
foreground: ONE_MINUS_SOURCE_ALPHA
Background: Gl_SRC_ALPHA
Blend Equation: GL_FUNC_REVERSE_SUBTRACT
I'm not sure how that will work with more layers, but at the moment it seems like a good example.
#8
08/12/2013 (9:14 pm)
I don't have time to play with this further, but if source changing is being discussed - what about adding a blending layer bitmask that works similar to the collision layer bitmask where you can specify certain layers to blend with each other and any other layer gets ignored?
#9
08/12/2013 (9:44 pm)
I COMPLETELY second Mike's request.
#10
08/12/2013 (10:43 pm)
Not quite a request :) I am just throwing the idea out there. Another thing to check is what happens to objects, that you don't want to be affected, when you turn their blending mode off. Also remember that the blending factors are always controlled by the source (foreground) object.
Torque Owner practicing01
MourningDoveSoft
0x800B for GL_FUNC_REVERSE_SUBTRACT_EXT?
Edit: oh.... just read the posts, these are not the droids you're looking for..
Are you looking for this:
More info is located within the sceneobject source.