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

Math for Color class #1971

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Math for Color class #1971

wants to merge 4 commits into from

Conversation

Be1zebub
Copy link
Contributor

@Be1zebub Be1zebub commented May 28, 2023

new metaevents support __unm, __add, __sub, __mul, __div, __lt, __le
new methods: :Invert(), :Copy(), :Normalize(), :GetNormalized()

@Kefta
Copy link
Contributor

Kefta commented May 29, 2023

Could you give some examples/documentation that makes these operations defined and sensible for rgb colours?

@Be1zebub
Copy link
Contributor Author

Be1zebub commented May 30, 2023

Could you give some examples/documentation that makes these operations defined and sensible for rgb colours?

arithmetic operators allows to write cleaner code, this is useful in complex code - eg for pseudo shaders (we dont have shaders api, so cope with rt & render.ReadPixel)
I actively use pseudo shaders in my projects, for example one of it implements bloom for some vgui elements
here are some examples how color math can be used:
https://gist.github.com/Be1zebub/66a16af468e2f2d7e2a9fc0dc9ee9311
image

Copy link
Contributor

@CornerPin CornerPin left a comment

Choose a reason for hiding this comment

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

Can you add functions like Add, Sub, etc. that modify the original color rather than create a new one? Vectors, angles and matrices already have these, so it would make sense for colors to have them too.


end

function COLOR:Normalize()
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use case of Normalize? Currently it just divides the color components by 255, i.e., if you ignore copying, it is equivalent to color / 255. Wouldn't clamping the components to the range of 0…255 make more sense for a function like this?

garrysmod/lua/includes/util/color.lua Show resolved Hide resolved
@robotboy655 robotboy655 added the Enhancement The pull request enhances current functionality. label May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement The pull request enhances current functionality.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants