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

Pre Multiplied Alpha Support #97

Open
PikaChokeMe opened this issue Jul 10, 2023 · 1 comment
Open

Pre Multiplied Alpha Support #97

PikaChokeMe opened this issue Jul 10, 2023 · 1 comment
Assignees
Labels

Comments

@PikaChokeMe
Copy link

PikaChokeMe commented Jul 10, 2023

I'm having trouble trying to implement and get premultiplied alpha support up and working with this plugin, and I'm wondering if anyone can give me a little guidance

I have a camera in unity with a clear flag set to solid colour, and a solid colour set to 0,0,0,0
I am outputting this to a render texture and then trying to use klakspout to send that render texture to OBS where I would like the scene to render over a background I have setup there using premultiplied alpha transparency.

I have the reciever on OBS'es end set up to use premultiplied Alpha composite mode, and I've taken a look at the internal Klakspout blit.shader and am attempting to do the same here, but I seem to be stuck.

First thing's first I try setting

Blend One OneMinusSrcAlpha

just before Cull Off Zwrite... and I almost immediately notice this old school windows graphics stuck on screen effect, behind the latest pass of what I'm rendering.
image

I'm assuming something here is no longer "blanking" properly between frames so they're basically piling up and that is why this is happening.

I've noticed that the shader itself has 5 internal passes, and I think from what I can tell the first two? passes are for Sending, while it seems like the later passes are for receiving? There is what appears to be a draw pass which runs BlitSimple, and then a blanking pass of sorts which runs BlitClearAlpha.
I've tried setting BlitClearAlpha to return float4(0, 0, 0, 1); as I've heard in a couple places that for pre-multiplied alpha to work it is necessary to clear the render target with a black texture, but I get the feeling just doing this isn't quite what I want and I'm still getting that same, stuck GPU, uncleared rendered texture effect.

In messing with this I've also tried modifying the BlitSimple function to return

return float4(tex2D(_MainTex, texCoord).rgb, 1);

Where the 1 in the alpha channel seems to clear all alpha entirely (no longer stacking rendering passes but instead drawing all black where alphas should be), which I guess makes sense if I think about it, and I've also tried modifing it to just return

tex2D(_MainTex, texCoord);

Just leaving the alpha channel that is there in place as is, but that still results in the previously mentioned effect where frames are rendering on top of each other with no clearing in between them at all.

Is there something different I have to do to somehow clear previously rendered frames so that I can just get the currently rendered frame with pre-multiplied alpha transparency? Or I guess maybe an even better question to ask is, is any of this even on the right track to getting premultiplied alpha to work? If I am far off the mark, how would I go about actually implementing this?

@keijiro keijiro self-assigned this Jul 10, 2023
@tastez
Copy link

tastez commented Aug 30, 2023

does the Test scene with alpha work for you? I had no issues with alpha with Spout and Spout2Capture obs plugin so far. maybe i misunderstand.
are you using HDRP/URP and Camera capture mode @PikaChokeMe ?

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

No branches or pull requests

3 participants