#OKColor - an okay color management implementing OKLab/OKLCH

1 messages · Page 1 of 1 (latest)

astral raft
#

GitHub: https://github.com/KeeVeeGames/OKColor.gml

OKColor is a color management library for GameMaker written in pure GML that implements the new "industry standard" OKLab/OKLCH perceptual models, among others.

Generate, convert, gamut map and mix colors properly with visually better results. Also supports RGB, HSV, HSL, Lab, LCH, and other models.

#

The problem with the standard RGB and HSV models is that they're not taking into consideration the human perception of the color. That means that if you follow the same rules to set the color components, the resulting colors might not look like these rules were followed.

For example, if two colors only differ in hue, they won't be consistent for our eyes and seems like they also have different saturation/value, despite having the same ones in the code. The hue itself is not perfect either: it distributes colors unevenly, so adding the same amount of hue to different colors won't make them "move" the same distance in the color wheel.

Perceptual color models such as the ones implemented in this library aim to fix this issues.

#

Here is some real-life examples of problems with generating colors in-code:

#

Let's say you want to recolor specific features of your character sprite in-game. With OKLCH the lightness is consistent throughout all the hue changes, shadows and highlights remain intact, and the overall visual is enhanced. This extends to other components: you can be sure that colors with the same hue will have the same perceptual hue, unlike HSV which tends to shift it when brightness is changed.

#

_ _
Otherwise, if instead you need the difference in color qualities such as for better accessibility, a perceptual color model is also beneficial.

For example, you want to color-code different collectables: blue one is standard, green is lighter and red is darker to make it easier for subconscious distinction and more accessible for color-blind people.

HSV results are not predictable: with the red appearing much darker than intended, and green and blue seemingly having similar brightness. OKLCH, on the other hand, provides more consistent and reasonable results, with each subsequent color being equally darker than the previous one, complementing the 10% change.

#

Color mixing is also a case. GameMaker's merge_color uses RGB model to mix colors and may suffer from the same disadvantages of unpredictable color qualities, non-linear distribution and component shifts. OKColor offers additional methods for mixing colors perceptually using CIELab and OKLab models.

Here are some examples of different gradients:

#

The library also provides functionality for gamut mapping.

When dealing with different color models you can retrieve a color that lies outside of the renderable range called "gamut". Gamut mapping is the process of taking a color that is out of gamut and adjusting it such that it fits within it.

This includes the basic naïve method of clipping RGB channels and advanced chroma reduction algorithms. I also implemented my own "Geometric" algorithm that estimates the similar results as CIELab chroma reduction but works much faster.

balmy fable
#

Very nice work! I’m planning to write a tutorial on this topic sometime

astral raft
balmy fable
#

I’ll be sure to reference your GitHub

plain fable
#

Very cool! 👀
No obvious use case for me at the moment, but I added it to bookmarks.

jovial urchin
#

Thanks for sharing !

astral raft
plain fable
#

So it goes haha

mighty lion
#

Is there any way to use "relative" chroma? Like in CSS, e.g.: oklch(50% 50% 120) @astral raft

astral raft