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

[Custom Levels] Improve color palette generation #3797

Merged
merged 3 commits into from
Dec 8, 2024
Merged

Conversation

water111
Copy link
Collaborator

@water111 water111 commented Dec 8, 2024

A few improvements to color palette selection. These were made by tracing some particularly bad colors through and seeing where it made obviously bad decisions for splitting. I tested on crystal cave, and a test GLBs from Kuitar that previously had issues with alpha.

  • The previous approach to splitting was based on trying to keep a tree of deduplicated colors balanced (same count in each leaf). This is not really a good idea for generating color palettes. A better approach is to try to minimize the volume of the child node, limiting how inaccurate a color can be. Splitting is now chosen based on the average of the deduplicated channel values, which in practice seems to work pretty well for Kuitar's levels. Other approaches could work here too.
  • The previous approach of alternating through dimensions to split on was kept.
  • The depth of the KD tree during the initial split was increased, allowing it to use up to 8192 colors, instead of just 1024.
  • In most cases, not all child nodes of the tree have colors in them, meaning that a tree of depth 13 would have less than 8192 colors. If this happens, child nodes are split until the color count reaches 8192. The selection of which nodes to split is somewhat arbitrary, but is breadth-first. The axis for splitting is the one with the largest range. (which might be a better idea in general?)

On crystal-cave, the worst case color error was reduced from 221 to 9.

@water111 water111 merged commit 5458d86 into master Dec 8, 2024
11 of 12 checks passed
@water111 water111 deleted the w/color-splits branch December 8, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant