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

Allow custom clear color for the window background #6205

Open
Erinaaaaaaa opened this issue Mar 6, 2024 · 5 comments
Open

Allow custom clear color for the window background #6205

Erinaaaaaaa opened this issue Mar 6, 2024 · 5 comments

Comments

@Erinaaaaaaa
Copy link
Contributor

Erinaaaaaaa commented Mar 6, 2024

A feature like this would allow making transparent applications for OBS.

In this specific scenario, a transparent clear color would likely allow for better management of transparency than chroma keying for example.

I tried an implementation a few days ago with just being able to change the clear color to transparent, but then I ran into issues with alpha blending (see the dark blobs below around the green and red lights) - let me know if you'd like me to upload a branch with my changes.
image

@bdach
Copy link
Collaborator

bdach commented Mar 6, 2024

Use a Box that fills all available space for chroma-keying? Or if you really don't want to, write a custom DrawNode for the root-level container that calls Renderer.Clear?

I don't see any reason to make any changes to framework to support this.

I'm not even sure how "clearing with transparent colour" works or does anything useful at all. It's not like the WM will know that the game has cleared its surface to transparent?

@Erinaaaaaaa
Copy link
Contributor Author

Erinaaaaaaa commented Mar 6, 2024

A transparent clear color allows using the "Allow Transparency" option in OBS' Game Capture to capture a transparent image directly for compositing a stream. An example of an app that already does this is Vtuber avatar tool VSeeFace.

In this case, I'm making a telemetry HUD overlay for F1 games (hence the screenshot above) as playing them in VR removes any and all HUD - in fact, the screenshot comes from OBS:
image

The main reason why I'm looking specifically for a transparent clear is to make sure I'm not limited in the colors I can use - the wheel lights (the row of 15 rectangles) has all three primary colors (green, red, and blue in that order), and I'm not entirely sure a chroma key would work all that well, though I haven't tried either.

That being said, I didn't consider the option of a custom DrawNode, so technically I suppose it's already possible to clear to a custom color? I'd generally like an easier way to change just the color, but a framework change might indeed not be needed for that. I'll need to play around with this, but then alpha blending might remain an issue, which would probably need a separate issue/discussion.

@peppy
Copy link
Sponsor Member

peppy commented Mar 7, 2024

We won't have any official use for this, so I'd recommend implementing yourself. If it's simple enough, we can consider merging the feature.

Keep in mind that implementing will have serious cross-platform concerns (ie. it likely won't be usable on mobile) and that may increase implementation complexity.

@smoogipoo
Copy link
Contributor

smoogipoo commented Mar 7, 2024

The first thing I'd check is to see if this works in theory by changing this line:

Clear(new ClearInfo(Color4.Black));

Then, I think the best way is for a custom DrawNode as previously proposed:

protected override DrawNode CreateDrawNode() => new GameDrawNode(this);

private class GameDrawNode : CompositeDrawableDrawNode
{
    public GameDrawNode(CompositeDrawable source)
        : base(source)
    {
    }

    protected override void Draw(IRenderer renderer)
    {
        renderer.Clear(new ClearInfo(Color4.Pink));
        base.Draw(renderer);
    }
}

@EVAST9919
Copy link
Contributor

but then I ran into issues with alpha blending (see the dark blobs below around the green and red lights)

Simplest solution for this would be using additive blending for glow. If you are using EdgeEffect - there's an EffectBlending parameter.
(Though I'm not sure how it will react to transparent background and your particular use case, so testing from your end is required)

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

No branches or pull requests

5 participants