fix(Texture2DConverter): decode ASTC_HDR formats with the HDR profile - #380
Open
nichinichisou0609 wants to merge 1 commit into
Open
nichinichisou0609 wants to merge 1 commit into
nichinichisou0609 wants to merge 1 commit into
Conversation
The ASTC decoder context always used the LDR profile, so the HDR blocks of an ASTC_HDR_* texture decoded to error colours: magenta for HDR endpoint modes, white for HDR constant-colour blocks. The HDR formats now get a context with the HDR profile, without the unorm8 decode flag, which is only valid for the LDR profiles. Values above 1.0 are clamped in the 8-bit image, as for the other HDR formats. tests/test_astc.py encodes synthetic HDR and LDR gradients with astc-encoder and decodes them through CONV_TABLE.
nichinichisou0609
force-pushed
the
fix/astc-hdr-profile
branch
from
September 26, 2026 01:05
de02bf5 to
4a32da8
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I ran into this with ASTC_HDR_6x6 textures from a Unity 6000.3 build.
_get_astc_contextalways creates the decoder context withASTCProfile.LDR, andCONV_TABLEroutes theASTC_HDR_4x4...ASTC_HDR_12x12formats through the sameastc()call. astcenc does not decode HDR blocks in an LDR profile: a block with HDR endpoint modes comes out as its error colour, magenta(255, 0, 255, 255), and an HDR constant-colour (void-extent) block as NaN, which ends up as white(255, 255, 255, 255)in the 8-bit output. The textures I ran into contain only HDR blocks, so they decode to nothing but magenta and white; the synthetic example below comes out all magenta.Reproduction without any game file:
Changes:
astc()/get_astc_context()take an optionalhdrargument (defaultFalse, so existing callers are unchanged). Withhdr=Truethe context usesASTCProfile.HDR, withoutUSE_DECODE_UNORM8, which astcenc only accepts for the LDR profiles. The context cache is keyed by it as well, so an HDR context is only created in a thread that decodes an HDR texture.ASTC_HDR_*entries ofCONV_TABLEpasshdr=True.RGBAHalfandBC6H. Keeping the HDR range would need a non-Pillow output, as discussed in feat: Lock-free ASTC codec operations #342; this change only replaces the error colour with the clamped image. If you would rather keep these formats unsupported until such an output exists, I can change this PR to raiseNotImplementedErrorfor them instead, which at least avoids returning a magenta image that looks like valid data.tests/test_astc.pyencodes synthetic gradients with astc-encoder and decodes them throughCONV_TABLE: HDR for all six block sizes (no error colour, values within 16 of the clamped source, clamping above 1.0) and LDR for three block sizes (within 4, unchanged by this PR). The HDR cases fail on master with the error colour.