Search code examples
openglblending

Highlighter blend func OpenGL


What is the standard builtin blend function used to implement a highlighter in OpenGL? Using glBlendEquation(GL_MIN); produces the desired effect but does not allow for opacity-based blending as well. I am modeling transparency using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Is it possible to account for opacity using min blending? If not, is it best to use a custom shader with a frame buffer object?

For reference, here is an example of the desired result (not rendered using OpenGL):

enter image description here


Solution

  • I ended up rendering highlight-able elements to floating point texture and blending using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);. This intermediate frame buffer can then be blended with the default framebuffer 0 using the same blend function. Subtractive blending can be emulated by multiplying the rgb components of the final value in the fragment shader by -1. Floating point textures support negative values and are typically write-able as frame buffer color attachments. See Blend negative value into framebuffer 0 opengl for more information.