Skip to content

[css-color-4] adjust raytracing algorithm to account for some edge cases - #14698

Merged
svgeesus merged 3 commits into
w3c:mainfrom
romainmenke:css-color-4--sensible-bloodhound-035b6427bd
Nov 1, 2026
Merged

svgeesus merged 3 commits into
w3c:mainfrom
romainmenke:css-color-4--sensible-bloodhound-035b6427bd

Conversation

@romainmenke

Copy link
Copy Markdown
Member

Without this adjustment:

A matrix of colors in oklch with c = 0.2, l = 100% at the top l = 0% at the bottom and starting from the left at h = 0deg. It shows a pure red cell in a region that should be near black

After:

The same matrix, but this time there is no cell with an unexpected value


@facelessuser would be great if you could check this, thanks 🙇

@facelessuser

Copy link
Copy Markdown
Contributor

@romainmenke I had a potential fix for this same issue, but I think your solution is more robust, so I'm going to say yours looks better for the spec.

On a side note, we need to add that the initial anchor should be clamped to [0, 1]. Conversion floating-point noise can leave an anchor slightly outside the cube and can cause a similar issue where the color is not found on the gamut surface and gets clipped, giving an incorrect, saturated color, even if you've done the lightness check earlier. This mainly can occur near black and white. This is a real issue that can occur, and the spec does not have this protection. If this case is handled separately, that is fine, but it really should be included in the spec as well.

@romainmenke

Copy link
Copy Markdown
Member Author

I've added the anchor clamp to the spec

@romainmenke
romainmenke requested a review from svgeesus October 31, 2026 18:20
@facelessuser

Copy link
Copy Markdown
Contributor

@romainmenke Two other small recommendations:

  1. Change:

    let inv_d be 1 / d
    let t1 be (bmin [i] - a ) * inv_d
    let t2 be (bmax [i] - a ) * inv_d
    

    To:

    let t1 be (bmin [i] - a ) / d
    let t2 be (bmax [i] - a ) / d
    

    There's an argument made for this change here: https://claude.ai/artifact/7bUg4fYdrPGLH68ukVF8XK

  2. The other one I mentioned to you in private: Raise the 32-bit anchor margin to 1e-5. This is 32 bit specific.

    Also covered here: https://claude.ai/artifact/7bUg4fYdrPGLH68ukVF8XK

That would address any current known issues.

@romainmenke

Copy link
Copy Markdown
Member Author

Also applied those, thanks!

@facelessuser

Copy link
Copy Markdown
Contributor

LGTM

@svgeesus svgeesus left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@svgeesus
svgeesus merged commit 1cf9918 into w3c:main Nov 1, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants