The comparison with 0 may work, but the mask edges may be rough, because it’s a threshold: either transparent or opaque.
@arturo In my tests black did not become transparent. As in @Gallo 's “what I have” image above, the white part of the mask shows the textures, but the black does not become transparent, but replaces the image texture with black.
oh yeah sorry you are right the mask works for color form rgb and for alpha from alpha. you can remap the channels using:
mask.setSwizzle(GL_TEXTURE_SWIZZLE_A, GL_RED);
which will map the red channel to act as alpha so you will see white as alpha 1 and black as alpha 0. you’ll need a texture allocated with alpha in the first place for this to work
setSwizzle() takes 5 microseconds on my system, while the two for loops take around 20500 microseconds. Just in case you need to be fast.
If your mask is not pure black and white, but has gray values, it might look like this:
Which you can solve like this using your approach:
for(int y = 0; y < mask.getHeight(); y++) {
for(int x = 0; x < mask.getWidth(); x++) {
mask.getPixels().setColor(x, y, ofColor(255, 255, 255, mask.getPixels().getColor(x, y).getBrightness()));
}
}
Or at least I would not compare to 0 (jpg may have introduced artifacts, as you can see on the right side of the pentagon). Using .getBrightness() < 128 would be better, I think.
I expected: white regions of the mask are showing the video, grey regions are partially transparent, black regions are fully transparent.
But it leads to: white regions of the mask are showing the video, some grey regions are in fact partially transparent, but black regions of the mask are non-transparent black.
Same outcome on Ubuntu 16.04 and OS X 10.9.5, both OF 0.9.8
I have in fact the same result when trying the same with a custom shader like:
The shader example from roymacdonald also has GL set to 3.2, (though there is a test in the example and uses different shaders depending upon GL Version)
Hi, I’m bumping this thread because I’m trying these methods on a Raspi and none of them work.
When I use the swizzle thing, it can’t find the constants, so I assume it is not on GLES. But the alpha methods don’t work either. Is there any limitation we should be aware of?