Переглянути джерело

Merge pull request #20376 from donmccurdy/bug-gltfloader-alpha-detection

GLTFLoader: Fix alpha detection for colorType=3,4
Mr.doob 4 роки тому
батько
коміт
45b15fe83c

+ 7 - 1
examples/js/loaders/GLTFLoader.js

@@ -2254,8 +2254,14 @@ THREE.GLTFLoader = ( function () {
 
 				if ( source.mimeType === 'image/png' ) {
 
+					// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
+					// alpha channel. This check is conservative — the image could have an alpha
+					// channel with all values == 1, and the indexed type (colorType == 3) only
+					// sometimes contains alpha.
+					//
 					// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
-					hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
+					var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
+					hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
 
 				}
 

+ 7 - 1
examples/jsm/loaders/GLTFLoader.js

@@ -2317,8 +2317,14 @@ var GLTFLoader = ( function () {
 
 				if ( source.mimeType === 'image/png' ) {
 
+					// Inspect the PNG 'IHDR' chunk to determine whether the image could have an
+					// alpha channel. This check is conservative — the image could have an alpha
+					// channel with all values == 1, and the indexed type (colorType == 3) only
+					// sometimes contains alpha.
+					//
 					// https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
-					hasAlpha = new DataView( bufferView, 25, 1 ).getUint8( 0, false ) === 6;
+					var colorType = new DataView( bufferView, 25, 1 ).getUint8( 0, false );
+					hasAlpha = colorType === 6 || colorType === 4 || colorType === 3;
 
 				}