Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
d50b29ff
T
three.js
项目概览
车家大少爷
/
three.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
three.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
d50b29ff
编写于
4月 11, 2020
作者:
G
Guilherme Avila
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
EXRLoader: add support HalfFloat texture from Float image
上级
7feede6b
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
96 addition
and
92 deletion
+96
-92
examples/js/loaders/EXRLoader.js
examples/js/loaders/EXRLoader.js
+48
-46
examples/jsm/loaders/EXRLoader.js
examples/jsm/loaders/EXRLoader.js
+48
-46
未找到文件。
examples/js/loaders/EXRLoader.js
浏览文件 @
d50b29ff
...
@@ -117,18 +117,19 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
...
@@ -117,18 +117,19 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
const
logBase
=
Math
.
pow
(
2.7182818
,
2.2
);
const
logBase
=
Math
.
pow
(
2.7182818
,
2.2
);
var
tmpDataView
=
new
DataView
(
new
ArrayBuffer
(
8
)
);
function
frexp
(
value
)
{
function
frexp
(
value
)
{
if
(
value
===
0
)
return
[
value
,
0
];
if
(
value
===
0
)
return
[
value
,
0
];
var
data
=
new
DataView
(
new
ArrayBuffer
(
8
)
);
tmpDataView
.
setFloat64
(
0
,
value
);
data
.
setFloat64
(
0
,
value
);
var
bits
=
(
data
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
;
var
bits
=
(
tmpDataView
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
;
if
(
bits
===
0
)
{
// denormal
if
(
bits
===
0
)
{
// denormal
data
.
setFloat64
(
0
,
value
*
Math
.
pow
(
2
,
64
)
);
// exp + 64
tmpDataView
.
setFloat64
(
0
,
value
*
Math
.
pow
(
2
,
64
)
);
// exp + 64
bits
=
(
(
data
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
)
-
64
;
bits
=
(
(
tmpDataView
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
)
-
64
;
}
}
var
exponent
=
bits
-
1022
;
var
exponent
=
bits
-
1022
;
...
@@ -1676,6 +1677,12 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
...
@@ -1676,6 +1677,12 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
}
}
function
decodeFloat32
(
dataView
,
offset
)
{
return
encodeFloat16
(
parseFloat32
(
dataView
,
offset
)
);
}
// https://stackoverflow.com/questions/5678432/decompressing-half-precision-floats-in-javascript
// https://stackoverflow.com/questions/5678432/decompressing-half-precision-floats-in-javascript
function
decodeFloat16
(
binary
)
{
function
decodeFloat16
(
binary
)
{
...
@@ -1694,60 +1701,54 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
...
@@ -1694,60 +1701,54 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
}
}
var
encodeFloat16
=
(
function
()
{
// http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
function
encodeFloat16
(
val
)
{
// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
var
floatView
=
new
Float32Array
(
1
);
var
int32View
=
new
Int32Array
(
floatView
.
buffer
);
/* This method is faster than the OpenEXR implementation (very often
/* This method is faster than the OpenEXR implementation (very often
* used, eg. in Ogre), with the additional benefit of rounding, inspired
* used, eg. in Ogre), with the additional benefit of rounding, inspired
* by James Tursa?s half-precision code. */
* by James Tursa?s half-precision code.
return
function
toHalf
(
val
)
{
*/
floatView
[
0
]
=
val
;
var
x
=
int32View
[
0
];
var
bits
=
(
x
>>
16
)
&
0x8000
;
/* Get the sign */
var
m
=
(
x
>>
12
)
&
0x07ff
;
/* Keep one extra bit for rounding */
var
e
=
(
x
>>
23
)
&
0xff
;
/* Using int is faster here */
/* If zero, or denormal, or exponent underflows too much for a denormal
tmpDataView
.
setFloat32
(
0
,
val
);
* half, return signed zero. */
var
x
=
tmpDataView
.
getInt32
(
0
);
if
(
e
<
103
)
return
bits
;
/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
var
bits
=
(
x
>>
16
)
&
0x8000
;
/* Get the sign */
if
(
e
>
142
)
{
var
m
=
(
x
>>
12
)
&
0x07ff
;
/* Keep one extra bit for rounding */
var
e
=
(
x
>>
23
)
&
0xff
;
/* Using int is faster here */
bits
|=
0x7c00
;
/* If zero, or denormal, or exponent underflows too much for a denormal
/* If exponent was 0xff and one mantissa bit was set, it means NaN,
* half, return signed zero. */
* not Inf, so make sure we set one mantissa bit too. */
if
(
e
<
103
)
return
bits
;
bits
|=
(
(
e
==
255
)
?
0
:
1
)
&&
(
x
&
0x007fffff
);
return
bits
;
}
/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
if
(
e
>
142
)
{
/* If exponent underflows but not too much, return a denormal */
bits
|=
0x7c00
;
if
(
e
<
113
)
{
/* If exponent was 0xff and one mantissa bit was set, it means NaN,
* not Inf, so make sure we set one mantissa bit too. */
bits
|=
(
(
e
==
255
)
?
0
:
1
)
&&
(
x
&
0x007fffff
);
return
bits
;
m
|=
0x0800
;
}
/* Extra rounding may overflow and set mantissa to 0 and exponent
* to 1, which is OK. */
bits
|=
(
m
>>
(
114
-
e
)
)
+
(
(
m
>>
(
113
-
e
)
)
&
1
);
return
bits
;
}
/* If exponent underflows but not too much, return a denormal */
if
(
e
<
113
)
{
bits
|=
(
(
e
-
112
)
<<
10
)
|
(
m
>>
1
)
;
m
|=
0x0800
;
/* Extra rounding
. An overflow will set mantissa to 0 and increm
ent
/* Extra rounding
may overflow and set mantissa to 0 and expon
ent
* the exponent
, which is OK. */
* to 1
, which is OK. */
bits
+=
m
&
1
;
bits
|=
(
m
>>
(
114
-
e
)
)
+
(
(
m
>>
(
113
-
e
)
)
&
1
)
;
return
bits
;
return
bits
;
};
}
bits
|=
(
(
e
-
112
)
<<
10
)
|
(
m
>>
1
);
/* Extra rounding. An overflow will set mantissa to 0 and increment
* the exponent, which is OK. */
bits
+=
m
&
1
;
return
bits
;
}
)();
}
function
parseUint16
(
dataView
,
offset
)
{
function
parseUint16
(
dataView
,
offset
)
{
...
@@ -2046,7 +2047,8 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
...
@@ -2046,7 +2047,8 @@ THREE.EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoade
case
THREE
.
HalfFloatType
:
case
THREE
.
HalfFloatType
:
throw
'
EXRLoader.parse: unsupported HalfFloatType texture for FloatType image file.
'
;
getValue
=
decodeFloat32
;
size_t
=
FLOAT32_SIZE
;
}
}
...
...
examples/jsm/loaders/EXRLoader.js
浏览文件 @
d50b29ff
...
@@ -132,18 +132,19 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
...
@@ -132,18 +132,19 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
const
logBase
=
Math
.
pow
(
2.7182818
,
2.2
);
const
logBase
=
Math
.
pow
(
2.7182818
,
2.2
);
var
tmpDataView
=
new
DataView
(
new
ArrayBuffer
(
8
)
);
function
frexp
(
value
)
{
function
frexp
(
value
)
{
if
(
value
===
0
)
return
[
value
,
0
];
if
(
value
===
0
)
return
[
value
,
0
];
var
data
=
new
DataView
(
new
ArrayBuffer
(
8
)
);
tmpDataView
.
setFloat64
(
0
,
value
);
data
.
setFloat64
(
0
,
value
);
var
bits
=
(
data
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
;
var
bits
=
(
tmpDataView
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
;
if
(
bits
===
0
)
{
// denormal
if
(
bits
===
0
)
{
// denormal
data
.
setFloat64
(
0
,
value
*
Math
.
pow
(
2
,
64
)
);
// exp + 64
tmpDataView
.
setFloat64
(
0
,
value
*
Math
.
pow
(
2
,
64
)
);
// exp + 64
bits
=
(
(
data
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
)
-
64
;
bits
=
(
(
tmpDataView
.
getUint32
(
0
)
>>>
20
)
&
0x7FF
)
-
64
;
}
}
var
exponent
=
bits
-
1022
;
var
exponent
=
bits
-
1022
;
...
@@ -1691,6 +1692,12 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
...
@@ -1691,6 +1692,12 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
}
}
function
decodeFloat32
(
dataView
,
offset
)
{
return
encodeFloat16
(
parseFloat32
(
dataView
,
offset
)
);
}
// https://stackoverflow.com/questions/5678432/decompressing-half-precision-floats-in-javascript
// https://stackoverflow.com/questions/5678432/decompressing-half-precision-floats-in-javascript
function
decodeFloat16
(
binary
)
{
function
decodeFloat16
(
binary
)
{
...
@@ -1709,60 +1716,54 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
...
@@ -1709,60 +1716,54 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
}
}
var
encodeFloat16
=
(
function
()
{
// http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
function
encodeFloat16
(
val
)
{
// Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
var
floatView
=
new
Float32Array
(
1
);
var
int32View
=
new
Int32Array
(
floatView
.
buffer
);
/* This method is faster than the OpenEXR implementation (very often
/* This method is faster than the OpenEXR implementation (very often
* used, eg. in Ogre), with the additional benefit of rounding, inspired
* used, eg. in Ogre), with the additional benefit of rounding, inspired
* by James Tursa?s half-precision code. */
* by James Tursa?s half-precision code.
return
function
toHalf
(
val
)
{
*/
floatView
[
0
]
=
val
;
var
x
=
int32View
[
0
];
var
bits
=
(
x
>>
16
)
&
0x8000
;
/* Get the sign */
var
m
=
(
x
>>
12
)
&
0x07ff
;
/* Keep one extra bit for rounding */
var
e
=
(
x
>>
23
)
&
0xff
;
/* Using int is faster here */
/* If zero, or denormal, or exponent underflows too much for a denormal
tmpDataView
.
setFloat32
(
0
,
val
);
* half, return signed zero. */
var
x
=
tmpDataView
.
getInt32
(
0
);
if
(
e
<
103
)
return
bits
;
/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
var
bits
=
(
x
>>
16
)
&
0x8000
;
/* Get the sign */
if
(
e
>
142
)
{
var
m
=
(
x
>>
12
)
&
0x07ff
;
/* Keep one extra bit for rounding */
var
e
=
(
x
>>
23
)
&
0xff
;
/* Using int is faster here */
bits
|=
0x7c00
;
/* If zero, or denormal, or exponent underflows too much for a denormal
/* If exponent was 0xff and one mantissa bit was set, it means NaN,
* half, return signed zero. */
* not Inf, so make sure we set one mantissa bit too. */
if
(
e
<
103
)
return
bits
;
bits
|=
(
(
e
==
255
)
?
0
:
1
)
&&
(
x
&
0x007fffff
);
return
bits
;
}
/* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
if
(
e
>
142
)
{
/* If exponent underflows but not too much, return a denormal */
bits
|=
0x7c00
;
if
(
e
<
113
)
{
/* If exponent was 0xff and one mantissa bit was set, it means NaN,
* not Inf, so make sure we set one mantissa bit too. */
bits
|=
(
(
e
==
255
)
?
0
:
1
)
&&
(
x
&
0x007fffff
);
return
bits
;
m
|=
0x0800
;
}
/* Extra rounding may overflow and set mantissa to 0 and exponent
* to 1, which is OK. */
bits
|=
(
m
>>
(
114
-
e
)
)
+
(
(
m
>>
(
113
-
e
)
)
&
1
);
return
bits
;
}
/* If exponent underflows but not too much, return a denormal */
if
(
e
<
113
)
{
bits
|=
(
(
e
-
112
)
<<
10
)
|
(
m
>>
1
)
;
m
|=
0x0800
;
/* Extra rounding
. An overflow will set mantissa to 0 and increm
ent
/* Extra rounding
may overflow and set mantissa to 0 and expon
ent
* the exponent
, which is OK. */
* to 1
, which is OK. */
bits
+=
m
&
1
;
bits
|=
(
m
>>
(
114
-
e
)
)
+
(
(
m
>>
(
113
-
e
)
)
&
1
)
;
return
bits
;
return
bits
;
};
}
bits
|=
(
(
e
-
112
)
<<
10
)
|
(
m
>>
1
);
/* Extra rounding. An overflow will set mantissa to 0 and increment
* the exponent, which is OK. */
bits
+=
m
&
1
;
return
bits
;
}
)();
}
function
parseUint16
(
dataView
,
offset
)
{
function
parseUint16
(
dataView
,
offset
)
{
...
@@ -2061,7 +2062,8 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
...
@@ -2061,7 +2062,8 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
case
HalfFloatType
:
case
HalfFloatType
:
throw
'
EXRLoader.parse: unsupported HalfFloatType texture for FloatType image file.
'
;
getValue
=
decodeFloat32
;
size_t
=
FLOAT32_SIZE
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录