Textures: reconstruct tangent-space Z on decoded BC5 normal maps #69
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/holdmysocks--SixNG!69
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/69/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Ahmet-Dedeler on GitHub · 2026-11-23 18:52 UTC · original
Ahmet-Dedeler:fix/bc5-normal-z→master· +51 −3 · 3 files · 1 commits · merged 2026-11-23 19:11 UTCtexture2ddecoder::decode_bc5outputs(R, G, 0, 255)for two-channel BC5 textures. Acrosspacks.rpf(3,326 / 3,329 BC5 texture bindings), BC5 textures are tangent-spacebumptexnormal maps.Leaving
B = 0caused three issues:z = -1(normals inverted into the surface) in standard glTF 2.0 viewers such as Blender.ttpf::stats()never setnormal_like(m[2] > 200.0) on BC5 normal maps.render3d_metal4.rs) readnormal_texture.sample(...).xyz * 2.0 - 1.0without reconstructingz(unlikeshader.wgsl, which already computessqrt(max(1 - x² - y², 0))).Changes
sixng-core/src/texture.rs: ReconstructB = sqrt(max(0, 1 - x² - y²))afterdecode_bc5into_rgba. R and G (DirectX green) are left untouched soshader.wgslandrender3d_metal4.rskeep working consistently, and DDS output is unchanged. Added unit testbc5_reconstructs_normal_z.sixng-core/src/ttpf.rs: Invalidate cached BC5 PNGs whose storedmean_rgba[2] < 1.0so previously exported caches pick up the reconstructed Z channel andnormal_likeflag.sixng-gui/src/render3d_metal4.rs: Reconstructsampled.z = sqrt(max(1.0 - sampled.x * sampled.x - sampled.y * sampled.y, 0.0))to matchshader.wgsl.Verification
cargo test -p sixng-core --no-default-features: 139 passed, 0 failed.cargo check --no-default-features: clean across all workspace crates (sixng-core,sixng-cli,sixng-gui).