Kineme GL Blend

yanomano's picture

To prevent black fringe around glow or luminous edges, I need a Special blend mode that creates an alpha channel based on the maximum luminance of the RGB channels, then make the RGB channels "un-premultiplied". I can do it with a core image kernel, but i need it at the root blending level of the patch ... Does the kineme GL Blend Equation can help me or something else ?

THX.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
example?

Can you provide an example?

the GL Blend modes aren't particularly powerful for this sort of thing (they're all channel-independent, so luma isn't possible).

GLSL could probably do this for you at the level you're wanting it.

yanomano's picture
Blend exemple

Here is an exemple : alpha generated by rgb max. This is specialy useful to blend glow, light, fire, lens flare and based particles on cleary backgrounds without black fringe... This actualy works but i need this principe inside an iterator with a lot of (different images) iterations and in this case a CI kernel on each would be very fat for FPS....

PreviewAttachmentSize
rgb max to alpha.qtz1.41 MB

cwright's picture
preprocess

Your best bet is to pre-process the images (if there's a fixed number), either manually, or with this method in QC (outside of the iterator).

unpremultiply isn't used for anything in this sample -- unpremultiply takes the color values, and divides by alpha -- in these examples, alpha is always one, so the division isn't doing anything (R/1 = R, etc.)

It should be possible in GLSL (without severe performance loss), if you want to go that route.

GL Blend cannot do this -- all the blend modes available do simple addition, subtraction, and multiplication (no division for unpremultiply), and no compares between components (for the max's).

yanomano's picture
Can't preprocess

My exemple was not ideal. (because of no alpha on images ;) Here is a much better one. To be more precise it is about a Fxplug based on a QC comp that is embed in a host. My problem is with particles blending : each particle is layered with the add blending mode. The alpha value is generated from the addition of each opacity of each particle. So I can't preprocess because original images (letters in this case) have a full plain alpha.

PreviewAttachmentSize
ParticleBlendingPB.jpg
ParticleBlendingPB.jpg481.6 KB

psonice's picture
premultiply

It's definitely premultiplication. If you want it at the root level of the patch, why not put the whole patch in a render in image? Then you can just add a CI filter with

return premultiply(sample(image, coords));

and connect to a billboard. It should be pretty fast.

yanomano's picture
can't premultiply all:)

I was trying to do it without RII because of differents composited nodes that i need to keep separated (animated Text+motionblur+particle+special background). the ideal is to render each node in a separated render to image patch then process, but this will kill the FPS on lower end GPU...

psonice's picture
back to GL blend then?

Ok, if that's not practical, back to your original suggestion of the GLBlend modes:

"The premulitplied blending function, with its alpha channel ignored, can be emulated by this function:

gBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);"

Is this function available in the blend modes at all?

cwright's picture
/me checks the GLTools source

We reverse engineered the Blend port to extend it with our Alpha blend mode. Here's the pertinent part:

   switch(mode)
   {
      case 0: // replace
         sfunc = dfunc = GL_ZERO;
         break;
      case 1:   // over
         sfunc = GL_ONE;
         dfunc = GL_ONE_MINUS_SRC_ALPHA;
         break;
      case 2:   // add
         sfunc = dfunc = GL_ONE;
         break;
      case 3:   // Alpha!
         sfunc = GL_SRC_ALPHA;
         dfunc = GL_ONE_MINUS_SRC_ALPHA;
   }

So it looks like the built-in Over mode should do it.

yanomano's picture
Thanks

Thanks to both of you. I think that RII with a custom CI will work.