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

Download this file

59 lines (40 with data), 995 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
48
49
50
51
52
53
54
55
56
57
58
/**
* @author felixturner / http://airtight.cc/
*
* Mirror Shader
* Copies half the input to the other half
*
* side: side of input to mirror (0 = left, 1 = right, 2 = top, 3 = bottom)
*/
THREE.MirrorShader = {
uniforms: {
"tDiffuse": { value: null },
"side": { value: 1 }
},
vertexShader: [
"varying vec2 vUv;",
"void main() {",
"vUv = uv;",
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
"}"
].join( "\n" ),
fragmentShader: [
"uniform sampler2D tDiffuse;",
"uniform int side;",
"varying vec2 vUv;",
"void main() {",
"vec2 p = vUv;",
"if (side == 0){",
"if (p.x > 0.5) p.x = 1.0 - p.x;",
"}else if (side == 1){",
"if (p.x < 0.5) p.x = 1.0 - p.x;",
"}else if (side == 2){",
"if (p.y < 0.5) p.y = 1.0 - p.y;",
"}else if (side == 3){",
"if (p.y > 0.5) p.y = 1.0 - p.y;",
"} ",
"vec4 color = texture2D(tDiffuse, p);",
"gl_FragColor = color;",
"}"
].join( "\n" )
};