Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
945a88ec
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,发现更多精彩内容 >>
提交
945a88ec
编写于
1月 31, 2016
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up.
上级
6fefbde3
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
31 deletion
+31
-31
examples/js/WaterShader.js
examples/js/WaterShader.js
+31
-31
未找到文件。
examples/js/WaterShader.js
浏览文件 @
945a88ec
...
...
@@ -10,7 +10,7 @@
THREE
.
ShaderLib
[
'
water
'
]
=
{
uniforms
:
THREE
.
UniformsUtils
.
merge
(
[
THREE
.
UniformsLib
[
"
fog
"
],
{
THREE
.
UniformsLib
[
"
fog
"
],
{
"
normalSampler
"
:
{
type
:
"
t
"
,
value
:
null
},
"
mirrorSampler
"
:
{
type
:
"
t
"
,
value
:
null
},
"
alpha
"
:
{
type
:
"
f
"
,
value
:
1.0
},
...
...
@@ -18,10 +18,10 @@ THREE.ShaderLib[ 'water' ] = {
"
distortionScale
"
:
{
type
:
"
f
"
,
value
:
20.0
},
"
noiseScale
"
:
{
type
:
"
f
"
,
value
:
1.0
},
"
textureMatrix
"
:
{
type
:
"
m4
"
,
value
:
new
THREE
.
Matrix4
()
},
"
sunColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x7F7F7F
)
},
"
sunDirection
"
:
{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
(
0.70707
,
0.70707
,
0
)
},
"
eye
"
:
{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
(
0
,
0
,
0
)
},
"
waterColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x555555
)
}
"
sunColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x7F7F7F
)
},
"
sunDirection
"
:
{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
(
0.70707
,
0.70707
,
0
)
},
"
eye
"
:
{
type
:
"
v3
"
,
value
:
new
THREE
.
Vector3
()
},
"
waterColor
"
:
{
type
:
"
c
"
,
value
:
new
THREE
.
Color
(
0x555555
)
}
}
]
),
...
...
@@ -31,7 +31,7 @@ THREE.ShaderLib[ 'water' ] = {
'
varying vec4 mirrorCoord;
'
,
'
varying vec3 worldPosition;
'
,
'
void main()
'
,
'
{
'
,
'
mirrorCoord = modelMatrix * vec4( position, 1.0 );
'
,
...
...
@@ -43,7 +43,7 @@ THREE.ShaderLib[ 'water' ] = {
fragmentShader
:
[
'
precision highp float;
'
,
'
uniform sampler2D mirrorSampler;
'
,
'
uniform float alpha;
'
,
'
uniform float time;
'
,
...
...
@@ -56,20 +56,20 @@ THREE.ShaderLib[ 'water' ] = {
'
varying vec4 mirrorCoord;
'
,
'
varying vec3 worldPosition;
'
,
'
vec4 getNoise( vec2 uv )
'
,
'
{
'
,
'
vec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);
'
,
'
vec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );
'
,
'
vec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );
'
,
'
vec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );
'
,
'
vec4 noise =
( texture2D( normalSampler, uv0 )
) +
'
,
'
( texture2D( normalSampler, uv1 )
) +
'
,
'
( texture2D( normalSampler, uv2 )
) +
'
,
'
( texture2D( normalSampler, uv3 )
);
'
,
'
vec4 noise =
texture2D( normalSampler, uv0
) +
'
,
'
texture2D( normalSampler, uv1
) +
'
,
'
texture2D( normalSampler, uv2
) +
'
,
'
texture2D( normalSampler, uv3
);
'
,
'
return noise * 0.5 - 1.0;
'
,
'
}
'
,
'
void sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor )
'
,
'
{
'
,
'
vec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );
'
,
...
...
@@ -79,7 +79,7 @@ THREE.ShaderLib[ 'water' ] = {
'
}
'
,
THREE
.
ShaderChunk
[
"
common
"
],
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
THREE
.
ShaderChunk
[
"
fog_pars_fragment
"
],
'
void main()
'
,
'
{
'
,
...
...
@@ -92,7 +92,7 @@ THREE.ShaderLib[ 'water' ] = {
'
vec3 worldToEye = eye-worldPosition;
'
,
'
vec3 eyeDirection = normalize( worldToEye );
'
,
'
sunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );
'
,
'
float distance = length(worldToEye);
'
,
'
vec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;
'
,
...
...
@@ -105,7 +105,7 @@ THREE.ShaderLib[ 'water' ] = {
'
vec3 albedo = mix( sunColor * diffuseLight * 0.3 + scatter, ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance );
'
,
'
vec3 outgoingLight = albedo;
'
,
THREE
.
ShaderChunk
[
"
fog_fragment
"
],
'
gl_FragColor = vec4( outgoingLight, alpha );
'
,
'
gl_FragColor = vec4( outgoingLight, alpha );
'
,
'
}
'
].
join
(
'
\n
'
)
...
...
@@ -123,9 +123,9 @@ THREE.Water = function ( renderer, camera, scene, options ) {
}
options
=
options
||
{};
this
.
matrixNeedsUpdate
=
true
;
var
width
=
optionalParameter
(
options
.
textureWidth
,
512
);
var
height
=
optionalParameter
(
options
.
textureHeight
,
512
);
this
.
clipBias
=
optionalParameter
(
options
.
clipBias
,
0.0
);
...
...
@@ -137,8 +137,8 @@ THREE.Water = function ( renderer, camera, scene, options ) {
this
.
waterColor
=
new
THREE
.
Color
(
optionalParameter
(
options
.
waterColor
,
0x7F7F7F
)
);
this
.
eye
=
optionalParameter
(
options
.
eye
,
new
THREE
.
Vector3
(
0
,
0
,
0
)
);
this
.
distortionScale
=
optionalParameter
(
options
.
distortionScale
,
20.0
);
this
.
side
=
optionalParameter
(
options
.
side
,
THREE
.
FrontSide
);
this
.
fog
=
optionalParameter
(
options
.
fog
,
false
);
this
.
side
=
optionalParameter
(
options
.
side
,
THREE
.
FrontSide
);
this
.
fog
=
optionalParameter
(
options
.
fog
,
false
);
this
.
renderer
=
renderer
;
this
.
scene
=
scene
;
...
...
@@ -149,33 +149,33 @@ THREE.Water = function ( renderer, camera, scene, options ) {
this
.
rotationMatrix
=
new
THREE
.
Matrix4
();
this
.
lookAtPosition
=
new
THREE
.
Vector3
(
0
,
0
,
-
1
);
this
.
clipPlane
=
new
THREE
.
Vector4
();
if
(
camera
instanceof
THREE
.
PerspectiveCamera
)
this
.
camera
=
camera
;
else
{
this
.
camera
=
new
THREE
.
PerspectiveCamera
();
console
.
log
(
this
.
name
+
'
: camera is not a Perspective Camera!
'
)
console
.
log
(
this
.
name
+
'
: camera is not a Perspective Camera!
'
)
;
}
this
.
textureMatrix
=
new
THREE
.
Matrix4
();
this
.
mirrorCamera
=
this
.
camera
.
clone
();
this
.
texture
=
new
THREE
.
WebGLRenderTarget
(
width
,
height
);
this
.
tempTexture
=
new
THREE
.
WebGLRenderTarget
(
width
,
height
);
var
mirrorShader
=
THREE
.
ShaderLib
[
"
water
"
];
var
mirrorUniforms
=
THREE
.
UniformsUtils
.
clone
(
mirrorShader
.
uniforms
);
this
.
material
=
new
THREE
.
ShaderMaterial
(
{
fragmentShader
:
mirrorShader
.
fragmentShader
,
vertexShader
:
mirrorShader
.
vertexShader
,
this
.
material
=
new
THREE
.
ShaderMaterial
(
{
fragmentShader
:
mirrorShader
.
fragmentShader
,
vertexShader
:
mirrorShader
.
vertexShader
,
uniforms
:
mirrorUniforms
,
transparent
:
true
,
side
:
this
.
side
,
fog
:
this
.
fog
fog
:
this
.
fog
}
);
this
.
material
.
uniforms
.
mirrorSampler
.
value
=
this
.
texture
;
...
...
@@ -187,9 +187,9 @@ THREE.Water = function ( renderer, camera, scene, options ) {
this
.
material
.
uniforms
.
waterColor
.
value
=
this
.
waterColor
;
this
.
material
.
uniforms
.
sunDirection
.
value
=
this
.
sunDirection
;
this
.
material
.
uniforms
.
distortionScale
.
value
=
this
.
distortionScale
;
this
.
material
.
uniforms
.
eye
.
value
=
this
.
eye
;
if
(
!
THREE
.
Math
.
isPowerOfTwo
(
width
)
||
!
THREE
.
Math
.
isPowerOfTwo
(
height
)
)
{
this
.
texture
.
generateMipmaps
=
false
;
...
...
@@ -286,7 +286,7 @@ THREE.Water.prototype.updateTextureMatrix = function () {
projectionMatrix
.
elements
[
6
]
=
c
.
y
;
projectionMatrix
.
elements
[
10
]
=
c
.
z
+
1.0
-
this
.
clipBias
;
projectionMatrix
.
elements
[
14
]
=
c
.
w
;
var
worldCoordinates
=
new
THREE
.
Vector3
();
worldCoordinates
.
setFromMatrixPosition
(
this
.
camera
.
matrixWorld
);
this
.
eye
=
worldCoordinates
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录