@@ -1231,7 +1231,7 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
12311231
12321232 for ( var i = 0 ; i < 64 ; ++ i ) {
12331233
1234- dst [ idx + i ] = encodeFloat16 ( toLinear ( src [ i ] ) ) ;
1234+ dst [ idx + i ] = THREE . DataUtils . toHalfFloat ( toLinear ( src [ i ] ) ) ;
12351235
12361236 }
12371237
@@ -1816,7 +1816,7 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
18161816
18171817 function decodeFloat32 ( dataView , offset ) {
18181818
1819- return encodeFloat16 ( parseFloat32 ( dataView , offset ) ) ;
1819+ return THREE . DataUtils . toHalfFloat ( parseFloat32 ( dataView , offset ) ) ;
18201820
18211821 }
18221822
@@ -1838,55 +1838,6 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
18381838
18391839 }
18401840
1841- // http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
1842- function encodeFloat16 ( val ) {
1843-
1844- /* This method is faster than the OpenEXR implementation (very often
1845- * used, eg. in Ogre), with the additional benefit of rounding, inspired
1846- * by James Tursa?s half-precision code.
1847- */
1848-
1849- tmpDataView . setFloat32 ( 0 , val ) ;
1850- var x = tmpDataView . getInt32 ( 0 ) ;
1851-
1852- var bits = ( x >> 16 ) & 0x8000 ; /* Get the sign */
1853- var m = ( x >> 12 ) & 0x07ff ; /* Keep one extra bit for rounding */
1854- var e = ( x >> 23 ) & 0xff ; /* Using int is faster here */
1855-
1856- /* If zero, or denormal, or exponent underflows too much for a denormal
1857- * half, return signed zero. */
1858- if ( e < 103 ) return bits ;
1859-
1860- /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
1861- if ( e > 142 ) {
1862-
1863- bits |= 0x7c00 ;
1864- /* If exponent was 0xff and one mantissa bit was set, it means NaN,
1865- * not Inf, so make sure we set one mantissa bit too. */
1866- bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff ) ;
1867- return bits ;
1868-
1869- }
1870-
1871- /* If exponent underflows but not too much, return a denormal */
1872- if ( e < 113 ) {
1873-
1874- m |= 0x0800 ;
1875- /* Extra rounding may overflow and set mantissa to 0 and exponent
1876- * to 1, which is OK. */
1877- bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 ) ;
1878- return bits ;
1879-
1880- }
1881-
1882- bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 ) ;
1883- /* Extra rounding. An overflow will set mantissa to 0 and increment
1884- * the exponent, which is OK. */
1885- bits += m & 1 ;
1886- return bits ;
1887-
1888- }
1889-
18901841 function parseUint16 ( dataView , offset ) {
18911842
18921843 var Uint16 = dataView . getUint16 ( offset . value , true ) ;
0 commit comments