Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
58f60e78
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,发现更多精彩内容 >>
未验证
提交
58f60e78
编写于
7月 30, 2018
作者:
M
Mr.doob
提交者:
GitHub
7月 30, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #13917 from HypnosNova/afterimage-effect
add afterimage effect
上级
251ebc87
972faecc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
265 addition
and
0 deletion
+265
-0
examples/files.js
examples/files.js
+1
-0
examples/js/postprocessing/AfterimagePass.js
examples/js/postprocessing/AfterimagePass.js
+88
-0
examples/js/shaders/AfterimageShader.js
examples/js/shaders/AfterimageShader.js
+60
-0
examples/webgl_postprocessing_afterimage.html
examples/webgl_postprocessing_afterimage.html
+116
-0
未找到文件。
examples/files.js
浏览文件 @
58f60e78
...
...
@@ -222,6 +222,7 @@ var files = {
"
webgl_points_sprites
"
,
"
webgl_postprocessing
"
,
"
webgl_postprocessing_advanced
"
,
"
webgl_postprocessing_afterimage
"
,
"
webgl_postprocessing_backgrounds
"
,
"
webgl_postprocessing_crossfade
"
,
"
webgl_postprocessing_dof
"
,
...
...
examples/js/postprocessing/AfterimagePass.js
0 → 100644
浏览文件 @
58f60e78
/**
* @author HypnosNova / https://www.threejs.org.cn/gallery/
*/
THREE
.
AfterimagePass
=
function
(
damp
)
{
THREE
.
Pass
.
call
(
this
);
if
(
THREE
.
AfterimageShader
===
undefined
)
console
.
error
(
"
THREE.AfterimagePass relies on THREE.AfterimageShader
"
);
this
.
shader
=
THREE
.
AfterimageShader
;
this
.
uniforms
=
THREE
.
UniformsUtils
.
clone
(
this
.
shader
.
uniforms
);
this
.
uniforms
[
"
damp
"
].
value
=
damp
!==
undefined
?
damp
:
0.96
;
this
.
textureComp
=
new
THREE
.
WebGLRenderTarget
(
window
.
innerWidth
,
window
.
innerHeight
,
{
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
NearestFilter
,
format
:
THREE
.
RGBAFormat
}
);
this
.
textureOld
=
new
THREE
.
WebGLRenderTarget
(
window
.
innerWidth
,
window
.
innerHeight
,
{
minFilter
:
THREE
.
LinearFilter
,
magFilter
:
THREE
.
NearestFilter
,
format
:
THREE
.
RGBAFormat
}
);
this
.
shaderMaterial
=
new
THREE
.
ShaderMaterial
(
{
uniforms
:
this
.
uniforms
,
vertexShader
:
this
.
shader
.
vertexShader
,
fragmentShader
:
this
.
shader
.
fragmentShader
}
);
this
.
sceneComp
=
new
THREE
.
Scene
();
this
.
scene
=
new
THREE
.
Scene
();
this
.
camera
=
new
THREE
.
OrthographicCamera
(
-
1
,
1
,
1
,
-
1
,
0
,
1
);
this
.
camera
.
position
.
z
=
1
;
var
geometry
=
new
THREE
.
PlaneBufferGeometry
(
2
,
2
);
this
.
quadComp
=
new
THREE
.
Mesh
(
geometry
,
this
.
shaderMaterial
);
this
.
sceneComp
.
add
(
this
.
quadComp
);
var
material
=
new
THREE
.
MeshBasicMaterial
(
{
map
:
this
.
textureComp
.
texture
}
);
var
quadScreen
=
new
THREE
.
Mesh
(
geometry
,
material
);
this
.
scene
.
add
(
quadScreen
);
};
THREE
.
AfterimagePass
.
prototype
=
Object
.
assign
(
Object
.
create
(
THREE
.
Pass
.
prototype
),
{
constructor
:
THREE
.
AfterimagePass
,
render
:
function
(
renderer
,
writeBuffer
,
readBuffer
)
{
this
.
uniforms
[
"
tOld
"
].
value
=
this
.
textureOld
.
texture
;
this
.
uniforms
[
"
tNew
"
].
value
=
readBuffer
.
texture
;
this
.
quadComp
.
material
=
this
.
shaderMaterial
;
renderer
.
render
(
this
.
sceneComp
,
this
.
camera
,
this
.
textureComp
);
renderer
.
render
(
this
.
scene
,
this
.
camera
,
this
.
textureOld
);
if
(
this
.
renderToScreen
)
{
renderer
.
render
(
this
.
scene
,
this
.
camera
);
}
else
{
renderer
.
render
(
this
.
scene
,
this
.
camera
,
writeBuffer
,
this
.
clear
);
}
}
}
);
examples/js/shaders/AfterimageShader.js
0 → 100644
浏览文件 @
58f60e78
/**
* @author HypnosNova / https://www.threejs.org.cn/gallery/
*
* Afterimage shader
* I created this effect inspired by a demo on codepen:
* https://codepen.io/brunoimbrizi/pen/MoRJaN?page=1&
*/
THREE
.
AfterimageShader
=
{
uniforms
:
{
"
damp
"
:
{
value
:
0.96
},
"
tOld
"
:
{
value
:
null
},
"
tNew
"
:
{
value
:
null
}
},
vertexShader
:
[
"
varying vec2 vUv;
"
,
"
void main() {
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
fragmentShader
:
[
"
uniform float damp;
"
,
"
uniform sampler2D tOld;
"
,
"
uniform sampler2D tNew;
"
,
"
varying vec2 vUv;
"
,
"
vec4 when_gt( vec4 x, float y ) {
"
,
"
return max( sign( x - y ), 0.0 );
"
,
"
}
"
,
"
void main() {
"
,
"
vec4 texelOld = texture2D( tOld, vUv );
"
,
"
vec4 texelNew = texture2D( tNew, vUv );
"
,
"
texelOld *= damp * when_gt( texelOld, 0.1 );
"
,
"
gl_FragColor = max(texelNew, texelOld);
"
,
"
}
"
].
join
(
"
\n
"
)
};
examples/webgl_postprocessing_afterimage.html
0 → 100644
浏览文件 @
58f60e78
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - postprocessing - afterimage
</title>
<meta
charset=
"utf-8"
>
<meta
name=
"viewport"
content=
"width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"
>
<style>
body
{
margin
:
0px
;
background-color
:
#000000
;
overflow
:
hidden
;
}
</style>
</head>
<body>
<script
src=
"../build/three.js"
></script>
<script
src=
"js/shaders/CopyShader.js"
></script>
<script
src=
"js/shaders/AfterimageShader.js"
></script>
<script
src=
"js/postprocessing/EffectComposer.js"
></script>
<script
src=
"js/postprocessing/RenderPass.js"
></script>
<script
src=
"js/postprocessing/MaskPass.js"
></script>
<script
src=
"js/postprocessing/ShaderPass.js"
></script>
<script
src=
"js/postprocessing/AfterimagePass.js"
></script>
<script
src=
"js/libs/dat.gui.min.js"
type=
"text/javascript"
charset=
"utf-8"
></script>
<script>
var
camera
,
scene
,
renderer
,
composer
;
var
mesh
,
light
;
var
afterimagePass
,
enable
=
true
;
init
();
createGUI
();
animate
();
function
init
()
{
renderer
=
new
THREE
.
WebGLRenderer
();
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
document
.
body
.
appendChild
(
renderer
.
domElement
);
camera
=
new
THREE
.
PerspectiveCamera
(
70
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
1000
);
camera
.
position
.
z
=
400
;
scene
=
new
THREE
.
Scene
();
scene
.
fog
=
new
THREE
.
Fog
(
0x000000
,
1
,
1000
);
object
=
new
THREE
.
Object3D
();
scene
.
add
(
object
);
var
geometry
=
new
THREE
.
BoxBufferGeometry
(
150
,
150
,
150
,
2
,
2
,
2
);
var
material
=
new
THREE
.
MeshNormalMaterial
();
mesh
=
new
THREE
.
Mesh
(
geometry
,
material
);
scene
.
add
(
mesh
);
// postprocessing
composer
=
new
THREE
.
EffectComposer
(
renderer
);
composer
.
addPass
(
new
THREE
.
RenderPass
(
scene
,
camera
)
);
afterimagePass
=
new
THREE
.
AfterimagePass
();
afterimagePass
.
renderToScreen
=
true
;
composer
.
addPass
(
afterimagePass
);
window
.
addEventListener
(
'
resize
'
,
onWindowResize
,
false
);
}
function
createGUI
(){
var
gui
=
new
dat
.
GUI
(
{
name
:
'
Damp setting
'
}
);
gui
.
add
(
afterimagePass
.
uniforms
[
"
damp
"
],
'
value
'
,
0
,
1
).
step
(
0.001
);
gui
.
add
(
this
,
'
enable
'
);
}
function
onWindowResize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
composer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
}
function
animate
()
{
requestAnimationFrame
(
animate
);
var
time
=
Date
.
now
();
mesh
.
rotation
.
x
+=
0.005
;
mesh
.
rotation
.
y
+=
0.01
;
if
(
enable
){
composer
.
render
();
}
else
{
renderer
.
render
(
scene
,
camera
);
}
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录