Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
8d3cae2f
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,发现更多精彩内容 >>
提交
8d3cae2f
编写于
10月 04, 2018
作者:
Y
yomboprime
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Changed water reset feedback to sample 1 point
上级
125e2d5a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
26 addition
and
25 deletion
+26
-25
examples/webgl_gpgpu_water.html
examples/webgl_gpgpu_water.html
+26
-25
未找到文件。
examples/webgl_gpgpu_water.html
浏览文件 @
8d3cae2f
...
@@ -127,7 +127,7 @@
...
@@ -127,7 +127,7 @@
</script>
</script>
<!-- This is a 'compute shader' to calculate the current volume of water -->
<!-- This is a 'compute shader' to calculate the current volume of water
at the center
-->
<!-- It is used with a variable of size 1x1 -->
<!-- It is used with a variable of size 1x1 -->
<script
id=
"sumFragmentShader"
type=
"x-shader/x-fragment"
>
<script
id=
"sumFragmentShader"
type=
"x-shader/x-fragment"
>
...
@@ -136,19 +136,31 @@
...
@@ -136,19 +136,31 @@
// Integer to float conversion from https://stackoverflow.com/questions/17981163/webgl-read-pixels-from-floating-point-render-target
// 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
)
{
float
shift_right
(
float
v
,
float
amt
)
{
v
=
floor
(
v
)
+
0.5
;
v
=
floor
(
v
)
+
0.5
;
return
floor
(
v
/
exp2
(
amt
)
);
return
floor
(
v
/
exp2
(
amt
)
);
}
}
float
shift_left
(
float
v
,
float
amt
)
{
float
shift_left
(
float
v
,
float
amt
)
{
return
floor
(
v
*
exp2
(
amt
)
+
0.5
);
return
floor
(
v
*
exp2
(
amt
)
+
0.5
);
}
}
float
mask_last
(
float
v
,
float
bits
)
{
float
mask_last
(
float
v
,
float
bits
)
{
return
mod
(
v
,
shift_left
(
1.0
,
bits
)
);
return
mod
(
v
,
shift_left
(
1.0
,
bits
)
);
}
}
float
extract_bits
(
float
num
,
float
from
,
float
to
)
{
float
extract_bits
(
float
num
,
float
from
,
float
to
)
{
from
=
floor
(
from
+
0.5
);
to
=
floor
(
to
+
0.5
);
from
=
floor
(
from
+
0.5
);
to
=
floor
(
to
+
0.5
);
return
mask_last
(
shift_right
(
num
,
from
),
to
-
from
);
return
mask_last
(
shift_right
(
num
,
from
),
to
-
from
);
}
}
vec4
encode_float
(
float
val
)
{
vec4
encode_float
(
float
val
)
{
if
(
val
==
0.0
)
return
vec4
(
0
,
0
,
0
,
0
);
if
(
val
==
0.0
)
return
vec4
(
0
,
0
,
0
,
0
);
float
sign
=
val
>
0.0
?
0.0
:
1.0
;
float
sign
=
val
>
0.0
?
0.0
:
1.0
;
...
@@ -168,26 +180,9 @@
...
@@ -168,26 +180,9 @@
void
main
()
{
void
main
()
{
vec2
cellSize
=
1.0
/
resolution
.
xy
;
float
waterLevel
=
texture2D
(
texture
,
vec2
(
0.5
,
0.5
)
).
x
;
float
volume
=
0.0
;
const
int
rx
=
int
(
resolution
.
x
);
const
int
ry
=
int
(
resolution
.
y
);
// Sum of water height over all water cells
for
(
int
j
=
0
;
j
<
ry
;
j
++
)
{
for
(
int
i
=
0
;
i
<
rx
;
i
++
)
{
vec2
uv
=
vec2
(
i
,
j
)
*
cellSize
;
vec4
textureValue
=
texture2D
(
texture
,
uv
);
volume
+=
textureValue
.
x
;
}
}
gl_FragColor
=
encode_float
(
volume
);
gl_FragColor
=
encode_float
(
waterLevel
);
}
}
...
@@ -559,7 +554,7 @@
...
@@ -559,7 +554,7 @@
function
readWaterLevel
()
{
function
readWaterLevel
()
{
// Returns current
average water level
// Returns current
water level at the center
var
currentRenderTarget
=
gpuCompute
.
getCurrentRenderTarget
(
heightmapVariable
);
var
currentRenderTarget
=
gpuCompute
.
getCurrentRenderTarget
(
heightmapVariable
);
...
@@ -572,7 +567,7 @@
...
@@ -572,7 +567,7 @@
var
pixels
=
new
Float32Array
(
readVolumeImage
.
buffer
);
var
pixels
=
new
Float32Array
(
readVolumeImage
.
buffer
);
return
pixels
[
0
]
/
NUM_TEXELS
;
return
pixels
[
0
];
}
}
...
@@ -667,18 +662,24 @@
...
@@ -667,18 +662,24 @@
numFrames
=
0
;
numFrames
=
0
;
heightCompensation
=
readWaterLevel
();
heightCompensation
=
-
readWaterLevel
();
}
}
// Apply gradually height compensation to reset water level
// Apply gradually height compensation to reset water level
if
(
heightCompensation
!==
0
)
{
if
(
heightCompensation
!==
0
)
{
var
decremHeight
=
Math
.
min
(
1
,
Math
.
abs
(
heightCompensation
)
)
*
Math
.
sign
(
heightCompensation
);
var
decremHeight
=
Math
.
min
(
0.2
,
Math
.
abs
(
heightCompensation
)
)
*
Math
.
sign
(
heightCompensation
);
heightCompensation
-=
decremHeight
;
heightCompensation
-=
decremHeight
;
heightmapVariable
.
material
.
uniforms
.
heightCompensation
.
value
=
-
decremHeight
*
Math
.
sign
(
heightCompensation
)
;
heightmapVariable
.
material
.
uniforms
.
heightCompensation
.
value
=
decremHeight
;
}
}
else
{
heightmapVariable
.
material
.
uniforms
.
heightCompensation
.
value
=
0
;
}
// Do the gpu computation
// Do the gpu computation
gpuCompute
.
compute
();
gpuCompute
.
compute
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录