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

Color maths 4 #12575

Merged
merged 4 commits into from
Mar 19, 2024
Merged

Color maths 4 #12575

merged 4 commits into from
Mar 19, 2024

Conversation

lynn-lumen
Copy link
Contributor

@lynn-lumen lynn-lumen commented Mar 19, 2024

Objective

Solution

  • This PR implements componentwise (including alpha) addition, subtraction and scalar multiplication/division for some color types.
  • The mentioned color types are Laba, Oklaba, LinearRgba and Xyza as all of them are either physically or perceptually linear as mentioned by @alice-i-cecile in the issue.

Changelog

  • Scalar mul/div for LinearRgba may modify alpha now.

Migration Guide

  • Users of scalar mul/div for LinearRgba need to be aware of the change and maybe use the .clamp() methods or manually set the alpha channel.

@NthTensor NthTensor added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Animation Make things move and change over time A-Math Fundamental domain-agnostic mathematical operations labels Mar 19, 2024
@NthTensor
Copy link
Contributor

Looking great!

I'll just repeat what I said on discord here as well: Eventually I want to have better support for non-linear alpha blending modes (perhaps with some sort of Blend<LinearRgba, BlendMode> or perhaps not). I also want to make converting vectors into colors a bit easier. Ditto with math on cylindrical color spaces. None of that needs to block this PR.

Mostly what I see remaining is bike-shedding about the specific implementation of the color algebra. The operations don't need to be perfect but they do need to be well defined.

@NthTensor
Copy link
Contributor

Rereading #12163 (comment) it looks like we might want to exclude alpha from scalar multiplication/division.

@IQuick143
Copy link
Contributor

Rereading #12163 (comment) it looks like we might want to exclude alpha from scalar multiplication/division.

That would break splines, as it breaks distributivity over addition.

@NthTensor
Copy link
Contributor

After looking at some other color crates, I am less concerned about the alpha component. We've got enough approvals for merge, and this isn't marked controversial so I am adding the tag.

@NthTensor NthTensor added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Mar 19, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Mar 19, 2024
Merged via the queue into bevyengine:main with commit d7372f2 Mar 19, 2024
27 checks passed
@BD103 BD103 added the A-Color Color spaces and color math label May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time A-Color Color spaces and color math A-Math Fundamental domain-agnostic mathematical operations A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add color animation support
6 participants