diff --git a/examples/jsm/loaders/DDSLoader.js b/examples/jsm/loaders/DDSLoader.js index f81537a00541c2..f2da1f6c38c406 100644 --- a/examples/jsm/loaders/DDSLoader.js +++ b/examples/jsm/loaders/DDSLoader.js @@ -109,6 +109,33 @@ class DDSLoader extends CompressedTextureLoader { } + function loadRGBMip( buffer, dataOffset, width, height ) { + + const dataLength = width * height * 3; + const srcBuffer = new Uint8Array( buffer, dataOffset, dataLength ); + const byteArray = new Uint8Array( width * height * 4 ); + let dst = 0; + let src = 0; + for ( let y = 0; y < height; y ++ ) { + + for ( let x = 0; x < width; x ++ ) { + + const b = srcBuffer[ src ]; src ++; + const g = srcBuffer[ src ]; src ++; + const r = srcBuffer[ src ]; src ++; + byteArray[ dst ] = r; dst ++; //r + byteArray[ dst ] = g; dst ++; //g + byteArray[ dst ] = b; dst ++; //b + byteArray[ dst ] = 1.0; dst ++; //a + + } + + } + + return byteArray; + + } + const FOURCC_DXT1 = fourCCToInt32( 'DXT1' ); const FOURCC_DXT3 = fourCCToInt32( 'DXT3' ); const FOURCC_DXT5 = fourCCToInt32( 'DXT5' ); @@ -161,6 +188,7 @@ class DDSLoader extends CompressedTextureLoader { const fourCC = header[ off_pfFourCC ]; let isRGBAUncompressed = false; + let isRGBUncompressed = false; let dataOffset = header[ off_size ] + 4; @@ -236,6 +264,15 @@ class DDSLoader extends CompressedTextureLoader { blockBytes = 64; dds.format = RGBAFormat; + } else if ( header[ off_RGBBitCount ] === 24 + && header[ off_RBitMask ] & 0xff0000 + && header[ off_GBitMask ] & 0xff00 + && header[ off_BBitMask ] & 0xff ) { + + isRGBUncompressed = true; + blockBytes = 64; + dds.format = RGBAFormat; + } else { console.error( 'THREE.DDSLoader.parse: Unsupported FourCC code ', int32ToFourCC( fourCC ) ); @@ -290,6 +327,11 @@ class DDSLoader extends CompressedTextureLoader { byteArray = loadARGBMip( buffer, dataOffset, width, height ); dataLength = byteArray.length; + } else if ( isRGBUncompressed ) { + + byteArray = loadRGBMip( buffer, dataOffset, width, height ); + dataLength = width * height * 3; + } else { dataLength = Math.max( 4, width ) / 4 * Math.max( 4, height ) / 4 * blockBytes; diff --git a/examples/screenshots/webgl_loader_texture_dds.jpg b/examples/screenshots/webgl_loader_texture_dds.jpg index 3a9e5ac5c9e42c..e7719ebcdacf34 100644 Binary files a/examples/screenshots/webgl_loader_texture_dds.jpg and b/examples/screenshots/webgl_loader_texture_dds.jpg differ diff --git a/examples/textures/wave_normals_24bit_uncompressed.dds b/examples/textures/wave_normals_24bit_uncompressed.dds new file mode 100644 index 00000000000000..1f935490f23425 Binary files /dev/null and b/examples/textures/wave_normals_24bit_uncompressed.dds differ diff --git a/examples/webgl_loader_texture_dds.html b/examples/webgl_loader_texture_dds.html index cafadb6ffa927e..613c4b74b65d0d 100644 --- a/examples/webgl_loader_texture_dds.html +++ b/examples/webgl_loader_texture_dds.html @@ -35,8 +35,9 @@ function init() { - camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 0.1, 100 ); - camera.position.z = 15; + camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 100 ); + camera.position.y = -2; + camera.position.z = 16; scene = new THREE.Scene(); @@ -90,6 +91,8 @@ const map10 = loader.load( 'textures/compressed/disturb_dx10_bc6h_unsigned_mip.dds' ); map10.anisotropy = 4; + const map11 = loader.load( 'textures/wave_normals_24bit_uncompressed.dds' ); + map11.anisotropy = 4; const cubemap1 = loader.load( 'textures/compressed/Mountains.dds', function ( texture ) { @@ -133,6 +136,7 @@ const material10 = new THREE.MeshBasicMaterial( { map: map8 } ); const material11 = new THREE.MeshBasicMaterial( { map: map9 } ); const material12 = new THREE.MeshBasicMaterial( { map: map10 } ); + const material13 = new THREE.MeshBasicMaterial( { map: map11 } ); let mesh = new THREE.Mesh( new THREE.TorusGeometry(), material1 ); mesh.position.x = - 10; @@ -206,6 +210,12 @@ scene.add( mesh ); meshes.push( mesh ); + mesh = new THREE.Mesh( geometry, material13 ); + mesh.position.x = -10; + mesh.position.y = -6; + scene.add( mesh ); + meshes.push( mesh ); + renderer = new THREE.WebGLRenderer( { antialias: true } ); renderer.setPixelRatio( window.devicePixelRatio ); renderer.setSize( window.innerWidth, window.innerHeight );