Skip to content

Change default clear color to black #9540

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rdrpenguin04
Copy link
Contributor

Objective

Black is an easier color to fill for GPUs (if by a small margin), and the choice of clear color really isn't necessary for most games, where 3D games will choose skyboxes and 2D games will choose background images (and most 2D games ideally wouldn't use rgb(0.4, 0.4, 0.4) as their background color of choice anyways). Thus, choosing black would enable a small optimization.

Solution

Adjusted ClearColor::default


Changelog

Changed: the default clear color is now black.

Migration Guide

Any applications relying on the default clear color being the original shade of dark grey should change them. Meanwhile, anyone who set the clear color to black, either as an optimization or for a space-related game, can now change their color back to the default.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Controversial There is active debate or serious implications around merging this PR labels Aug 22, 2023
@alice-i-cecile
Copy link
Member

I don't think I agree with this decision. The performance argument isn't convincing at all to me without data, and this will make quick experiments and examples less useful since you won't be able to see black lines that are drawn.

@alice-i-cecile alice-i-cecile added the M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide label Aug 22, 2023
@rdrpenguin04
Copy link
Contributor Author

rdrpenguin04 commented Aug 22, 2023

Not being able to see black lines isn't a convincing argument to me, since white-on-black is easier to see than black-on-dark-grey or white-on-dark-grey.

On the performance side, check https://gpuopen.com/learn/rdna-performance-guide/#clears; while I don't have performance metrics, I was directed here.

@JMS55
Copy link
Contributor

JMS55 commented Aug 22, 2023

While I agree with this in principal, I think we should delay it until we add procedural skyboxes. Probably sometime in 0.13 assuming I don't run into major issues.

@rdrpenguin04
Copy link
Contributor Author

The thing is, if someone wanted a non-black background, chances are they set it manually anyway. The default color is almost certainly not used in production ever except by accident. I don't think procedural skyboxes are needed for a simple change that affects almost nobody; if someone wants to use a non-black clear color, there's nothing stopping them from doing so. All this does is change the default.

@superdump
Copy link
Contributor

I also agree with this in principal and I think @JMS55 point about skyboxes is a good one.

I tend to think that hidden costs are much more difficult to be aware of / discover than things that just don't work.

When lots of things will use some kind of skybox or background of some form which will replace all the clear colour, it would be difficult to be aware of the lost performance from slow-path clearing of textures and from what I recall from @HackerFoo 's work on the Noumenal mobile app, things like clearing buffers has significant impact on mobile in particular. AMD/NVIDIA also recommend using fast paths for clearing/initialising textures if possible.

On the other hand, not being able to see black lines on a black background is immediate and clear friction that is actionable.

@rdrpenguin04
Copy link
Contributor Author

rdrpenguin04 commented Aug 23, 2023

I'm still somewhat failing to see the problem with black lines on a black background; if the background is obviously black, why isn't it trivial to make the lines white?

Edit: Oh right, that's your point: it is trivial to fix, but clear color is less obvious -- oh, that makes more sense, and I completely agree.

@alice-i-cecile
Copy link
Member

Yep :) Note that this will have an impact on more complex rendering examples too: things like the examples that demonstrate the effects of lighting and PBR materials will look quite different on a black rather than neutral-gray background!

I'm fine to defer to the tastes of the rendering experts here, but we should verify that all of the visual examples still look fine as part of this PR and manually set the clear color (or change the line etc. color) as needed.

@rdrpenguin04
Copy link
Contributor Author

Are there automated tests to check against an existing screenshot?

@dmyyy
Copy link
Contributor

dmyyy commented Aug 23, 2023

I think @mockersf was working on something like that here: #9220

@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through and removed X-Controversial There is active debate or serious implications around merging this PR labels Aug 16, 2024
@janhohenheim
Copy link
Member

Triage: has merge conflicts
@rdrpenguin04 do you want to update this PR or should I tag it S-Needs-Adoption? :)

@janhohenheim janhohenheim added the S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged label May 17, 2025
@rdrpenguin04
Copy link
Contributor Author

rdrpenguin04 commented May 17, 2025

I can update the PR, sure; I just got on summer break anyway

Edit: We're up to date now.

Copy link
Contributor

Your PR caused a change in the graphical output of an example or rendering test. This might be intentional, but it could also mean that something broke!
You can review it at https://pixel-eagle.com/project/B04F67C0-C054-4A6F-92EC-F599FEC2FD1D?filter=PR-9540

