Skip to content

Commit cefb1f9

Browse files
author
Don McCurdy
committed
GLTFLoader: Fix alpha detection for colorType=3,4
1 parent 62813ff commit cefb1f9

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
@@ -2170,8 +2170,14 @@ THREE.GLTFLoader = ( function () {
21702170

21712171
if ( source.mimeType === 'image/png' ) {
21722172

2173+
// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
2174+
// alpha channel. This check is conservative — the image could have an alpha
2175+
// channel with all values == 1, and the indexed type (colorType == 3) only
2176+
// sometimes contains alpha.
2177+
//
21732178
// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
2174-
hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
2179+
var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
2180+
hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
21752181

21762182
}
21772183

examples/jsm/loaders/GLTFLoader.js

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

22342234
if ( source.mimeType === 'image/png' ) {
22352235

2236+
// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
2237+
// alpha channel. This check is conservative — the image could have an alpha
2238+
// channel with all values == 1, and the indexed type (colorType == 3) only
2239+
// sometimes contains alpha.
2240+
//
22362241
// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
2237-
hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
2242+
var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
2243+
hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
22382244

22392245
}
22402246

0 commit comments

Comments
 (0)