Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RGBA Image as background #54

Open
kevinpl07 opened this issue Feb 8, 2023 · 5 comments
Open

RGBA Image as background #54

kevinpl07 opened this issue Feb 8, 2023 · 5 comments

Comments

@kevinpl07
Copy link

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?

@Volcomix
Copy link
Owner

Volcomix commented Feb 9, 2023

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/

@kevinpl07
Copy link
Author

kevinpl07 commented Mar 1, 2023

@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.

@rishabh-adda
Copy link

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

@kevinpl07
Copy link
Author

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

yes, see the code change given above

@rishabh-adda
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants