Fix broken Oklab color space matrices and conversions. #129
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello.
This PR resolves what seems to be a big of mix up with the Oklab color space functions, naming, and its use of the srgb <--> (linear)rgb conversion functions.
I think transformation functionality was misnamed and/or put into the wrong files in the two different conversion scenarios: oklab2(s)rgb and (s)rgb2oklab. This problem was then exacerbated by using the wrong order of linear (rgb) and non-linear (srgb) transformations, probably due to the naming and placement of functionality.
For example,
oklab2srgb
to perform a correct transform of oklab->linear, but then incorrectly usessrgb2rgb
(a double transform to linear).For testing, I used this pinkish color and the srgb and oklab derived values provided by the color picker functionality. I could not achieve results that were expected with any combination of current functions. These incorrect results can be seen by using this Oklab tester shader which I creatred to confirm this fix. With existing code, the color turned out on the lime green side of things rather than pinkish. With this fix, the expected results are a 2x2 grid of the same pinkish color.
I think there may have been one or two errors in the transform matrices involved. I have replaced them with the current ones found at the resource here, which I utilized to perform this fix:
Converting from linear sRGB to Oklab
Use a linear version of sRGB
I can only confirm the glsl functionality works as I expect, and was unable to test the updated hlsh/wgsl code.
Cheers, Brad