Blend Mode - InvertColor

Hello!
Im trying to get with a blend that invert the colors of two shapes. For ex: a black circle overlaps a black circle = a white circle.
What do you think i can do?

Probably in a shader iwould do something like:

vec3(1.0)-(color1.xyz+color2.xyz)

but i want to do that kind of blend with two circles (or multiples but in one single texture)

you can use one of this addons or copy code from them:

ofxKsmrFragmentFx
ofxDotFrag

I used both to invert an fbo.

Thanks but this is not exactly what i need. Because that will working with an entire FBO, i only need to change the blend from the main FBO where the geometry is drawing, and do the blend with geomtrys not with FBO


This is what i want to do

ok, sorry.
this addon has a lot of blending modes to learn about:

like this one: BlendNegation

maybe you can test this tool too, to test some modes easily:
Visual glBlendFunc + glBlendEquation Tool
Even if you haven’t seen glBlendFunc(), you don’t need to worry about it. ofEnableBlend() is using glBlendFunc() internally
https://www.andersriggelsen.dk/glblendfunc.php

hope it helps in some way

glEnable(GL_BLEND);
glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR);

should work for that specific case, but also check the different combinations available for glBlendFunc to find exactly what you need. also glBlendEquation if you want to do something else than adding the diferent alphas and colors

Mmm… Thanks for the answers!
I dont sure if i understand how blend is working…

im doing this:

void ofApp::draw(){
   
    
//    ofBackground(255);
    
//    ofDisableAlphaBlending();
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE_MINUS_SRC_COLOR, GL_DST_COLOR);
    
    ofSetColor(0);
    ofFill();
    
    ofEllipse(ofGetWidth()/2, ofGetHeight()/2, 100, 100);
    ofEllipse(ofGetWidth()/2+50, ofGetHeight()/2, 100, 100);

    
    
}

and this is the result:

if i discoment the background i cant see the circles anymore.

void ofApp::setup() {
    ofSetBackgroundColor(255);
    ofSetCircleResolution(100);
}
void ofApp::draw() {
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO);
    ofSetColor(255);
    ofFill();
    for(int i = 0; i < 20; i++) {
        float sz = 50 + (i % 4) * 50;
        float x = ofGetWidth() * 0.33f + 50 * (i % 3);
        float y = ofGetHeight() * 0.33f + 50 * (i % 5);
        ofDrawCircle(x, y, sz);
    }
}

Found it here by searching for “glBlendFunc invert”.

1 Like