[b86468]: / v3 / js / libs / three / shaders / PixelShader.js

Download this file

48 lines (30 with data), 730 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @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" )
};