Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
fddef609
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,发现更多精彩内容 >>
提交
fddef609
编写于
12月 27, 2011
作者:
A
alteredq
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added linear color space handling to normal map shader.
上级
b54b8ead
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
136 addition
and
33 deletion
+136
-33
build/Three.js
build/Three.js
+6
-5
build/custom/ThreeCanvas.js
build/custom/ThreeCanvas.js
+4
-3
build/custom/ThreeDOM.js
build/custom/ThreeDOM.js
+4
-3
build/custom/ThreeExtras.js
build/custom/ThreeExtras.js
+2
-2
build/custom/ThreeSVG.js
build/custom/ThreeSVG.js
+4
-3
build/custom/ThreeWebGL.js
build/custom/ThreeWebGL.js
+4
-3
examples/webgl_materials_normalmap.html
examples/webgl_materials_normalmap.html
+10
-0
examples/webgl_materials_normalmap2.html
examples/webgl_materials_normalmap2.html
+11
-4
examples/webgl_postprocessing.html
examples/webgl_postprocessing.html
+14
-3
examples/webgl_trackballcamera_earth.html
examples/webgl_trackballcamera_earth.html
+14
-3
src/core/Color.js
src/core/Color.js
+22
-0
src/extras/ShaderUtils.js
src/extras/ShaderUtils.js
+41
-4
未找到文件。
build/Three.js
浏览文件 @
fddef609
...
...
@@ -2,9 +2,10 @@
'
use strict
'
;
var
THREE
=
THREE
||
{};
if
(
!
self
.
Int32Array
)
self
.
Int32Array
=
Array
,
self
.
Float32Array
=
Array
;
if
(
!
self
.
requestAnimationFrame
)
self
.
requestAnimationFrame
=
function
(){
return
self
.
webkitRequestAnimationFrame
||
self
.
mozRequestAnimationFrame
||
self
.
oRequestAnimationFrame
||
self
.
msRequestAnimationFrame
||
function
(
a
){
self
.
setTimeout
(
a
,
1
E3
/
60
)}}();
THREE
.
Clock
=
function
(
a
){
this
.
autoStart
=
void
0
!==
a
?
a
:
!
0
;
this
.
elapsedTime
=
this
.
oldTime
=
this
.
startTime
=
0
;
this
.
running
=!
1
};
THREE
.
Clock
.
prototype
.
start
=
function
(){
this
.
oldTime
=
this
.
startTime
=
Date
.
now
();
this
.
running
=!
0
};
THREE
.
Clock
.
prototype
.
stop
=
function
(){
this
.
getElapsedTime
();
this
.
running
=!
1
};
THREE
.
Clock
.
prototype
.
getElapsedTime
=
function
(){
return
this
.
elapsedTime
+=
this
.
getDelta
()};
THREE
.
Clock
.
prototype
.
getDelta
=
function
(){
var
a
=
0
;
this
.
autoStart
&&!
this
.
running
&&
this
.
start
();
if
(
this
.
running
){
var
b
=
Date
.
now
(),
a
=
0.0010
*
(
b
-
this
.
oldTime
);
this
.
oldTime
=
b
;
this
.
elapsedTime
+=
a
}
return
a
};
THREE
.
Color
=
function
(
a
){
void
0
!==
a
&&
this
.
setHex
(
a
);
return
this
};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
convertGammaToLinear
:
function
(){
var
a
=
this
.
r
,
b
=
this
.
g
,
c
=
this
.
b
;
this
.
r
=
a
*
a
;
this
.
g
=
b
*
b
;
this
.
b
=
c
*
c
;
return
this
},
convertLinearToGamma
:
function
(){
this
.
r
=
Math
.
sqrt
(
this
.
r
);
this
.
g
=
Math
.
sqrt
(
this
.
g
);
this
.
b
=
Math
.
sqrt
(
this
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Frustum
.
prototype
.
setFromMatrix
=
function
(
a
){
var
b
,
c
=
this
.
planes
;
c
[
0
].
set
(
a
.
n41
-
a
.
n11
,
a
.
n42
-
a
.
n12
,
a
.
n43
-
a
.
n13
,
a
.
n44
-
a
.
n14
);
c
[
1
].
set
(
a
.
n41
+
a
.
n11
,
a
.
n42
+
a
.
n12
,
a
.
n43
+
a
.
n13
,
a
.
n44
+
a
.
n14
);
c
[
2
].
set
(
a
.
n41
+
a
.
n21
,
a
.
n42
+
a
.
n22
,
a
.
n43
+
a
.
n23
,
a
.
n44
+
a
.
n24
);
c
[
3
].
set
(
a
.
n41
-
a
.
n21
,
a
.
n42
-
a
.
n22
,
a
.
n43
-
a
.
n23
,
a
.
n44
-
a
.
n24
);
c
[
4
].
set
(
a
.
n41
-
a
.
n31
,
a
.
n42
-
a
.
n32
,
a
.
n43
-
a
.
n33
,
a
.
n44
-
a
.
n34
);
c
[
5
].
set
(
a
.
n41
+
a
.
n31
,
a
.
n42
+
a
.
n32
,
a
.
n43
+
a
.
n33
,
a
.
n44
+
a
.
n34
);
for
(
a
=
0
;
6
>
a
;
a
++
)
b
=
c
[
a
],
b
.
divideScalar
(
Math
.
sqrt
(
b
.
x
*
b
.
x
+
b
.
y
*
b
.
y
+
b
.
z
*
b
.
z
))};
THREE
.
Frustum
.
prototype
.
contains
=
function
(
a
){
for
(
var
b
=
this
.
planes
,
c
=
a
.
matrixWorld
,
d
=-
a
.
geometry
.
boundingSphere
.
radius
*
Math
.
max
(
a
.
scale
.
x
,
Math
.
max
(
a
.
scale
.
y
,
a
.
scale
.
z
)),
e
=
0
;
6
>
e
;
e
++
)
if
(
a
=
b
[
e
].
x
*
c
.
n14
+
b
[
e
].
y
*
c
.
n24
+
b
[
e
].
z
*
c
.
n34
+
b
[
e
].
w
,
a
<=
d
)
return
!
1
;
return
!
0
};
THREE
.
Vector2
=
function
(
a
,
b
){
this
.
x
=
a
||
0
;
this
.
y
=
b
||
0
};
THREE
.
Vector2
.
prototype
=
{
constructor
:
THREE
.
Vector2
,
set
:
function
(
a
,
b
){
this
.
x
=
a
;
this
.
y
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
x
=
a
.
x
;
this
.
y
=
a
.
y
;
return
this
},
clone
:
function
(){
return
new
THREE
.
Vector2
(
this
.
x
,
this
.
y
)},
add
:
function
(
a
,
b
){
this
.
x
=
a
.
x
+
b
.
x
;
this
.
y
=
a
.
y
+
b
.
y
;
return
this
},
addSelf
:
function
(
a
){
this
.
x
+=
a
.
x
;
this
.
y
+=
a
.
y
;
return
this
},
sub
:
function
(
a
,
b
){
this
.
x
=
a
.
x
-
b
.
x
;
this
.
y
=
a
.
y
-
b
.
y
;
return
this
},
subSelf
:
function
(
a
){
this
.
x
-=
a
.
x
;
this
.
y
-=
a
.
y
;
return
this
},
multiplyScalar
:
function
(
a
){
this
.
x
*=
a
;
this
.
y
*=
a
;
return
this
},
...
...
@@ -376,8 +377,8 @@ if(THREE.WebGLRenderer)THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRat
vertexShader
:
"
uniform float mRefractionRatio;
\n
uniform float mFresnelBias;
\n
uniform float mFresnelScale;
\n
uniform float mFresnelPower;
\n
varying vec3 vReflect;
\n
varying vec3 vRefract[3];
\n
varying float vReflectionFactor;
\n
void main() {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );
\n
vec3 I = mPosition.xyz - cameraPosition;
\n
vReflect = reflect( I, nWorld );
\n
vRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );
\n
vRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );
\n
vRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );
\n
vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );
\n
gl_Position = projectionMatrix * mvPosition;
\n
}
"
},
normal
:{
uniforms
:
THREE
.
UniformsUtils
.
merge
([
THREE
.
UniformsLib
.
fog
,
THREE
.
UniformsLib
.
lights
,
THREE
.
UniformsLib
.
shadowmap
,{
enableAO
:{
type
:
"
i
"
,
value
:
0
},
enableDiffuse
:{
type
:
"
i
"
,
value
:
0
},
enableSpecular
:{
type
:
"
i
"
,
value
:
0
},
enableReflection
:{
type
:
"
i
"
,
value
:
0
},
tDiffuse
:{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
tNormal
:{
type
:
"
t
"
,
value
:
2
,
texture
:
null
},
tSpecular
:{
type
:
"
t
"
,
value
:
3
,
texture
:
null
},
tAO
:{
type
:
"
t
"
,
value
:
4
,
texture
:
null
},
tDisplacement
:{
type
:
"
t
"
,
value
:
5
,
texture
:
null
},
uNormalScale
:{
type
:
"
f
"
,
value
:
1
},
uDisplacementBias
:{
type
:
"
f
"
,
value
:
0
},
uDisplacementScale
:{
type
:
"
f
"
,
value
:
1
},
uDiffuseColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
15658734
)},
uSpecularColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
1118481
)},
uAmbientColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
328965
)},
uShininess
:{
type
:
"
f
"
,
value
:
30
},
uOpacity
:{
type
:
"
f
"
,
value
:
1
},
uReflectivity
:{
type
:
"
f
"
,
value
:
0.5
},
uOffset
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
0
,
0
)},
uRepeat
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
1
,
1
)}}]),
fragmentShader
:[
"
uniform vec3 uAmbientColor;
\n
uniform vec3 uDiffuseColor;
\n
uniform vec3 uSpecularColor;
\n
uniform float uShininess;
\n
uniform float uOpacity;
\n
uniform bool enableDiffuse;
\n
uniform bool enableSpecular;
\n
uniform bool enableAO;
\n
uniform bool enableReflection;
\n
uniform sampler2D tDiffuse;
\n
uniform sampler2D tNormal;
\n
uniform sampler2D tSpecular;
\n
uniform sampler2D tAO;
\n
uniform samplerCube tCube;
\n
uniform float uNormalScale;
\n
uniform float uReflectivity;
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
uniform vec3 ambientLightColor;
\n
#if MAX_DIR_LIGHTS > 0
\n
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
\n
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
gl_FragColor = vec4( vec3( 1.0 ), uOpacity );
\n
vec3 specularTex = vec3( 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse )
\n
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
\n
if( enableAO )
\n
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
\n
if( enableSpecular )
\n
specularTex = texture2D( tSpecular, vUv ).xyz;
\n
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec3 pointVector = normalize( vPointLight[ i ].xyz );
\n
vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );
\n
float pointDistance = vPointLight[ i ].w;
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
float pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );
\n
pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
float dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );
\n
dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;
\n
if ( enableReflection ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
vec3 vReflect = reflect( normalize( wPos ), normal );
\n
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
\n
}
"
,
THREE
.
ShaderChunk
.
shadowmap_fragment
,
THREE
.
ShaderChunk
.
fog_fragment
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:[
"
attribute vec4 tangent;
\n
uniform vec2 uOffset;
\n
uniform vec2 uRepeat;
\n
#ifdef VERTEX_TEXTURES
\n
uniform sampler2D tDisplacement;
\n
uniform float uDisplacementScale;
\n
uniform float uDisplacementBias;
\n
#endif
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
gl_FragColor = vec4( vec3( 1.0 ), uOpacity );
\n
vec3 specularTex = vec3( 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse )
{
\n
#ifdef GAMMA_INPUT
\n
vec4 texelColor = texture2D( tDiffuse, vUv );
\n
texelColor.xyz *= texelColor.xyz;
\n
gl_FragColor = gl_FragColor * texelColor;
\n
#else
\n
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
\n
#endif
\n
}
\n
if( enableAO ) {
\n
#ifdef GAMMA_INPUT
\n
vec4 aoColor = texture2D( tAO, vUv );
\n
aoColor.xyz *= aoColor.xyz;
\n
gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
\n
#endif
\n
}
\n
if( enableSpecular )
\n
specularTex = texture2D( tSpecular, vUv ).xyz;
\n
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec3 pointVector = normalize( vPointLight[ i ].xyz );
\n
vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );
\n
float pointDistance = vPointLight[ i ].w;
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
float pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );
\n
pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
float dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );
\n
dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;
\n
if ( enableReflection ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
vec3 vReflect = reflect( normalize( wPos ), normal );
\n
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
#ifdef GAMMA_INPUT
\n
cubeColor.xyz *= cubeColor.xyz;
\n
#endif
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
\n
}
"
,
THREE
.
ShaderChunk
.
shadowmap_fragment
,
THREE
.
ShaderChunk
.
linear_to_gamma_fragment
,
THREE
.
ShaderChunk
.
fog_fragment
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:[
"
attribute vec4 tangent;
\n
uniform vec2 uOffset;
\n
uniform vec2 uRepeat;
\n
#ifdef VERTEX_TEXTURES
\n
uniform sampler2D tDisplacement;
\n
uniform float uDisplacementScale;
\n
uniform float uDisplacementBias;
\n
#endif
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_vertex
,
"
void main() {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vViewPosition = -mvPosition.xyz;
\n
vNormal = normalMatrix * normal;
\n
vTangent = normalMatrix * tangent.xyz;
\n
vBinormal = cross( vNormal, vTangent ) * tangent.w;
\n
vUv = uv * uRepeat + uOffset;
\n
#if MAX_POINT_LIGHTS > 0
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
vPointLight[ i ] = vec4( lVector, lDistance );
\n
}
\n
#endif
\n
#ifdef VERTEX_TEXTURES
\n
vec3 dv = texture2D( tDisplacement, uv ).xyz;
\n
float df = uDisplacementScale * dv.x + uDisplacementBias;
\n
vec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;
\n
gl_Position = projectionMatrix * displacedPosition;
\n
#else
\n
gl_Position = projectionMatrix * mvPosition;
\n
#endif
"
,
THREE
.
ShaderChunk
.
shadowmap_vertex
,
"
}
"
].
join
(
"
\n
"
)},
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
tFlip
:{
type
:
"
f
"
,
value
:
-
1
}},
vertexShader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vViewPosition = cameraPosition - mPosition.xyz;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragmentShader
:
"
uniform samplerCube tCube;
\n
uniform float tFlip;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( tFlip * wPos.x, wPos.yz ) );
\n
}
"
}}};
THREE
.
BufferGeometry
=
function
(){
this
.
id
=
THREE
.
GeometryCount
++
;
this
.
vertexColorArray
=
this
.
vertexUvArray
=
this
.
vertexNormalArray
=
this
.
vertexPositionArray
=
this
.
vertexIndexArray
=
this
.
vertexColorBuffer
=
this
.
vertexUvBuffer
=
this
.
vertexNormalBuffer
=
this
.
vertexPositionBuffer
=
this
.
vertexIndexBuffer
=
null
;
this
.
dynamic
=!
1
;
this
.
boundingSphere
=
this
.
boundingBox
=
null
;
this
.
morphTargets
=
[]};
THREE
.
BufferGeometry
.
prototype
=
{
constructor
:
THREE
.
BufferGeometry
,
computeBoundingBox
:
function
(){},
computeBoundingSphere
:
function
(){}};
...
...
build/custom/ThreeCanvas.js
浏览文件 @
fddef609
// ThreeCanvas.js r47dev - http://github.com/mrdoob/three.js
'
use strict
'
;
var
THREE
=
THREE
||
{};
if
(
!
self
.
Int32Array
)
self
.
Int32Array
=
Array
,
self
.
Float32Array
=
Array
;
if
(
!
self
.
requestAnimationFrame
)
self
.
requestAnimationFrame
=
function
(){
return
self
.
webkitRequestAnimationFrame
||
self
.
mozRequestAnimationFrame
||
self
.
oRequestAnimationFrame
||
self
.
msRequestAnimationFrame
||
function
(
a
){
self
.
setTimeout
(
a
,
1
E3
/
60
)}}();
THREE
.
Color
=
function
(
a
){
void
0
!==
a
&&
this
.
setHex
(
a
);
return
this
};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
convertGammaToLinear
:
function
(){
var
a
=
this
.
r
,
b
=
this
.
g
,
c
=
this
.
b
;
this
.
r
=
a
*
a
;
this
.
g
=
b
*
b
;
this
.
b
=
c
*
c
;
return
this
},
convertLinearToGamma
:
function
(){
this
.
r
=
Math
.
sqrt
(
this
.
r
);
this
.
g
=
Math
.
sqrt
(
this
.
g
);
this
.
b
=
Math
.
sqrt
(
this
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Frustum
.
prototype
.
setFromMatrix
=
function
(
a
){
var
b
,
c
=
this
.
planes
;
c
[
0
].
set
(
a
.
n41
-
a
.
n11
,
a
.
n42
-
a
.
n12
,
a
.
n43
-
a
.
n13
,
a
.
n44
-
a
.
n14
);
c
[
1
].
set
(
a
.
n41
+
a
.
n11
,
a
.
n42
+
a
.
n12
,
a
.
n43
+
a
.
n13
,
a
.
n44
+
a
.
n14
);
c
[
2
].
set
(
a
.
n41
+
a
.
n21
,
a
.
n42
+
a
.
n22
,
a
.
n43
+
a
.
n23
,
a
.
n44
+
a
.
n24
);
c
[
3
].
set
(
a
.
n41
-
a
.
n21
,
a
.
n42
-
a
.
n22
,
a
.
n43
-
a
.
n23
,
a
.
n44
-
a
.
n24
);
c
[
4
].
set
(
a
.
n41
-
a
.
n31
,
a
.
n42
-
a
.
n32
,
a
.
n43
-
a
.
n33
,
a
.
n44
-
a
.
n34
);
c
[
5
].
set
(
a
.
n41
+
a
.
n31
,
a
.
n42
+
a
.
n32
,
a
.
n43
+
a
.
n33
,
a
.
n44
+
a
.
n34
);
for
(
a
=
0
;
6
>
a
;
a
++
)
b
=
c
[
a
],
b
.
divideScalar
(
Math
.
sqrt
(
b
.
x
*
b
.
x
+
b
.
y
*
b
.
y
+
b
.
z
*
b
.
z
))};
THREE
.
Frustum
.
prototype
.
contains
=
function
(
a
){
for
(
var
b
=
this
.
planes
,
c
=
a
.
matrixWorld
,
d
=-
a
.
geometry
.
boundingSphere
.
radius
*
Math
.
max
(
a
.
scale
.
x
,
Math
.
max
(
a
.
scale
.
y
,
a
.
scale
.
z
)),
e
=
0
;
6
>
e
;
e
++
)
if
(
a
=
b
[
e
].
x
*
c
.
n14
+
b
[
e
].
y
*
c
.
n24
+
b
[
e
].
z
*
c
.
n34
+
b
[
e
].
w
,
a
<=
d
)
return
!
1
;
return
!
0
};
THREE
.
Vector2
=
function
(
a
,
b
){
this
.
x
=
a
||
0
;
this
.
y
=
b
||
0
};
THREE
.
Vector2
.
prototype
=
{
constructor
:
THREE
.
Vector2
,
set
:
function
(
a
,
b
){
this
.
x
=
a
;
this
.
y
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
x
=
a
.
x
;
this
.
y
=
a
.
y
;
return
this
},
clone
:
function
(){
return
new
THREE
.
Vector2
(
this
.
x
,
this
.
y
)},
add
:
function
(
a
,
b
){
this
.
x
=
a
.
x
+
b
.
x
;
this
.
y
=
a
.
y
+
b
.
y
;
return
this
},
addSelf
:
function
(
a
){
this
.
x
+=
a
.
x
;
this
.
y
+=
a
.
y
;
return
this
},
sub
:
function
(
a
,
b
){
this
.
x
=
a
.
x
-
b
.
x
;
this
.
y
=
a
.
y
-
b
.
y
;
return
this
},
subSelf
:
function
(
a
){
this
.
x
-=
a
.
x
;
this
.
y
-=
a
.
y
;
return
this
},
multiplyScalar
:
function
(
a
){
this
.
x
*=
a
;
this
.
y
*=
a
;
return
this
},
...
...
build/custom/ThreeDOM.js
浏览文件 @
fddef609
// ThreeDOM.js r47dev - http://github.com/mrdoob/three.js
'
use strict
'
;
var
THREE
=
THREE
||
{};
if
(
!
self
.
Int32Array
)
self
.
Int32Array
=
Array
,
self
.
Float32Array
=
Array
;
if
(
!
self
.
requestAnimationFrame
)
self
.
requestAnimationFrame
=
function
(){
return
self
.
webkitRequestAnimationFrame
||
self
.
mozRequestAnimationFrame
||
self
.
oRequestAnimationFrame
||
self
.
msRequestAnimationFrame
||
function
(
a
){
self
.
setTimeout
(
a
,
1
E3
/
60
)}}();
THREE
.
Color
=
function
(
a
){
void
0
!==
a
&&
this
.
setHex
(
a
);
return
this
};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
convertGammaToLinear
:
function
(){
var
a
=
this
.
r
,
b
=
this
.
g
,
c
=
this
.
b
;
this
.
r
=
a
*
a
;
this
.
g
=
b
*
b
;
this
.
b
=
c
*
c
;
return
this
},
convertLinearToGamma
:
function
(){
this
.
r
=
Math
.
sqrt
(
this
.
r
);
this
.
g
=
Math
.
sqrt
(
this
.
g
);
this
.
b
=
Math
.
sqrt
(
this
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Frustum
.
prototype
.
setFromMatrix
=
function
(
a
){
var
b
,
c
=
this
.
planes
;
c
[
0
].
set
(
a
.
n41
-
a
.
n11
,
a
.
n42
-
a
.
n12
,
a
.
n43
-
a
.
n13
,
a
.
n44
-
a
.
n14
);
c
[
1
].
set
(
a
.
n41
+
a
.
n11
,
a
.
n42
+
a
.
n12
,
a
.
n43
+
a
.
n13
,
a
.
n44
+
a
.
n14
);
c
[
2
].
set
(
a
.
n41
+
a
.
n21
,
a
.
n42
+
a
.
n22
,
a
.
n43
+
a
.
n23
,
a
.
n44
+
a
.
n24
);
c
[
3
].
set
(
a
.
n41
-
a
.
n21
,
a
.
n42
-
a
.
n22
,
a
.
n43
-
a
.
n23
,
a
.
n44
-
a
.
n24
);
c
[
4
].
set
(
a
.
n41
-
a
.
n31
,
a
.
n42
-
a
.
n32
,
a
.
n43
-
a
.
n33
,
a
.
n44
-
a
.
n34
);
c
[
5
].
set
(
a
.
n41
+
a
.
n31
,
a
.
n42
+
a
.
n32
,
a
.
n43
+
a
.
n33
,
a
.
n44
+
a
.
n34
);
for
(
a
=
0
;
6
>
a
;
a
++
)
b
=
c
[
a
],
b
.
divideScalar
(
Math
.
sqrt
(
b
.
x
*
b
.
x
+
b
.
y
*
b
.
y
+
b
.
z
*
b
.
z
))};
THREE
.
Frustum
.
prototype
.
contains
=
function
(
a
){
for
(
var
b
=
this
.
planes
,
c
=
a
.
matrixWorld
,
d
=-
a
.
geometry
.
boundingSphere
.
radius
*
Math
.
max
(
a
.
scale
.
x
,
Math
.
max
(
a
.
scale
.
y
,
a
.
scale
.
z
)),
e
=
0
;
6
>
e
;
e
++
)
if
(
a
=
b
[
e
].
x
*
c
.
n14
+
b
[
e
].
y
*
c
.
n24
+
b
[
e
].
z
*
c
.
n34
+
b
[
e
].
w
,
a
<=
d
)
return
!
1
;
return
!
0
};
THREE
.
Vector2
=
function
(
a
,
b
){
this
.
x
=
a
||
0
;
this
.
y
=
b
||
0
};
THREE
.
Vector2
.
prototype
=
{
constructor
:
THREE
.
Vector2
,
set
:
function
(
a
,
b
){
this
.
x
=
a
;
this
.
y
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
x
=
a
.
x
;
this
.
y
=
a
.
y
;
return
this
},
clone
:
function
(){
return
new
THREE
.
Vector2
(
this
.
x
,
this
.
y
)},
add
:
function
(
a
,
b
){
this
.
x
=
a
.
x
+
b
.
x
;
this
.
y
=
a
.
y
+
b
.
y
;
return
this
},
addSelf
:
function
(
a
){
this
.
x
+=
a
.
x
;
this
.
y
+=
a
.
y
;
return
this
},
sub
:
function
(
a
,
b
){
this
.
x
=
a
.
x
-
b
.
x
;
this
.
y
=
a
.
y
-
b
.
y
;
return
this
},
subSelf
:
function
(
a
){
this
.
x
-=
a
.
x
;
this
.
y
-=
a
.
y
;
return
this
},
multiplyScalar
:
function
(
a
){
this
.
x
*=
a
;
this
.
y
*=
a
;
return
this
},
...
...
build/custom/ThreeExtras.js
浏览文件 @
fddef609
...
...
@@ -25,8 +25,8 @@ if(THREE.WebGLRenderer)THREE.ShaderUtils={lib:{fresnel:{uniforms:{mRefractionRat
vertexShader
:
"
uniform float mRefractionRatio;
\n
uniform float mFresnelBias;
\n
uniform float mFresnelScale;
\n
uniform float mFresnelPower;
\n
varying vec3 vReflect;
\n
varying vec3 vRefract[3];
\n
varying float vReflectionFactor;
\n
void main() {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vec3 nWorld = normalize ( mat3( objectMatrix[0].xyz, objectMatrix[1].xyz, objectMatrix[2].xyz ) * normal );
\n
vec3 I = mPosition.xyz - cameraPosition;
\n
vReflect = reflect( I, nWorld );
\n
vRefract[0] = refract( normalize( I ), nWorld, mRefractionRatio );
\n
vRefract[1] = refract( normalize( I ), nWorld, mRefractionRatio * 0.99 );
\n
vRefract[2] = refract( normalize( I ), nWorld, mRefractionRatio * 0.98 );
\n
vReflectionFactor = mFresnelBias + mFresnelScale * pow( 1.0 + dot( normalize( I ), nWorld ), mFresnelPower );
\n
gl_Position = projectionMatrix * mvPosition;
\n
}
"
},
normal
:{
uniforms
:
THREE
.
UniformsUtils
.
merge
([
THREE
.
UniformsLib
.
fog
,
THREE
.
UniformsLib
.
lights
,
THREE
.
UniformsLib
.
shadowmap
,{
enableAO
:{
type
:
"
i
"
,
value
:
0
},
enableDiffuse
:{
type
:
"
i
"
,
value
:
0
},
enableSpecular
:{
type
:
"
i
"
,
value
:
0
},
enableReflection
:{
type
:
"
i
"
,
value
:
0
},
tDiffuse
:{
type
:
"
t
"
,
value
:
0
,
texture
:
null
},
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
tNormal
:{
type
:
"
t
"
,
value
:
2
,
texture
:
null
},
tSpecular
:{
type
:
"
t
"
,
value
:
3
,
texture
:
null
},
tAO
:{
type
:
"
t
"
,
value
:
4
,
texture
:
null
},
tDisplacement
:{
type
:
"
t
"
,
value
:
5
,
texture
:
null
},
uNormalScale
:{
type
:
"
f
"
,
value
:
1
},
uDisplacementBias
:{
type
:
"
f
"
,
value
:
0
},
uDisplacementScale
:{
type
:
"
f
"
,
value
:
1
},
uDiffuseColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
15658734
)},
uSpecularColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
1118481
)},
uAmbientColor
:{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
328965
)},
uShininess
:{
type
:
"
f
"
,
value
:
30
},
uOpacity
:{
type
:
"
f
"
,
value
:
1
},
uReflectivity
:{
type
:
"
f
"
,
value
:
0.5
},
uOffset
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
0
,
0
)},
uRepeat
:{
type
:
"
v2
"
,
value
:
new
THREE
.
Vector2
(
1
,
1
)}}]),
fragmentShader
:[
"
uniform vec3 uAmbientColor;
\n
uniform vec3 uDiffuseColor;
\n
uniform vec3 uSpecularColor;
\n
uniform float uShininess;
\n
uniform float uOpacity;
\n
uniform bool enableDiffuse;
\n
uniform bool enableSpecular;
\n
uniform bool enableAO;
\n
uniform bool enableReflection;
\n
uniform sampler2D tDiffuse;
\n
uniform sampler2D tNormal;
\n
uniform sampler2D tSpecular;
\n
uniform sampler2D tAO;
\n
uniform samplerCube tCube;
\n
uniform float uNormalScale;
\n
uniform float uReflectivity;
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
uniform vec3 ambientLightColor;
\n
#if MAX_DIR_LIGHTS > 0
\n
uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];
\n
uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
gl_FragColor = vec4( vec3( 1.0 ), uOpacity );
\n
vec3 specularTex = vec3( 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse )
\n
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
\n
if( enableAO )
\n
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
\n
if( enableSpecular )
\n
specularTex = texture2D( tSpecular, vUv ).xyz;
\n
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec3 pointVector = normalize( vPointLight[ i ].xyz );
\n
vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );
\n
float pointDistance = vPointLight[ i ].w;
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
float pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );
\n
pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
float dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );
\n
dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;
\n
if ( enableReflection ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
vec3 vReflect = reflect( normalize( wPos ), normal );
\n
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
\n
}
"
,
THREE
.
ShaderChunk
.
shadowmap_fragment
,
THREE
.
ShaderChunk
.
fog_fragment
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:[
"
attribute vec4 tangent;
\n
uniform vec2 uOffset;
\n
uniform vec2 uRepeat;
\n
#ifdef VERTEX_TEXTURES
\n
uniform sampler2D tDisplacement;
\n
uniform float uDisplacementScale;
\n
uniform float uDisplacementBias;
\n
#endif
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_fragment
,
THREE
.
ShaderChunk
.
fog_pars_fragment
,
"
void main() {
\n
gl_FragColor = vec4( vec3( 1.0 ), uOpacity );
\n
vec3 specularTex = vec3( 1.0 );
\n
vec3 normalTex = texture2D( tNormal, vUv ).xyz * 2.0 - 1.0;
\n
normalTex.xy *= uNormalScale;
\n
normalTex = normalize( normalTex );
\n
if( enableDiffuse )
{
\n
#ifdef GAMMA_INPUT
\n
vec4 texelColor = texture2D( tDiffuse, vUv );
\n
texelColor.xyz *= texelColor.xyz;
\n
gl_FragColor = gl_FragColor * texelColor;
\n
#else
\n
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
\n
#endif
\n
}
\n
if( enableAO ) {
\n
#ifdef GAMMA_INPUT
\n
vec4 aoColor = texture2D( tAO, vUv );
\n
aoColor.xyz *= aoColor.xyz;
\n
gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;
\n
#else
\n
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
\n
#endif
\n
}
\n
if( enableSpecular )
\n
specularTex = texture2D( tSpecular, vUv ).xyz;
\n
mat3 tsb = mat3( normalize( vTangent ), normalize( vBinormal ), normalize( vNormal ) );
\n
vec3 finalNormal = tsb * normalTex;
\n
vec3 normal = normalize( finalNormal );
\n
vec3 viewPosition = normalize( vViewPosition );
\n
#if MAX_POINT_LIGHTS > 0
\n
vec3 pointDiffuse = vec3( 0.0 );
\n
vec3 pointSpecular = vec3( 0.0 );
\n
for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {
\n
vec3 pointVector = normalize( vPointLight[ i ].xyz );
\n
vec3 pointHalfVector = normalize( vPointLight[ i ].xyz + viewPosition );
\n
float pointDistance = vPointLight[ i ].w;
\n
float pointDotNormalHalf = max( dot( normal, pointHalfVector ), 0.0 );
\n
float pointDiffuseWeight = max( dot( normal, pointVector ), 0.0 );
\n
float pointSpecularWeight = specularTex.r * pow( pointDotNormalHalf, uShininess );
\n
pointDiffuse += pointDistance * pointLightColor[ i ] * uDiffuseColor * pointDiffuseWeight;
\n
pointSpecular += pointDistance * pointLightColor[ i ] * uSpecularColor * pointSpecularWeight * pointDiffuseWeight;
\n
}
\n
#endif
\n
#if MAX_DIR_LIGHTS > 0
\n
vec3 dirDiffuse = vec3( 0.0 );
\n
vec3 dirSpecular = vec3( 0.0 );
\n
for( int i = 0; i < MAX_DIR_LIGHTS; i++ ) {
\n
vec4 lDirection = viewMatrix * vec4( directionalLightDirection[ i ], 0.0 );
\n
vec3 dirVector = normalize( lDirection.xyz );
\n
vec3 dirHalfVector = normalize( lDirection.xyz + viewPosition );
\n
float dirDotNormalHalf = max( dot( normal, dirHalfVector ), 0.0 );
\n
float dirDiffuseWeight = max( dot( normal, dirVector ), 0.0 );
\n
float dirSpecularWeight = specularTex.r * pow( dirDotNormalHalf, uShininess );
\n
dirDiffuse += directionalLightColor[ i ] * uDiffuseColor * dirDiffuseWeight;
\n
dirSpecular += directionalLightColor[ i ] * uSpecularColor * dirSpecularWeight * dirDiffuseWeight;
\n
}
\n
#endif
\n
vec3 totalDiffuse = vec3( 0.0 );
\n
vec3 totalSpecular = vec3( 0.0 );
\n
#if MAX_DIR_LIGHTS > 0
\n
totalDiffuse += dirDiffuse;
\n
totalSpecular += dirSpecular;
\n
#endif
\n
#if MAX_POINT_LIGHTS > 0
\n
totalDiffuse += pointDiffuse;
\n
totalSpecular += pointSpecular;
\n
#endif
\n
gl_FragColor.xyz = gl_FragColor.xyz * ( totalDiffuse + ambientLightColor * uAmbientColor) + totalSpecular;
\n
if ( enableReflection ) {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
vec3 vReflect = reflect( normalize( wPos ), normal );
\n
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
\n
#ifdef GAMMA_INPUT
\n
cubeColor.xyz *= cubeColor.xyz;
\n
#endif
\n
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
\n
}
"
,
THREE
.
ShaderChunk
.
shadowmap_fragment
,
THREE
.
ShaderChunk
.
linear_to_gamma_fragment
,
THREE
.
ShaderChunk
.
fog_fragment
,
"
}
"
].
join
(
"
\n
"
),
vertexShader
:[
"
attribute vec4 tangent;
\n
uniform vec2 uOffset;
\n
uniform vec2 uRepeat;
\n
#ifdef VERTEX_TEXTURES
\n
uniform sampler2D tDisplacement;
\n
uniform float uDisplacementScale;
\n
uniform float uDisplacementBias;
\n
#endif
\n
varying vec3 vTangent;
\n
varying vec3 vBinormal;
\n
varying vec3 vNormal;
\n
varying vec2 vUv;
\n
#if MAX_POINT_LIGHTS > 0
\n
uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];
\n
uniform float pointLightDistance[ MAX_POINT_LIGHTS ];
\n
varying vec4 vPointLight[ MAX_POINT_LIGHTS ];
\n
#endif
\n
varying vec3 vViewPosition;
"
,
THREE
.
ShaderChunk
.
shadowmap_pars_vertex
,
"
void main() {
\n
vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
\n
vViewPosition = -mvPosition.xyz;
\n
vNormal = normalMatrix * normal;
\n
vTangent = normalMatrix * tangent.xyz;
\n
vBinormal = cross( vNormal, vTangent ) * tangent.w;
\n
vUv = uv * uRepeat + uOffset;
\n
#if MAX_POINT_LIGHTS > 0
\n
for( int i = 0; i < MAX_POINT_LIGHTS; i++ ) {
\n
vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );
\n
vec3 lVector = lPosition.xyz - mvPosition.xyz;
\n
float lDistance = 1.0;
\n
if ( pointLightDistance[ i ] > 0.0 )
\n
lDistance = 1.0 - min( ( length( lVector ) / pointLightDistance[ i ] ), 1.0 );
\n
lVector = normalize( lVector );
\n
vPointLight[ i ] = vec4( lVector, lDistance );
\n
}
\n
#endif
\n
#ifdef VERTEX_TEXTURES
\n
vec3 dv = texture2D( tDisplacement, uv ).xyz;
\n
float df = uDisplacementScale * dv.x + uDisplacementBias;
\n
vec4 displacedPosition = vec4( normalize( vNormal.xyz ) * df, 0.0 ) + mvPosition;
\n
gl_Position = projectionMatrix * displacedPosition;
\n
#else
\n
gl_Position = projectionMatrix * mvPosition;
\n
#endif
"
,
THREE
.
ShaderChunk
.
shadowmap_vertex
,
"
}
"
].
join
(
"
\n
"
)},
cube
:{
uniforms
:{
tCube
:{
type
:
"
t
"
,
value
:
1
,
texture
:
null
},
tFlip
:{
type
:
"
f
"
,
value
:
-
1
}},
vertexShader
:
"
varying vec3 vViewPosition;
\n
void main() {
\n
vec4 mPosition = objectMatrix * vec4( position, 1.0 );
\n
vViewPosition = cameraPosition - mPosition.xyz;
\n
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
\n
}
"
,
fragmentShader
:
"
uniform samplerCube tCube;
\n
uniform float tFlip;
\n
varying vec3 vViewPosition;
\n
void main() {
\n
vec3 wPos = cameraPosition - vViewPosition;
\n
gl_FragColor = textureCube( tCube, vec3( tFlip * wPos.x, wPos.yz ) );
\n
}
"
}}};
THREE
.
BufferGeometry
=
function
(){
this
.
id
=
THREE
.
GeometryCount
++
;
this
.
vertexColorArray
=
this
.
vertexUvArray
=
this
.
vertexNormalArray
=
this
.
vertexPositionArray
=
this
.
vertexIndexArray
=
this
.
vertexColorBuffer
=
this
.
vertexUvBuffer
=
this
.
vertexNormalBuffer
=
this
.
vertexPositionBuffer
=
this
.
vertexIndexBuffer
=
null
;
this
.
dynamic
=!
1
;
this
.
boundingSphere
=
this
.
boundingBox
=
null
;
this
.
morphTargets
=
[]};
THREE
.
BufferGeometry
.
prototype
=
{
constructor
:
THREE
.
BufferGeometry
,
computeBoundingBox
:
function
(){},
computeBoundingSphere
:
function
(){}};
...
...
build/custom/ThreeSVG.js
浏览文件 @
fddef609
// ThreeSVG.js r47dev - http://github.com/mrdoob/three.js
'
use strict
'
;
var
THREE
=
THREE
||
{};
if
(
!
self
.
Int32Array
)
self
.
Int32Array
=
Array
,
self
.
Float32Array
=
Array
;
if
(
!
self
.
requestAnimationFrame
)
self
.
requestAnimationFrame
=
function
(){
return
self
.
webkitRequestAnimationFrame
||
self
.
mozRequestAnimationFrame
||
self
.
oRequestAnimationFrame
||
self
.
msRequestAnimationFrame
||
function
(
a
){
self
.
setTimeout
(
a
,
1
E3
/
60
)}}();
THREE
.
Color
=
function
(
a
){
void
0
!==
a
&&
this
.
setHex
(
a
);
return
this
};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
convertGammaToLinear
:
function
(){
var
a
=
this
.
r
,
b
=
this
.
g
,
c
=
this
.
b
;
this
.
r
=
a
*
a
;
this
.
g
=
b
*
b
;
this
.
b
=
c
*
c
;
return
this
},
convertLinearToGamma
:
function
(){
this
.
r
=
Math
.
sqrt
(
this
.
r
);
this
.
g
=
Math
.
sqrt
(
this
.
g
);
this
.
b
=
Math
.
sqrt
(
this
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
f
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
f
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
f
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
f
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
f
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Frustum
.
prototype
.
setFromMatrix
=
function
(
a
){
var
b
,
c
=
this
.
planes
;
c
[
0
].
set
(
a
.
n41
-
a
.
n11
,
a
.
n42
-
a
.
n12
,
a
.
n43
-
a
.
n13
,
a
.
n44
-
a
.
n14
);
c
[
1
].
set
(
a
.
n41
+
a
.
n11
,
a
.
n42
+
a
.
n12
,
a
.
n43
+
a
.
n13
,
a
.
n44
+
a
.
n14
);
c
[
2
].
set
(
a
.
n41
+
a
.
n21
,
a
.
n42
+
a
.
n22
,
a
.
n43
+
a
.
n23
,
a
.
n44
+
a
.
n24
);
c
[
3
].
set
(
a
.
n41
-
a
.
n21
,
a
.
n42
-
a
.
n22
,
a
.
n43
-
a
.
n23
,
a
.
n44
-
a
.
n24
);
c
[
4
].
set
(
a
.
n41
-
a
.
n31
,
a
.
n42
-
a
.
n32
,
a
.
n43
-
a
.
n33
,
a
.
n44
-
a
.
n34
);
c
[
5
].
set
(
a
.
n41
+
a
.
n31
,
a
.
n42
+
a
.
n32
,
a
.
n43
+
a
.
n33
,
a
.
n44
+
a
.
n34
);
for
(
a
=
0
;
6
>
a
;
a
++
)
b
=
c
[
a
],
b
.
divideScalar
(
Math
.
sqrt
(
b
.
x
*
b
.
x
+
b
.
y
*
b
.
y
+
b
.
z
*
b
.
z
))};
THREE
.
Frustum
.
prototype
.
contains
=
function
(
a
){
for
(
var
b
=
this
.
planes
,
c
=
a
.
matrixWorld
,
d
=-
a
.
geometry
.
boundingSphere
.
radius
*
Math
.
max
(
a
.
scale
.
x
,
Math
.
max
(
a
.
scale
.
y
,
a
.
scale
.
z
)),
e
=
0
;
6
>
e
;
e
++
)
if
(
a
=
b
[
e
].
x
*
c
.
n14
+
b
[
e
].
y
*
c
.
n24
+
b
[
e
].
z
*
c
.
n34
+
b
[
e
].
w
,
a
<=
d
)
return
!
1
;
return
!
0
};
THREE
.
Vector2
=
function
(
a
,
b
){
this
.
x
=
a
||
0
;
this
.
y
=
b
||
0
};
THREE
.
Vector2
.
prototype
=
{
constructor
:
THREE
.
Vector2
,
set
:
function
(
a
,
b
){
this
.
x
=
a
;
this
.
y
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
x
=
a
.
x
;
this
.
y
=
a
.
y
;
return
this
},
clone
:
function
(){
return
new
THREE
.
Vector2
(
this
.
x
,
this
.
y
)},
add
:
function
(
a
,
b
){
this
.
x
=
a
.
x
+
b
.
x
;
this
.
y
=
a
.
y
+
b
.
y
;
return
this
},
addSelf
:
function
(
a
){
this
.
x
+=
a
.
x
;
this
.
y
+=
a
.
y
;
return
this
},
sub
:
function
(
a
,
b
){
this
.
x
=
a
.
x
-
b
.
x
;
this
.
y
=
a
.
y
-
b
.
y
;
return
this
},
subSelf
:
function
(
a
){
this
.
x
-=
a
.
x
;
this
.
y
-=
a
.
y
;
return
this
},
multiplyScalar
:
function
(
a
){
this
.
x
*=
a
;
this
.
y
*=
a
;
return
this
},
...
...
build/custom/ThreeWebGL.js
浏览文件 @
fddef609
// ThreeWebGL.js r47dev - http://github.com/mrdoob/three.js
'
use strict
'
;
var
THREE
=
THREE
||
{};
if
(
!
self
.
Int32Array
)
self
.
Int32Array
=
Array
,
self
.
Float32Array
=
Array
;
if
(
!
self
.
requestAnimationFrame
)
self
.
requestAnimationFrame
=
function
(){
return
self
.
webkitRequestAnimationFrame
||
self
.
mozRequestAnimationFrame
||
self
.
oRequestAnimationFrame
||
self
.
msRequestAnimationFrame
||
function
(
a
){
self
.
setTimeout
(
a
,
1
E3
/
60
)}}();
THREE
.
Color
=
function
(
a
){
void
0
!==
a
&&
this
.
setHex
(
a
);
return
this
};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
g
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
g
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
g
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
g
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
g
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Color
.
prototype
=
{
constructor
:
THREE
.
Color
,
r
:
1
,
g
:
1
,
b
:
1
,
copy
:
function
(
a
){
this
.
r
=
a
.
r
;
this
.
g
=
a
.
g
;
this
.
b
=
a
.
b
;
return
this
},
copyGammaToLinear
:
function
(
a
){
this
.
r
=
a
.
r
*
a
.
r
;
this
.
g
=
a
.
g
*
a
.
g
;
this
.
b
=
a
.
b
*
a
.
b
;
return
this
},
copyLinearToGamma
:
function
(
a
){
this
.
r
=
Math
.
sqrt
(
a
.
r
);
this
.
g
=
Math
.
sqrt
(
a
.
g
);
this
.
b
=
Math
.
sqrt
(
a
.
b
);
return
this
},
convertGammaToLinear
:
function
(){
var
a
=
this
.
r
,
b
=
this
.
g
,
c
=
this
.
b
;
this
.
r
=
a
*
a
;
this
.
g
=
b
*
b
;
this
.
b
=
c
*
c
;
return
this
},
convertLinearToGamma
:
function
(){
this
.
r
=
Math
.
sqrt
(
this
.
r
);
this
.
g
=
Math
.
sqrt
(
this
.
g
);
this
.
b
=
Math
.
sqrt
(
this
.
b
);
return
this
},
setRGB
:
function
(
a
,
b
,
c
){
this
.
r
=
a
;
this
.
g
=
b
;
this
.
b
=
c
;
return
this
},
setHSV
:
function
(
a
,
b
,
c
){
var
d
,
e
,
g
;
if
(
0
===
c
)
this
.
r
=
this
.
g
=
this
.
b
=
0
;
else
switch
(
d
=
Math
.
floor
(
6
*
a
),
e
=
6
*
a
-
d
,
a
=
c
*
(
1
-
b
),
g
=
c
*
(
1
-
b
*
e
),
b
=
c
*
(
1
-
b
*
(
1
-
e
)),
d
){
case
1
:
this
.
r
=
g
;
this
.
g
=
c
;
this
.
b
=
a
;
break
;
case
2
:
this
.
r
=
a
;
this
.
g
=
c
;
this
.
b
=
b
;
break
;
case
3
:
this
.
r
=
a
;
this
.
g
=
g
;
this
.
b
=
c
;
break
;
case
4
:
this
.
r
=
b
;
this
.
g
=
a
;
this
.
b
=
c
;
break
;
case
5
:
this
.
r
=
c
;
this
.
g
=
a
;
this
.
b
=
g
;
break
;
case
6
:
case
0
:
this
.
r
=
c
,
this
.
g
=
b
,
this
.
b
=
a
}
return
this
},
setHex
:
function
(
a
){
a
=
Math
.
floor
(
a
);
this
.
r
=
(
a
>>
16
&
255
)
/
255
;
this
.
g
=
(
a
>>
8
&
255
)
/
255
;
this
.
b
=
(
a
&
255
)
/
255
;
return
this
},
getHex
:
function
(){
return
Math
.
floor
(
255
*
this
.
r
)
<<
16
^
Math
.
floor
(
255
*
this
.
g
)
<<
8
^
Math
.
floor
(
255
*
this
.
b
)},
getContextStyle
:
function
(){
return
"
rgb(
"
+
Math
.
floor
(
255
*
this
.
r
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
g
)
+
"
,
"
+
Math
.
floor
(
255
*
this
.
b
)
+
"
)
"
},
clone
:
function
(){
return
(
new
THREE
.
Color
).
setRGB
(
this
.
r
,
this
.
g
,
this
.
b
)}};
THREE
.
Frustum
=
function
(){
this
.
planes
=
[
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
,
new
THREE
.
Vector4
]};
THREE
.
Frustum
.
prototype
.
setFromMatrix
=
function
(
a
){
var
b
,
c
=
this
.
planes
;
c
[
0
].
set
(
a
.
n41
-
a
.
n11
,
a
.
n42
-
a
.
n12
,
a
.
n43
-
a
.
n13
,
a
.
n44
-
a
.
n14
);
c
[
1
].
set
(
a
.
n41
+
a
.
n11
,
a
.
n42
+
a
.
n12
,
a
.
n43
+
a
.
n13
,
a
.
n44
+
a
.
n14
);
c
[
2
].
set
(
a
.
n41
+
a
.
n21
,
a
.
n42
+
a
.
n22
,
a
.
n43
+
a
.
n23
,
a
.
n44
+
a
.
n24
);
c
[
3
].
set
(
a
.
n41
-
a
.
n21
,
a
.
n42
-
a
.
n22
,
a
.
n43
-
a
.
n23
,
a
.
n44
-
a
.
n24
);
c
[
4
].
set
(
a
.
n41
-
a
.
n31
,
a
.
n42
-
a
.
n32
,
a
.
n43
-
a
.
n33
,
a
.
n44
-
a
.
n34
);
c
[
5
].
set
(
a
.
n41
+
a
.
n31
,
a
.
n42
+
a
.
n32
,
a
.
n43
+
a
.
n33
,
a
.
n44
+
a
.
n34
);
for
(
a
=
0
;
6
>
a
;
a
++
)
b
=
c
[
a
],
b
.
divideScalar
(
Math
.
sqrt
(
b
.
x
*
b
.
x
+
b
.
y
*
b
.
y
+
b
.
z
*
b
.
z
))};
THREE
.
Frustum
.
prototype
.
contains
=
function
(
a
){
for
(
var
b
=
this
.
planes
,
c
=
a
.
matrixWorld
,
d
=-
a
.
geometry
.
boundingSphere
.
radius
*
Math
.
max
(
a
.
scale
.
x
,
Math
.
max
(
a
.
scale
.
y
,
a
.
scale
.
z
)),
e
=
0
;
6
>
e
;
e
++
)
if
(
a
=
b
[
e
].
x
*
c
.
n14
+
b
[
e
].
y
*
c
.
n24
+
b
[
e
].
z
*
c
.
n34
+
b
[
e
].
w
,
a
<=
d
)
return
!
1
;
return
!
0
};
THREE
.
Vector2
=
function
(
a
,
b
){
this
.
x
=
a
||
0
;
this
.
y
=
b
||
0
};
THREE
.
Vector2
.
prototype
=
{
constructor
:
THREE
.
Vector2
,
set
:
function
(
a
,
b
){
this
.
x
=
a
;
this
.
y
=
b
;
return
this
},
copy
:
function
(
a
){
this
.
x
=
a
.
x
;
this
.
y
=
a
.
y
;
return
this
},
clone
:
function
(){
return
new
THREE
.
Vector2
(
this
.
x
,
this
.
y
)},
add
:
function
(
a
,
b
){
this
.
x
=
a
.
x
+
b
.
x
;
this
.
y
=
a
.
y
+
b
.
y
;
return
this
},
addSelf
:
function
(
a
){
this
.
x
+=
a
.
x
;
this
.
y
+=
a
.
y
;
return
this
},
sub
:
function
(
a
,
b
){
this
.
x
=
a
.
x
-
b
.
x
;
this
.
y
=
a
.
y
-
b
.
y
;
return
this
},
subSelf
:
function
(
a
){
this
.
x
-=
a
.
x
;
this
.
y
-=
a
.
y
;
return
this
},
multiplyScalar
:
function
(
a
){
this
.
x
*=
a
;
this
.
y
*=
a
;
return
this
},
...
...
examples/webgl_materials_normalmap.html
浏览文件 @
fddef609
...
...
@@ -175,6 +175,11 @@
uniforms
[
"
tCube
"
].
texture
=
reflectionCube
;
uniforms
[
"
uReflectivity
"
].
value
=
0.1
;
uniforms
[
"
uDiffuseColor
"
].
value
.
convertGammaToLinear
();
uniforms
[
"
uSpecularColor
"
].
value
.
convertGammaToLinear
();
uniforms
[
"
uAmbientColor
"
].
value
.
convertGammaToLinear
();
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
,
fog
:
false
};
var
material1
=
new
THREE
.
ShaderMaterial
(
parameters
);
...
...
@@ -195,6 +200,11 @@
//
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
//
renderer
.
shadowCameraFov
=
70
;
renderer
.
shadowMapBias
=
0.0039
;
...
...
examples/webgl_materials_normalmap2.html
浏览文件 @
fddef609
...
...
@@ -98,17 +98,17 @@
scene
.
add
(
ambientLight
);
pointLight
=
new
THREE
.
PointLight
(
0xffffff
);
pointLight
.
position
.
z
=
600
;
pointLight
.
position
.
set
(
0
,
0
,
600
)
;
scene
.
add
(
pointLight
);
directionalLight
=
new
THREE
.
DirectionalLight
(
0xffffff
);
directionalLight
.
position
.
set
(
1
,
1
,
-
1
).
normalize
(
);
directionalLight
.
position
.
set
(
1
,
-
0.5
,
-
1
);
scene
.
add
(
directionalLight
);
// material parameters
var
ambient
=
0x
111111
,
diffuse
=
0xaaaaaa
,
specular
=
0x080810
,
shininess
=
2
;
var
ambient
=
0x
331111
,
diffuse
=
0xbbbbbb
,
specular
=
0x080808
,
shininess
=
30
;
var
shader
=
THREE
.
ShaderUtils
.
lib
[
"
normal
"
];
var
uniforms
=
THREE
.
UniformsUtils
.
clone
(
shader
.
uniforms
);
...
...
@@ -136,10 +136,17 @@
loader
.
load
(
"
obj/leeperrysmith/LeePerrySmith.js
"
,
function
(
geometry
)
{
createScene
(
geometry
,
100
,
material
)
}
);
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
container
.
appendChild
(
renderer
.
domElement
);
//
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
//
if
(
statsEnabled
)
{
stats
=
new
Stats
();
...
...
examples/webgl_postprocessing.html
浏览文件 @
fddef609
...
...
@@ -135,7 +135,7 @@
//
directionalLight
=
new
THREE
.
DirectionalLight
(
0xffffff
);
directionalLight
.
position
.
set
(
0
,
0
,
1
).
normalize
();
directionalLight
.
position
.
set
(
0
,
-
0.1
,
1
).
normalize
();
sceneModel
.
add
(
directionalLight
);
loader
=
new
THREE
.
JSONLoader
(
true
);
...
...
@@ -178,6 +178,13 @@
renderer
.
setClearColorHex
(
0x000000
,
1
);
renderer
.
autoClear
=
false
;
//
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
//
container
.
appendChild
(
renderer
.
domElement
);
//
...
...
@@ -207,7 +214,7 @@
effectVignette
.
uniforms
[
"
darkness
"
].
value
=
1.6
;
var
effectBloom
=
new
THREE
.
BloomPass
(
0.5
);
var
effectFilm
=
new
THREE
.
FilmPass
(
0.5
,
0.025
,
648
,
false
);
var
effectFilm
=
new
THREE
.
FilmPass
(
0.
3
5
,
0.025
,
648
,
false
);
var
effectFilmBW
=
new
THREE
.
FilmPass
(
0.35
,
0.5
,
2048
,
true
);
var
effectFilmBW2
=
new
THREE
.
FilmPass
(
0.05
,
0.5
,
2048
,
true
);
var
effectDotScreen
=
new
THREE
.
DotScreenPass
(
new
THREE
.
Vector2
(
0
,
0
),
0.5
,
0.6
);
...
...
@@ -339,7 +346,7 @@
geometry
.
computeTangents
();
var
ambient
=
0x444444
,
diffuse
=
0x
888888
,
specular
=
0x080810
,
shininess
=
2
;
var
ambient
=
0x444444
,
diffuse
=
0x
999999
,
specular
=
0x080808
,
shininess
=
20
;
var
shader
=
THREE
.
ShaderUtils
.
lib
[
"
normal
"
];
var
uniforms
=
THREE
.
UniformsUtils
.
clone
(
shader
.
uniforms
);
...
...
@@ -358,6 +365,10 @@
uniforms
[
"
uShininess
"
].
value
=
shininess
;
uniforms
[
"
uDiffuseColor
"
].
value
.
convertGammaToLinear
();
uniforms
[
"
uSpecularColor
"
].
value
.
convertGammaToLinear
();
uniforms
[
"
uAmbientColor
"
].
value
.
convertGammaToLinear
();
var
parameters
=
{
fragmentShader
:
shader
.
fragmentShader
,
vertexShader
:
shader
.
vertexShader
,
uniforms
:
uniforms
,
lights
:
true
};
var
mat2
=
new
THREE
.
ShaderMaterial
(
parameters
);
...
...
examples/webgl_trackballcamera_earth.html
浏览文件 @
fddef609
...
...
@@ -85,11 +85,18 @@
scene
=
new
THREE
.
Scene
();
renderer
=
new
THREE
.
WebGLRenderer
(
{
clearAlpha
:
1
,
clearColor
:
0x000000
}
);
renderer
=
new
THREE
.
WebGLRenderer
(
{
clearAlpha
:
1
,
clearColor
:
0x000000
,
antialias
:
true
}
);
renderer
.
setSize
(
width
,
height
);
renderer
.
sortObjects
=
false
;
renderer
.
autoClear
=
false
;
//
renderer
.
gammaInput
=
true
;
renderer
.
gammaOutput
=
true
;
//
container
.
appendChild
(
renderer
.
domElement
);
camera
=
new
THREE
.
PerspectiveCamera
(
25
,
width
/
height
,
50
,
1
e7
);
...
...
@@ -137,10 +144,14 @@
uniforms
[
"
enableSpecular
"
].
value
=
true
;
uniforms
[
"
uDiffuseColor
"
].
value
.
setHex
(
0xffffff
);
uniforms
[
"
uSpecularColor
"
].
value
.
setHex
(
0x
333333
);
uniforms
[
"
uSpecularColor
"
].
value
.
setHex
(
0x
666666
);
uniforms
[
"
uAmbientColor
"
].
value
.
setHex
(
0x000000
);
uniforms
[
"
uShininess
"
].
value
=
15
;
uniforms
[
"
uShininess
"
].
value
=
20
;
uniforms
[
"
uDiffuseColor
"
].
value
.
convertGammaToLinear
();
uniforms
[
"
uSpecularColor
"
].
value
.
convertGammaToLinear
();
uniforms
[
"
uAmbientColor
"
].
value
.
convertGammaToLinear
();
var
materialNormalMap
=
new
THREE
.
ShaderMaterial
({
fragmentShader
:
shader
.
fragmentShader
,
...
...
src/core/Color.js
浏览文件 @
fddef609
...
...
@@ -45,6 +45,28 @@ THREE.Color.prototype = {
},
convertGammaToLinear
:
function
()
{
var
r
=
this
.
r
,
g
=
this
.
g
,
b
=
this
.
b
;
this
.
r
=
r
*
r
;
this
.
g
=
g
*
g
;
this
.
b
=
b
*
b
;
return
this
;
},
convertLinearToGamma
:
function
()
{
this
.
r
=
Math
.
sqrt
(
this
.
r
);
this
.
g
=
Math
.
sqrt
(
this
.
g
);
this
.
b
=
Math
.
sqrt
(
this
.
b
);
return
this
;
},
setRGB
:
function
(
r
,
g
,
b
)
{
this
.
r
=
r
;
...
...
src/extras/ShaderUtils.js
浏览文件 @
fddef609
...
...
@@ -195,11 +195,39 @@ THREE.ShaderUtils = {
"
normalTex.xy *= uNormalScale;
"
,
"
normalTex = normalize( normalTex );
"
,
"
if( enableDiffuse )
"
,
"
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
"
,
"
if( enableDiffuse ) {
"
,
"
if( enableAO )
"
,
"
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
"
,
"
#ifdef GAMMA_INPUT
"
,
"
vec4 texelColor = texture2D( tDiffuse, vUv );
"
,
"
texelColor.xyz *= texelColor.xyz;
"
,
"
gl_FragColor = gl_FragColor * texelColor;
"
,
"
#else
"
,
"
gl_FragColor = gl_FragColor * texture2D( tDiffuse, vUv );
"
,
"
#endif
"
,
"
}
"
,
"
if( enableAO ) {
"
,
"
#ifdef GAMMA_INPUT
"
,
"
vec4 aoColor = texture2D( tAO, vUv );
"
,
"
aoColor.xyz *= aoColor.xyz;
"
,
"
gl_FragColor.xyz = gl_FragColor.xyz * aoColor.xyz;
"
,
"
#else
"
,
"
gl_FragColor.xyz = gl_FragColor.xyz * texture2D( tAO, vUv ).xyz;
"
,
"
#endif
"
,
"
}
"
,
"
if( enableSpecular )
"
,
"
specularTex = texture2D( tSpecular, vUv ).xyz;
"
,
...
...
@@ -286,12 +314,21 @@ THREE.ShaderUtils = {
"
vec3 wPos = cameraPosition - vViewPosition;
"
,
"
vec3 vReflect = reflect( normalize( wPos ), normal );
"
,
"
vec4 cubeColor = textureCube( tCube, vec3( -vReflect.x, vReflect.yz ) );
"
,
"
#ifdef GAMMA_INPUT
"
,
"
cubeColor.xyz *= cubeColor.xyz;
"
,
"
#endif
"
,
"
gl_FragColor.xyz = mix( gl_FragColor.xyz, cubeColor.xyz, specularTex.r * uReflectivity );
"
,
"
}
"
,
THREE
.
ShaderChunk
[
"
shadowmap_fragment
"
],
THREE
.
ShaderChunk
[
"
linear_to_gamma_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
"
}
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录