Skip to content

Commit 45b15fe

Browse files
authored
Merge pull request #20376 from donmccurdy/bug-gltfloader-alpha-detection
GLTFLoader: Fix alpha detection for colorType=3,4
2 parents e22c4ff + cefb1f9 commit 45b15fe

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

examples/js/loaders/GLTFLoader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,8 +2254,14 @@ THREE.GLTFLoader = ( function () {
22542254

22552255
if ( source.mimeType === 'image/png' ) {
22562256

2257+
// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
2258+
// alpha channel. This check is conservative — the image could have an alpha
2259+
// channel with all values == 1, and the indexed type (colorType == 3) only
2260+
// sometimes contains alpha.
2261+
//
22572262
// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
2258-
hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
2263+
var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
2264+
hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
22592265

22602266
}
22612267

examples/jsm/loaders/GLTFLoader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2317,8 +2317,14 @@ var GLTFLoader = ( function () {
23172317

23182318
if ( source.mimeType === 'image/png' ) {
23192319

2320+
// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
2321+
// alpha channel. This check is conservative — the image could have an alpha
2322+
// channel with all values == 1, and the indexed type (colorType == 3) only
2323+
// sometimes contains alpha.
2324+
//
23202325
// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
2321-
hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
2326+
var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
2327+
hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
23222328

23232329
}
23242330

0 commit comments

Comments
 (0)