Repository navigation
fix: Warn about texture channel mismatches in the glTF exporter - #9851
Open
willeastcott wants to merge 1 commit into
Open
willeastcott wants to merge 1 commit into
willeastcott wants to merge 1 commit into
Conversation
glTF reads each texture from fixed channels, such as occlusion, clearcoat, iridescence and transmission from red, metalness from blue, and sheen roughness and specular strength from alpha. Apart from the diffuse transmission map, whose channel it moves into alpha, the exporter attached material maps to these textures without checking which channel the material samples, and exported their texels unchanged. The StandardMaterial defaults for the AO, clearcoat, iridescence, metalness, refraction, sheen gloss and specularity factor maps are the green channel, so materials authored in the engine exported these maps to textures that glTF reads from a different channel. Materials imported from glTF set the channels glTF reads, so they were unaffected. glTF also reads roughness from the metallic-roughness texture, which the exporter fills from the metalness map. A gloss map that wasn't the same texture as the metalness map was dropped silently, and glTF read roughness from whatever the metalness map held in its green channel. The exporter now warns when a material samples a map from other channels than glTF reads, when its gloss and metalness maps aren't the same texture, and when its base gloss map holds gloss rather than roughness, as it already does for the clearcoat and sheen gloss maps. The build() documentation describes these limitations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build size reportThis PR changes the size of the minified bundles.
|
This branch was successfully 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.
Follows #9837, which made the glTF exporter honour the clearcoat and sheen gloss invert flags and warn when it exports their gloss maps as roughness textures.
glTF reads each texture from fixed channels: occlusion, clearcoat, iridescence and transmission from red, roughness from green, metalness from blue, and sheen roughness and specular strength from alpha. The exporter attached material maps to these textures without checking which channel the material samples. Apart from the diffuse transmission map, whose channel it has moved into alpha since #9558, it exports texels unchanged.
Several
StandardMaterialmaps default to the green channel:aoMapChannel,clearCoatMapChannel,iridescenceMapChannel,metalnessMapChannel,refractionMapChannel,sheenGlossMapChannelandspecularityFactorMapChannel. Materials authored in the engine therefore exported these maps, without any warning, to textures that glTF reads from a different channel. The baseglossMapwas also dropped silently unless it was the same texture as themetalnessMap, and glTF then read roughness from the metalness map's green channel.Materials imported from glTF set the channels glTF reads, so they export as before, with no warnings.
Changes
glossMapandmetalnessMaparen't the same texture. In that case the gloss map isn't exported, and glTF reads roughness from the metalness map.glossMapandmetalnessMapare the same texture, it checksglossMapChannelandglossInvert, as fix: Honour the clearcoat and sheen gloss invert flags in the glTF exporter #9837 does for the clearcoat and sheen gloss maps.GltfExporter#builddocumentation lists these limitations.A grayscale texture holds the same data in its red, green and blue channels, so a warning such as
aoMapChannel'g' against glTF's 'r' is harmless for it. The exporter can't tell without reading the texels.Public API
No API changes.
build()can log newconsole.warnmessages, and its documentation is updated.Tests
Verification
npm run lint: no errors.npm test: 4566 passing, 43 pending.npm run test:webgpu: 4564 passing, 40 pending.npm run docs: no warnings, and the new links in thebuild()documentation resolve.main: the 16 channel mismatch cases and the 4 gloss and metalness cases.Possible follow-up
The channel copy added for the diffuse transmission map could also move the other single-channel maps into the channel glTF reads, so they export correctly instead of only producing a warning.
🤖 Generated with Claude Code