How can I use webcam as mask?

Hello there,
I am a beginner now struggling in how to make my code below work. I am now putting a green screen raindrop video on top of the webcam streaming and trying to add an interaction which allows the raindrops layer to be erased. I am trying the interaction part based on a Fbo Alpha Mask example from shader folder, but it is not working.
Thank you
Here is the screenshots of my code to better understanding:

Hi @hlliu,
Hey welcome to the forum! You can post code directly if you hit the </> button in the post window.

So have a look at the /examples/gl/multiTextureShaderExample if this is not the one you referenced above. Its an example for ofFbo, and also has a shader in it.

An ofFbo has an ofTexture in it (so does an ofImage). An ofTexture has a method .setAlphaMask() that takes another ofTexture as an argument. There is a pretty good forum post about it here: alphaMask shader example and texture/image size/dims problem. There is also a very short description of it here:

So, to set a mask (say from an ofImage) for something like a webcam (which has an ofTexture), you would do something like:

ofVideoGrabber webcam;
ofImage image;

Depending on what you are trying to do, .setAlphaMask() might work really well. And its been a while but I don’t think you need a shader to use it. And I think you can just call it once in ofApp::setup(), and not during each update() and draw() cycle. ofTexture::disableAlphaMask() will disable the alpha mask if you need to.

And remember, if your mask is an ofImage, you have to .update() the image after any changes to it. Hope this helps!