Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Ablesons
three.js
提交
96ec75e3
T
three.js
项目概览
Ablesons
/
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,发现更多精彩内容 >>
提交
96ec75e3
编写于
10月 09, 2018
作者:
M
Mr.doob
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Examples clean up.
上级
8c482dbc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
28 deletion
+27
-28
examples/files.js
examples/files.js
+4
-4
examples/webgl_gpgpu_water.html
examples/webgl_gpgpu_water.html
+23
-24
未找到文件。
examples/files.js
浏览文件 @
96ec75e3
...
...
@@ -42,10 +42,6 @@ var files = {
"
webgl_geometry_terrain_raycast
"
,
"
webgl_geometry_text
"
,
"
webgl_geometry_text_shapes
"
,
"
webgl_gpgpu_birds
"
,
"
webgl_gpgpu_water
"
,
"
webgl_gpgpu_protoplanet
"
,
"
webgl_gpu_particle_system
"
,
"
webgl_hdr
"
,
"
webgl_helpers
"
,
"
webgl_interactive_buffergeometry
"
,
...
...
@@ -300,6 +296,10 @@ var files = {
"
webgl_custom_attributes_points
"
,
"
webgl_custom_attributes_points2
"
,
"
webgl_custom_attributes_points3
"
,
"
webgl_gpgpu_birds
"
,
"
webgl_gpgpu_water
"
,
"
webgl_gpgpu_protoplanet
"
,
"
webgl_gpu_particle_system
"
,
"
webgl_materials_modified
"
,
"
webgl_raymarching_reflect
"
,
"
webgl_shadowmap_pcss
"
,
...
...
examples/webgl_gpgpu_water.html
浏览文件 @
96ec75e3
...
...
@@ -74,12 +74,14 @@
vec4
east
=
texture2D
(
heightmap
,
uv
+
vec2
(
cellSize
.
x
,
0.0
)
);
vec4
west
=
texture2D
(
heightmap
,
uv
+
vec2
(
-
cellSize
.
x
,
0.0
)
);
// https://web.archive.org/web/20080618181901/http://freespace.virgin.net/hugo.elias/graphics/x_water.htm
float
newHeight
=
(
(
north
.
x
+
south
.
x
+
east
.
x
+
west
.
x
)
*
0.5
-
heightmapValue
.
y
)
*
viscosityConstant
;
// Mouse influence
float
mousePhase
=
clamp
(
length
(
(
uv
-
vec2
(
0.5
)
)
*
BOUNDS
-
vec2
(
mousePos
.
x
,
-
mousePos
.
y
)
)
*
PI
/
mouseSize
,
0.0
,
PI
);
newHeight
+=
(
cos
(
mousePhase
)
+
1.0
)
*
0.28
;
heightmapValue
.
y
=
heightmapValue
.
x
;
heightmapValue
.
x
=
newHeight
;
...
...
@@ -114,17 +116,17 @@
}
</script>
<!-- This is a 'compute shader' to read the current level and normal of water at a point -->
<!-- It is used with a variable of size 1x1 -->
<script
id=
"readWaterLevelFragmentShader"
type=
"x-shader/x-fragment"
>
uniform
vec2
point1
;
uniform
sampler2D
texture
;
// Integer to float conversion from https://stackoverflow.com/questions/17981163/webgl-read-pixels-from-floating-point-render-target
float
shift_right
(
float
v
,
float
amt
)
{
v
=
floor
(
v
)
+
0.5
;
...
...
@@ -132,7 +134,7 @@
}
float
shift_left
(
float
v
,
float
amt
)
{
float
shift_left
(
float
v
,
float
amt
)
{
return
floor
(
v
*
exp2
(
amt
)
+
0.5
);
...
...
@@ -181,19 +183,16 @@
if
(
gl_FragCoord
.
x
<
1.5
)
{
gl_FragColor
=
encode_float
(
waterLevel
);
}
else
if
(
gl_FragCoord
.
x
<
2.5
)
{
}
else
if
(
gl_FragCoord
.
x
<
2.5
)
{
gl_FragColor
=
encode_float
(
normal
.
x
);
}
else
if
(
gl_FragCoord
.
x
<
3.5
)
{
}
else
if
(
gl_FragCoord
.
x
<
3.5
)
{
gl_FragColor
=
encode_float
(
normal
.
y
);
}
else
{
}
else
{
gl_FragColor
=
encode_float
(
0.0
);
...
...
@@ -314,7 +313,7 @@
var
readWaterLevelRenderTarget
;
var
readWaterLevelImage
;
var
waterNormal
=
new
THREE
.
Vector3
();
var
NUM_SPHERES
=
5
;
var
spheres
=
[];
var
spheresEnabled
=
true
;
...
...
@@ -424,7 +423,7 @@
initWater
();
createSpheres
();
valuesChanger
();
...
...
@@ -519,7 +518,7 @@
}
);
readWaterLevelShader
.
defines
.
WIDTH
=
WIDTH
.
toFixed
(
1
);
readWaterLevelShader
.
defines
.
BOUNDS
=
BOUNDS
.
toFixed
(
1
);
// Create a 4x1 pixel image and a render target (Uint8, 4 channels, 1 byte per channel) to read water height and orientation
readWaterLevelImage
=
new
Uint8Array
(
4
*
1
*
4
);
...
...
@@ -586,7 +585,7 @@
gpuCompute
.
doRenderTarget
(
smoothShader
,
currentRenderTarget
);
}
}
function
createSpheres
()
{
...
...
@@ -602,7 +601,7 @@
sphere
.
position
.
x
=
(
Math
.
random
()
-
0.5
)
*
BOUNDS
*
0.7
;
sphere
.
position
.
z
=
(
Math
.
random
()
-
0.5
)
*
BOUNDS
*
0.7
;
sphere
.
userData
.
velocity
=
new
THREE
.
Vector3
();
scene
.
add
(
sphere
);
...
...
@@ -623,7 +622,7 @@
for
(
var
i
=
0
;
i
<
NUM_SPHERES
;
i
++
)
{
var
sphere
=
spheres
[
i
];
if
(
sphere
)
{
// Read water level and orientation
...
...
@@ -633,21 +632,21 @@
gpuCompute
.
doRenderTarget
(
readWaterLevelShader
,
readWaterLevelRenderTarget
);
gl
.
readPixels
(
0
,
0
,
4
,
1
,
gl
.
RGBA
,
gl
.
UNSIGNED_BYTE
,
readWaterLevelImage
);
var
pixels
=
new
Float32Array
(
readWaterLevelImage
.
buffer
);
// Get orientation
waterNormal
.
set
(
pixels
[
1
],
0
,
-
pixels
[
2
]
);
var
pos
=
sphere
.
position
;
// Set height
pos
.
y
=
pixels
[
0
];
// Move sphere
waterNormal
.
multiplyScalar
(
0.1
);
sphere
.
userData
.
velocity
.
add
(
waterNormal
);
sphere
.
userData
.
velocity
.
multiplyScalar
(
0.998
);
pos
.
add
(
sphere
.
userData
.
velocity
);
if
(
pos
.
x
<
-
BOUNDS_HALF
)
{
pos
.
x
=
-
BOUNDS_HALF
+
0.001
;
sphere
.
userData
.
velocity
.
x
*=
-
0.3
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录