File: MirrorShader.js

package info (click to toggle)
three.js 111%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,184 kB
  • sloc: javascript: 133,174; makefile: 24; sh: 1
file content (62 lines) | stat: -rw-r--r-- 1,015 bytes parent folder | download | duplicates (2)
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
59
60
61
62
/**
 * @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)
 */



var 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" )

};

export { MirrorShader };