If it's expected, please add the M-Deliberate-Rendering-Change label.

If this change seems unrelated to your PR, you can consider updating your PR to target the latest main branch, either by rebasing or merging main into it.

@janhohenheim janhohenheim added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels May 18, 2025
@rdrpenguin04
Copy link
Contributor Author

(yes, this does need M-Deliberate-Rendering-Change)

@superdump superdump added the M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered label May 18, 2025
@alice-i-cecile
Copy link
Member

@mate-h @ecoskey, how do y'all feel about this as a default now that we have a skybox impl?

@rparrett, how do you feel about the impact of this on our examples? Should we add boilerplate to every example, reject this PR, or do something hacky to get the best of both worlds?

I think I'm personally in the "reject this PR, write a book chapter and template for perf optimzation" but I do agree that this is kind of a silly situation.

@alice-i-cecile alice-i-cecile added S-Needs-Design This issue requires design work to think about how it would best be accomplished and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Contentious There are nontrivial implications that should be thought through labels May 19, 2025
@alice-i-cecile alice-i-cecile added the X-Controversial There is active debate or serious implications around merging this PR label May 19, 2025
@rparrett
Copy link
Contributor

rparrett commented May 19, 2025

@rparrett, how do you feel about the impact of this on our examples? Should we add boilerplate to every example, reject this PR, or do something hacky to get the best of both worlds?

IMO, given the assumption that this is an large and important optimization, I'd probably just take the minor aesthetic hit. Not the end of the world, but many examples would need adjustments as we did in #10339. Cart's opinion would be more valuable here, because I can't quantify either the branding value or performance impact.

If this is a minor optimization in the grand scheme of things, or if there's no motivation to make a determination to that end, then I like the plan to close and educate. Maybe we can warn or override if there's a skybox or something?

And in any case, we should probably give some info on fast clears the clear color related docs:
https://docs.rs/bevy/latest/bevy/prelude/struct.ClearColor.html
https://docs.rs/bevy/latest/bevy/prelude/enum.ClearColorConfig.html

@rdrpenguin04
Copy link
Contributor Author

One option could be to create a "default clear color" resource that the examples (with the exception of ones involving a changed background) all insert to be the bevy-default-grey, so the examples still use the same grey and fit the Bevy branding.

The motivation for making this change at all is that AMD's own documentation seems to imply that a non-fast clear is a major performance drop. I'm a bit surprised that it's supposedly this big of an impact myself.

@rparrett
Copy link
Contributor

rparrett commented May 19, 2025

I think Alice's mention of the word "boilerplate" scared me off, but you are right, app.insert_resource(ClearColor::BEVY_GRAY) (or whatever) really isn't a huge burden.

@rdrpenguin04
Copy link
Contributor Author

Another option could be a feature flag that sets the clear color to bevy-gray, and the examples use that.

Or what you said about detecting a skybox and automatically disabling the clear color. There are a lot of options; I truly did not expect a two-line change to be this controversial :)

@ecoskey
Copy link
Contributor

ecoskey commented May 19, 2025

@mate-h @ecoskey, how do y'all feel about this as a default now that we have a skybox impl?

I'm fine with the change personally, especially since setting a per-app default with the ClearColor resource is so easy, but I don't feel too strongly. I'm a little surprised the gray clear color hasn't caused problems for atmospherics actually, considering it composites on top of the existing background 🤔. I guess it'd also be technically "more pbr" to have a black background unless there's an env map enabled, but we probably shouldn't strongly link those.

@alice-i-cecile
Copy link
Member

alice-i-cecile commented May 20, 2025

app.insert_resource(ClearColor::BEVY_GRAY)

This seems like a fine solution to me, but I'm sure @cart will have feelings. I feel like we should do that as part of this PR, to avoid creating a ton of noise for the screenshots and collect the changes into a single atomic item.

Pretty soon, I think we should be moving many of our examples away from a clear color background, and towards a slightly more realistic procedural skybox or something anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use M-Deliberate-Rendering-Change An intentional change to how tests and examples are rendered M-Needs-Migration-Guide A breaking change to Bevy's public API that needs to be noted in a migration guide S-Needs-Design This issue requires design work to think about how it would best be accomplished X-Controversial There is active debate or serious implications around merging this PR
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

8 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy