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

[Merged by Bors] - Sprites - keep color as 4 f32 #4361

Closed
wants to merge 1 commit into from

Conversation

mockersf
Copy link
Member

Objective

Solution

  • Do not reduce the color of sprites to 4 u8

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Mar 29, 2022
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen and removed S-Needs-Triage This issue needs to be labelled labels Mar 29, 2022
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a better solution than rounding. Color consistency and accuracy is better than the very small performance win.

Copy link
Member

@cart cart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think this is the move. I'll hold off on merging just to give some space for dissenting opinions.

@cart cart added this to the Bevy 0.7 milestone Mar 29, 2022
@alice-i-cecile
Copy link
Member

Ping @bevyengine/rendering-team for quick opinions on this :)

@bytemuck
Copy link
Contributor

This is the way to go IMO.

@rparrett
Copy link
Contributor

rparrett commented Mar 30, 2022

Should mesh2d_manual get the same treatment?

If so, are as_rgba_u32 and as_linear_rgba_u32 still useful to keep around?

@HackerFoo
Copy link
Contributor

This would probably be a good place to use FP16 in the future: gpuweb/gpuweb#658

@mockersf
Copy link
Member Author

Should mesh2d_manual get the same treatment?

This examples needs to use a u32 as the attribute for mesh color is marked as Uint32:

/// Per vertex coloring. Use in conjunction with [`Mesh::insert_attribute`]
pub const ATTRIBUTE_COLOR: MeshVertexAttribute =
MeshVertexAttribute::new("Vertex_Color", 4, VertexFormat::Uint32);

It could change there too, but I don't know if there was another reason there for it to be u32

@CptPotato
Copy link
Contributor

CptPotato commented Mar 30, 2022

I prefer this fix over #4357 👍

An alternative would be passing the color using 4 x u8 (as before) but encoded using SRGB color and then doing the transform back to linear in the shader. But I think f32/f16 is the better option as this also works with higher bit depths and unclipped colors, which allows brightening sprites, HDR, etc..

Regarding the vertex color, it makes sense to me to keep them compressed as u32 in my opinion, since switching to 4 x f32 would increase the memory required per vertex quite a bit.
I haven't tested the vertex colors, but I think they probably have the same precision issue. Maybe doing the SRGB encoding I mentioned above makes sense for the vertex color in the future?

@inodentry
Copy link
Contributor

I was originally one of the proponents of this idea to "compress" the color into a u32. In retrospect I think I am now convinced that it was over-optimizing, trading off correctness and support for some valid use cases, for a drop of performance. I agree with this PR that we should not do that anymore. :)

The current sprites renderer was designed with WebGL2 limitations in mind. If we really want performance gains for sprites rendering, we should look into having a fast path (using storage buffers and vertex pulling, or other such render techniqes) for platforms that aren't so limited, and leave the current implementation as a fallback for platforms that don't support it. That would be much more beneficial, than trying to "micro-optimize" the individual struct fields.

@cart
Copy link
Member

cart commented Mar 30, 2022

Sounds like we have consensus!

@cart
Copy link
Member

cart commented Mar 30, 2022

bors r+

bors bot pushed a commit that referenced this pull request Mar 30, 2022
# Objective

- Fix #4356

## Solution

- Do not reduce the color of sprites to 4 u8
@bors bors bot changed the title Sprites - keep color as 4 f32 [Merged by Bors] - Sprites - keep color as 4 f32 Mar 30, 2022
@bors bors bot closed this Mar 30, 2022
bors bot pushed a commit that referenced this pull request Apr 25, 2022
# Objective

- Fixes inaccurate UI colors similar to this [Sprite color fix](#4361).

## Solution

- Do not reduce the color of UI quads to 4 u8.

 Left is the displayed color. Right is the input color(#202225).
| Before Fix | After Fix |
|--------|--------|
|![before](https://user-images.githubusercontent.com/2303421/163661335-7f970a43-1f8b-45af-ae0a-cd74424aa9fb.png)|![after](https://user-images.githubusercontent.com/2303421/163661342-d8d56c08-924b-4bce-8bc8-a8de85aadc97.png)|
exjam pushed a commit to exjam/bevy that referenced this pull request May 22, 2022
# Objective

- Fixes inaccurate UI colors similar to this [Sprite color fix](bevyengine#4361).

## Solution

- Do not reduce the color of UI quads to 4 u8.

 Left is the displayed color. Right is the input color(#202225).
| Before Fix | After Fix |
|--------|--------|
|![before](https://user-images.githubusercontent.com/2303421/163661335-7f970a43-1f8b-45af-ae0a-cd74424aa9fb.png)|![after](https://user-images.githubusercontent.com/2303421/163661342-d8d56c08-924b-4bce-8bc8-a8de85aadc97.png)|
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# Objective

- Fix bevyengine#4356

## Solution

- Do not reduce the color of sprites to 4 u8
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Fix bevyengine#4356

## Solution

- Do not reduce the color of sprites to 4 u8
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Fixes inaccurate UI colors similar to this [Sprite color fix](bevyengine#4361).

## Solution

- Do not reduce the color of UI quads to 4 u8.

 Left is the displayed color. Right is the input color(#202225).
| Before Fix | After Fix |
|--------|--------|
|![before](https://user-images.githubusercontent.com/2303421/163661335-7f970a43-1f8b-45af-ae0a-cd74424aa9fb.png)|![after](https://user-images.githubusercontent.com/2303421/163661342-d8d56c08-924b-4bce-8bc8-a8de85aadc97.png)|
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-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ClearColor and Sprite same value yields different color
8 participants