virtual-background icon indicating copy to clipboard operation
virtual-background copied to clipboard

RGBA Image as background

Open kevinpl07 opened this issue 2 years ago • 5 comments
trafficstars

I want to experiment with rgba images as a background image. That way the rgba image would be over the camera except for the cutout person mask. I can't seem to get the fragment shader to work with rgba.

Any ideas?

kevinpl07 avatar Feb 08 '23 19:02 kevinpl07

I think in the fragment shader, changing this line to something like this should be a good starting point:

outColor = vec4(frameColor, personMask);

Then there is something to take into consideration to have it working, it's that the alpha channel might not be processed by WebRTC. So you'll probably need to hack around something similar to this: https://webrtchacks.com/how-to-make-virtual-backgrounds-transparent-in-webrtc/

Volcomix avatar Feb 09 '23 14:02 Volcomix

@Volcomix Btw I managed to make it work with a simple trick in the shader of the backgroundImageStage:

float personMask = clamp((1.0 - texture(u_background, v_backgroundCoord).a) + texture(u_personMask, v_texCoord).a, 0.0, 1.0);

This way RGBA pngs as background images will be correclty displayed on top of the backround while allowing the original background to be visible wherever the image is transparent.

kevinpl07 avatar Mar 01 '23 21:03 kevinpl07

Hi Kevin , I am also trying to achieve transparent background . Are you able to do that @kevinpl07

rishabh-adda avatar Apr 24 '23 10:04 rishabh-adda

Hi Kevin , I am also trying to achieve transparent background . Are you able to do that @kevinpl07

yes, see the code change given above

kevinpl07 avatar Apr 24 '23 10:04 kevinpl07

I have made the above code change , Anything else required. I am still facing issues generating transparent background , can you share the Screenshot Images that you were able to achieve @kevinpl07 . Thanks

rishabh-adda avatar Apr 24 '23 10:04 rishabh-adda