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

Add PropagateOpacity for controlling the alpha of entire UI node trees #15206

Closed
wants to merge 4 commits into from

Conversation

UkoeHB
Copy link
Contributor

@UkoeHB UkoeHB commented Sep 15, 2024

Objective

  • Allow fading entire groups of UI nodes at once.

Solution

  • Add PropagateControl, OpacityModifier, and BlockOpacityPropagation components. PropagateControl will accumulate modifiers down the UI hierarchy, and then those modifiers will be pre-multiplied to UI components when extracting to render them. You can also insert OpacityModifier directly as long as either there's no ancestor with PropagateControl, or you include BlockOpacityPropagation on the entity. Also note that OpacityModifier has to be mutated every tick in order to be applied, which allows us to not care about hierarchy changes that might invalidate the modifier (and in another sense it enables manually setting the modifier since we never automatically remove it).

Testing

  • Expanded transparency_ui example to include PropagateOpacity.

Showcase

TODO: this is showcase-worthy.

@UkoeHB
Copy link
Contributor Author

UkoeHB commented Sep 15, 2024

Right now the modifiers are pre-multiplied when extracting, but we could also move the modifier into ExtractedUiNode to make it less brittle. Open to opinions here, it might cost a little bit more to use ExtractedUiNode.

@benfrankel
Copy link
Contributor

benfrankel commented Sep 15, 2024

Not having looked at the code, I have a couple questions:

  1. Is there a reason this is limited to UI? (e.g. what about a hierarchy of sprites or meshes?)
  2. Is there a reason this is limited to the alpha channel rather than full color multiplication?

Raising these questions because I've wanted this before: #11157 (comment). UI-only and alpha-only is enough for UI fade in / out animations, though, which is already useful.

@UkoeHB
Copy link
Contributor Author

UkoeHB commented Sep 15, 2024

Is there a reason this is limited to UI? (e.g. what about a hierarchy of sprites or meshes?)
Is there a reason this is limited to the alpha channel rather than full color multiplication?

Hmm yeah I don't see a technical limitation here. This PR is currently scoped to just-UI and just-alpha because that's as far as I've gotten while developing this idea. I'd like to focus on staying scope-constrained, and follow-up PRs can expand the functionality.

@UkoeHB
Copy link
Contributor Author

UkoeHB commented Sep 15, 2024

@viridia pointed out on discord that this PR is not a proper solution, because, for example, backgrounds of a window will bleed through text on that window when you fade using alphas as in this PR.

See #6956 and #11716

@UkoeHB UkoeHB closed this Sep 15, 2024
@UkoeHB UkoeHB deleted the opacity branch September 22, 2024 19:05
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

Successfully merging this pull request may close these issues.

2 participants