I’m facing a weird issue with playing videos with alpha channel.
I’ve been testing ofxVideoPlayer, ofxAVFundationPlayer and ofxHapPlayer but the same problem remains.
Everything is playing ok but there’s a little grey outtline around the shapes of my videos. I guess It’s something opengl related but I’ve been trying loads of different things and have no clue.
Here is a screenshot with the video played – you can notice this subtle grey outline around the mask.
Here is the same video played in OSX preview ( the background is grey in this case, but I have the same result if I import it in any video editor ) – ther’s no outline.
Is it the same file you’re playing in both OSX Preview and openFrameworks ? (to rule out any encoding issue)
It seems to be a weird alpha blending problem ; fully opaque / transparent is fine, but on the edge the antialiasing get messed up. You could try to play with shaders for changing the way the compositing is done, or use a variation of the function glBlendFuncSeparate to change how the alpha blending is done (the latter is probably easier) https://www.khronos.org/opengles/sdk/docs/man/xhtml/glBlendFuncSeparate.xml
Yes It’s indeed the same file.
I also read a lot of different threads regarding issues with transparency / FBOS and played around different ways to change alpha blending but still have the same problem.
I will have a look at alpha blending with shaders, It seems pretty straightforward.
If any of you have any example or have faced the same issue I would be grateful to read about that
Hey @Martial, I ran into this issue recently drawing PNGs with transparency into an FBO and then either drawing that FBO to screen or saving its pixels to a PNG file. I half-understand what’s going on here – it’s a premultiplied alpha issue. If you google “OpenGL premultiplied alpha” you’ll find a number of articles that will explain it much better than I can
Here’s a great write-up by @roxlu with some screenshots & solutions that should be helpful
Indeed the problem was drawing multiple FBOS with ofEnableAlphaBlending() – and then redrawing it again with alpha blending.
After some tries, I finally managed to have something right – and realized that It was really important to manage perfectly the way blending is called for each objects in the main thread !
I think ran into an issue similar to this but ended up figuring it out too.
I needed 1 fbo with autoClear and one without but I got confused with antialiasing, smoothing and depth stuff.
Here’s the minimal code:
// setup
fboOne.allocate(100,100,GL_RGB, 4); // 4x anti aliasing
// setting this to 0 also "pixelises" the lines drawn in fbo2
fboOne.begin();
//ofEnableSmoothing(); // makes no difference
fboOne.end();
fboTwo.allocate(100,100,GL_RGBA, 4); // 4x anti aliasing
fboTwo.begin();
//ofEnableSmoothing(); // makes no difference
ofClear(0,0,0,0);
fboTwo.end();
.
// draw
fboOne.begin();
ofClear(0,0,0,1);
fboTwo.begin();
ofSetColor(255);
ofDrawLine(0,0,100,100);
ofDrawLine(100,0,0,100);
fboTwo.end();
fboTwo.draw(); // <-- dont forget to draw it into fboOne
ofDrawLine(50,0,50,100);
ofDrawLine(0,50,0,100);
fboOne.end();
fboOne.draw(0,0);