Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
车家大少爷
three.js
提交
8e974ee3
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,发现更多精彩内容 >>
未验证
提交
8e974ee3
编写于
12月 27, 2017
作者:
M
Mr.doob
提交者:
GitHub
12月 27, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12932 from wongbryan/pixel-shader
Pixelation shader w/ example
上级
92dacdcc
b04eed4c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
244 addition
and
0 deletion
+244
-0
examples/js/shaders/PixelShader.js
examples/js/shaders/PixelShader.js
+47
-0
examples/webgl_postprocessing_pixel.html
examples/webgl_postprocessing_pixel.html
+197
-0
未找到文件。
examples/js/shaders/PixelShader.js
0 → 100644
浏览文件 @
8e974ee3
/**
* @author wongbryan / http://wongbryan.github.io
*
* Pixelation shader
*/
THREE
.
PixelShader
=
{
uniforms
:
{
"
tDiffuse
"
:
{
value
:
null
},
"
resolution
"
:
{
value
:
null
},
"
pixelSize
"
:
{
value
:
1
.
},
},
vertexShader
:
[
"
varying highp vec2 vUv;
"
,
"
void main() {
"
,
"
vUv = uv;
"
,
"
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
"
,
"
}
"
].
join
(
"
\n
"
),
fragmentShader
:
[
"
uniform sampler2D tDiffuse;
"
,
"
uniform float pixelSize;
"
,
"
uniform vec2 resolution;
"
,
"
varying highp vec2 vUv;
"
,
"
void main(){
"
,
"
vec2 dxy = pixelSize / resolution;
"
,
"
vec2 coord = dxy * floor( vUv / dxy );
"
,
"
gl_FragColor = texture2D(tDiffuse, coord);
"
,
"
}
"
].
join
(
"
\n
"
)
};
examples/webgl_postprocessing_pixel.html
0 → 100644
浏览文件 @
8e974ee3
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<title>
three.js webgl - postprocessing - pixel shader
</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
{
background-color
:
#000000
;
margin
:
0px
;
overflow
:
hidden
;
font-family
:
Monospace
;
font-size
:
13px
;
/*text-align:center;*/
font-weight
:
lighter
;
}
a
{
color
:
gray
;
font-weight
:
bold
;
}
#info
{
color
:
gray
;
position
:
absolute
;
bottom
:
0px
;
width
:
100%
;
padding
:
15px
;
}
.dg.ac
{
z-index
:
1
!important
;
}
</style>
</head>
<body>
<script
src=
"../build/three.js"
></script>
<script
src=
"js/shaders/CopyShader.js"
></script>
<script
src=
"js/shaders/PixelShader.js"
></script>
<script
src=
"js/postprocessing/EffectComposer.js"
></script>
<script
src=
"js/postprocessing/RenderPass.js"
></script>
<script
src=
"js/postprocessing/ShaderPass.js"
></script>
<script
src=
"js/controls/TrackballControls.js"
></script>
<script
src=
'js/libs/dat.gui.min.js'
></script>
<div
id=
"container"
></div>
<div
id=
"info"
>
<a
href=
"http://threejs.org"
target=
"_blank"
rel=
"noopener"
>
three.js
</a>
- pixel shader example
<br/>
shader by
<a
href=
"http://wongbryan.github.io"
>
wongbryan
</a>
</div>
<script>
var
camera
,
scene
,
renderer
,
gui
,
composer
;
var
pixelPass
,
params
;
var
geomData
=
[],
group
;
init
();
animate
();
function
updateGUI
()
{
pixelPass
.
uniforms
.
pixelSize
.
value
=
params
.
pixelSize
;
}
function
resize
()
{
camera
.
aspect
=
window
.
innerWidth
/
window
.
innerHeight
;
camera
.
updateProjectionMatrix
();
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
pixelPass
.
uniforms
.
resolution
.
value
.
set
(
window
.
innerWidth
,
window
.
innerHeight
).
multiplyScalar
(
window
.
devicePixelRatio
);
}
function
init
()
{
var
container
=
document
.
getElementById
(
'
container
'
);
renderer
=
new
THREE
.
WebGLRenderer
(
{
antialias
:
true
}
);
renderer
.
setPixelRatio
(
window
.
devicePixelRatio
);
renderer
.
setSize
(
window
.
innerWidth
,
window
.
innerHeight
);
renderer
.
setClearColor
(
0xbfe7ff
);
container
.
appendChild
(
renderer
.
domElement
);
camera
=
new
THREE
.
PerspectiveCamera
(
75
,
window
.
innerWidth
/
window
.
innerHeight
,
1
,
10000
);
camera
.
position
.
set
(
0
,
0
,
30
);
controls
=
new
THREE
.
TrackballControls
(
camera
,
renderer
.
domElement
);
controls
.
rotateSpeed
=
2.0
;
controls
.
panSpeed
=
0.8
;
controls
.
zoomSpeed
=
1.5
;
scene
=
new
THREE
.
Scene
();
var
hemisphereLight
=
new
THREE
.
HemisphereLight
(
0xfceafc
,
0x000000
,
.
8
);
scene
.
add
(
hemisphereLight
);
var
dirLight
=
new
THREE
.
DirectionalLight
(
0xffffff
,
.
5
);
dirLight
.
position
.
set
(
150
,
75
,
150
);
scene
.
add
(
dirLight
);
var
dirLight2
=
new
THREE
.
DirectionalLight
(
0xffffff
,
.
2
);
dirLight2
.
position
.
set
(
-
150
,
75
,
-
150
);
scene
.
add
(
dirLight2
);
var
dirLight3
=
new
THREE
.
DirectionalLight
(
0xffffff
,
.
1
);
dirLight3
.
position
.
set
(
0
,
125
,
0
);
scene
.
add
(
dirLight3
);
scene
.
add
(
hemisphereLight
);
scene
.
add
(
dirLight
);
scene
.
add
(
dirLight2
);
scene
.
add
(
dirLight3
);
geomData
.
push
(
new
THREE
.
SphereGeometry
(
1
,
64
,
64
)
);
geomData
.
push
(
new
THREE
.
BoxGeometry
(
1
,
1
,
1
)
);
geomData
.
push
(
new
THREE
.
ConeGeometry
(
1
,
1
,
32
)
);
geomData
.
push
(
new
THREE
.
TetrahedronGeometry
(
1
)
);
geomData
.
push
(
new
THREE
.
TorusKnotGeometry
(
1
,
.
4
)
);
var
numShapes
=
25
;
group
=
new
THREE
.
Group
();
for
(
var
i
=
0
;
i
<
numShapes
;
i
++
)
{
var
geom
=
geomData
[
Math
.
floor
(
Math
.
random
()
*
geomData
.
length
)
];
var
color
=
new
THREE
.
Color
();
color
.
setHSL
(
Math
.
random
(),
.
7
+
.
2
*
Math
.
random
(),
.
5
+
.
1
*
Math
.
random
()
);
var
mat
=
new
THREE
.
MeshPhongMaterial
(
{
color
:
color
,
shininess
:
200
}
);
var
mesh
=
new
THREE
.
Mesh
(
geom
,
mat
);
var
s
=
4
+
Math
.
random
()
*
10
;
mesh
.
scale
.
set
(
s
,
s
,
s
);
mesh
.
position
.
set
(
Math
.
random
()
-
0.5
,
Math
.
random
()
-
0.5
,
Math
.
random
()
-
0.5
).
normalize
();
mesh
.
position
.
multiplyScalar
(
Math
.
random
()
*
200
);
mesh
.
rotation
.
set
(
Math
.
random
()
*
2
,
Math
.
random
()
*
2
,
Math
.
random
()
*
2
);
group
.
add
(
mesh
);
}
scene
.
add
(
group
);
composer
=
new
THREE
.
EffectComposer
(
renderer
);
composer
.
addPass
(
new
THREE
.
RenderPass
(
scene
,
camera
)
);
pixelPass
=
new
THREE
.
ShaderPass
(
THREE
.
PixelShader
);
pixelPass
.
uniforms
.
resolution
.
value
=
new
THREE
.
Vector2
(
window
.
innerWidth
,
window
.
innerHeight
);
pixelPass
.
uniforms
.
resolution
.
value
.
multiplyScalar
(
window
.
devicePixelRatio
);
pixelPass
.
renderToScreen
=
true
;
composer
.
addPass
(
pixelPass
);
window
.
addEventListener
(
'
resize
'
,
resize
);
params
=
{
pixelSize
:
128
,
postprocessing
:
true
};
gui
=
new
dat
.
GUI
();
gui
.
add
(
params
,
'
pixelSize
'
).
min
(
2
).
max
(
256
).
step
(
2
);
gui
.
add
(
params
,
'
postprocessing
'
);
}
function
update
()
{
controls
.
update
();
updateGUI
();
group
.
rotation
.
y
+=
.
0015
;
group
.
rotation
.
z
+=
.
001
;
}
function
animate
()
{
update
();
if
(
params
.
postprocessing
)
{
composer
.
render
();
}
else
{
renderer
.
render
(
scene
,
camera
);
}
window
.
requestAnimationFrame
(
animate
);
}
</script>
</body>
</html>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录