PDA

View Full Version : Setting blending-function in GLSL



hlewin
08-24-2013, 08:07 AM
Hello!

Would it be possible to set the blending-functions to be used for a fragment from withing a fragment shader to allow constructs like


if(someCondition) gl_DstBlendFactor = X;
else gl_DstBlendFactor = Y;


Searching for this I've found this old thread (http://www.opengl.org/discussion_boards/showthread.php/164194-GLSL-blend-functions) and wonder what happened. Nonetheless something like the above, which I deem much simpler, would be enough for my needs.
Or is there already such functionality which google won't show me?

Alfonse Reinheart
08-24-2013, 09:34 AM
Would it be possible

Not in any hardware currently existing. Or at least, not in any hardware currently existing that isn't capable of implementing blending in the fragment shader (http://www.khronos.org/registry/gles/extensions/EXT/EXT_shader_framebuffer_fetch.txt).

Now, you can use dual source blending (https://www.opengl.org/wiki/Blending#Dual_Source_Blending). This won't let you change the actual blending factor, but it will give you a second color output, which could be applied to the destination color. You can affect the value, but of course, it has to be a value accessible/computeable from the fragment shader (ie: not based on the destination color).


Searching for this I've found this old thread and wonder what happened.

What do you mean "what happened?" Posting things on this forum has little if any bearing on what actually gets into OpenGL. Just because someone asked for something doesn't mean that it was ever going to happen.

hlewin
08-24-2013, 09:57 AM
What do you mean "what happened?" Posting things on this forum has little if any bearing on what actually gets into OpenGL. Just because someone asked for something doesn't mean that it was ever going to happen.
That's clear. Nonetheless the extension you linked is a proof that thought has already been spent on the issue be it for whatever reason.
Altough - that's an oppinion - I'd say that - if going to make blending programmable - this should definitely be done in a pipeline-stage for it's own.

Regarding the extension you linked: This is an ES-extension. Are those actually ever intended to be available in general GL?

I'll have a closer look on dual-source blending. I cannot intuitively say if/how this is going to solve the issue. Maybe I'll have to use the stencil and render things twice.

Alfonse Reinheart
08-24-2013, 10:35 AM
Nonetheless the extension you linked is a proof that thought has already been spent on the issue be it for whatever reason.

Or that a particular piece of hardware just so happened to be able to provide the functionality as an outgrowth of the basic hardware design (being a tile-based renderer, for example).


Are those actually ever intended to be available in general GL?

No. I was simply pointing out that there is hardware that can pull off programmatic blending directly. I could not simply say "no hardware can do what you want", because hardware that implements that extension can.

hlewin
08-24-2013, 10:59 AM
Okay. Thank you.

I've often asked myself the question if there're documents publicly available that describe the actual functionality of graphics-hardware in how they work exactly. There seems to be much consideration about intellectual property rights in this area - at least the last times I googled for such things. This makes judgeing many aspects that a programmer is confronted with when using an API like OpenGL quite difficult. The CPU and the hardware in general seems to be a lot better documented - at least when looking at PC hardware - from a public point of view.