alpha mask shader multitexture

Hi

I try to make a simple thing, i want to mask an ofFbo with a ofImage. Something like spray paint with a template.
I want to use a shader for that and i have found this one https://github.com/Flightphase/ofxAlphaMask

The Fbo is filled with particles so it changes and the mask is a loaded ofImage.

Main relevant part of the code

  
  
testApp::setup(){  
    mascaraShader.load("shaders/composite");  
    mascaraShader.begin();  
    mascaraShader.setUniformTexture("Tex0", fboParticulas.getTextureReference(), 0);  
    mascaraShader.setUniformTexture("Tex1", ofImageMascara.getTextureReference(), 1);  
    mascaraShader.end();  
}  
testApp::update(){    
    fboParticulas.begin();  
    ofClear(255,0);  
    for (int i = 0; i<particulas.size(); i++) {  
    	particulas[i]->draw();  
    }  
    fboParticulas.end();  
  
    mascaraShader.begin();  
    mascaraShader.setUniformTexture("Tex0", fboParticulas.getTextureReference(), 0);  
    mascaraShader.setUniformTexture("Tex1", ofImageMascara.getTextureReference(), 1);  
    mascaraShader.end();  
}  
  
testApp::draw(){  
    ofEnableAlphaBlending();  
    //ofClear(255);  
    mascaraShader.begin();  
    //our shader uses two textures, the top layer and the alpha  
    //we can load two textures into a shader using the multi texture coordinate extensions  
    glActiveTexture(GL_TEXTURE0_ARB);  
    fboParticulas.getTextureReference().bind();  
    glActiveTexture(GL_TEXTURE1_ARB);  
    ofImageMascara.getTextureReference().bind();  
    //draw a quad the size of the frame  
    glBegin(GL_QUADS);  
    //move the mascara around with the mouse by modifying the texture coordinates  
    float mascaraOffset = 0;  
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 0);  
    glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, mascaraOffset);  
    glVertex2f( 0, 0);  
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 1200, 0);  
    glMultiTexCoord2d(GL_TEXTURE1_ARB, 1200, mascaraOffset);  
    glVertex2f( ofGetWidth(), 0);  
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 1200, 800);  
    glMultiTexCoord2d(GL_TEXTURE1_ARB, 1200, 800);  
    glVertex2f( ofGetWidth(), ofGetHeight());  
    glMultiTexCoord2d(GL_TEXTURE0_ARB, 0, 800);  
    glMultiTexCoord2d(GL_TEXTURE1_ARB, 0, 800);  
    glVertex2f( 0, ofGetHeight() );  
    glEnd();  
    //deactive and clean up  
    glActiveTexture(GL_TEXTURE1_ARB);  
    ofImageMascara.getTextureReference().unbind();  
    glActiveTexture(GL_TEXTURE0_ARB);  
    fboParticulas.getTextureReference().unbind();  
    mascaraShader.end();  
    ofDisableAlphaBlending();  
}  
  

The shader outputs without masking, i think that my problems comes because one of the textures that i set to the shader fboParticulas to mask is dynamic filled, so it doesnt seems to update.

Can someone give me some ligth ???

regards
natxo pedreira gonzalez

Hello my fellow Pandereto!

I download ofxAlphaMask addon and I found a little tricky the way it makes the masking. So I implement an easier way of GLSL shader masking and I add it to ofxFX addon.
You could check it out here https://github.com/patriciogonzalezvivo/ofxFX/tree/master/example-mask
I hope you found it usefull

thanks Patricio !!! its more clean now :slight_smile:

Your library wroks great, im also using the blur shader

Hi, good work @patricio i have also a new addon to ofxFX … another cellular automata , a Wireworld style … if i understand how to push in the ofxFX repo i will upload the files!

Great! you are soo welcome!

I think you first have to clone a version of ofxFx on your github web page… then clone pull it to your computer ( it´s important to choose the read & writte one)… once the changes are made on your gitHub version you could pull them to mine.

Maybe there is an easiest way of doing this… but I don´t know it. : )

I think you first have to clone a version of ofxFx on your github web page

Do you mean to fork a repo?
yes i did it.

then clone pull it to your computer ( it´s important to choose the read & writte one)… once the changes are made on your gitHub version you could pull them to mine.

yes also this… the next step is to push the changes in the repo… i will try tomorrow!