Skip to content

Commit e8a0d7c

Browse files
committed
Adding 3 Shaders
Adding Kaleidoscope, Mirror and RGBShift Shaders.
1 parent b63ad21 commit e8a0d7c

3 files changed

Lines changed: 174 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* @author felixturner / http://airtight.cc/
3+
*
4+
* Kaleidoscope Shader
5+
* Radial reflection around center point
6+
* Ported from: http://pixelshaders.com/editor/
7+
* by Toby Schachman / http://tobyschachman.com/
8+
*
9+
* sides: number of reflections
10+
* angle: initial angle in radians
11+
*/
12+
13+
THREE.KaleidoShader = {
14+
15+
uniforms: {
16+
17+
"tDiffuse": { type: "t", value: null },
18+
"sides": { type: "f", value: 6.0 },
19+
"angle": { type: "f", value: 0.0 }
20+
21+
},
22+
23+
vertexShader: [
24+
25+
"varying vec2 vUv;",
26+
27+
"void main() {",
28+
29+
"vUv = uv;",
30+
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
31+
32+
"}"
33+
34+
].join("\n"),
35+
36+
fragmentShader: [
37+
38+
"uniform sampler2D tDiffuse;",
39+
"uniform float sides;",
40+
"uniform float angle;",
41+
42+
"varying vec2 vUv;",
43+
44+
"void main() {",
45+
46+
"vec2 p = vUv - 0.5;",
47+
"float r = length(p);",
48+
"float a = atan(p.y, p.x) + angle;",
49+
"float tau = 2. * 3.1416 ;",
50+
"a = mod(a, tau/sides);",
51+
"a = abs(a - tau/sides/2.) ;",
52+
"p = r * vec2(cos(a), sin(a));",
53+
"vec4 color = texture2D(tDiffuse, p + 0.5);",
54+
"gl_FragColor = color;",
55+
56+
"}"
57+
58+
].join("\n")
59+
60+
};
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @author felixturner / http://airtight.cc/
3+
*
4+
* Mirror Shader
5+
* Copies half the input to the other half
6+
*
7+
* side: side of input to mirror (0 = left, 1 = right, 2 = top, 3 = bottom)
8+
*/
9+
10+
THREE.MirrorShader = {
11+
12+
uniforms: {
13+
14+
"tDiffuse": { type: "t", value: null },
15+
"side": { type: "i", value: 1 }
16+
17+
},
18+
19+
vertexShader: [
20+
21+
"varying vec2 vUv;",
22+
23+
"void main() {",
24+
25+
"vUv = uv;",
26+
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
27+
28+
"}"
29+
30+
].join("\n"),
31+
32+
fragmentShader: [
33+
34+
"uniform sampler2D tDiffuse;",
35+
"uniform int side;",
36+
37+
"varying vec2 vUv;",
38+
39+
"void main() {",
40+
41+
"vec2 p = vUv;",
42+
"if (side == 0){",
43+
"if (p.x > 0.5) p.x = 1.0 - p.x;",
44+
"}else if (side == 1){",
45+
"if (p.x < 0.5) p.x = 1.0 - p.x;",
46+
"}else if (side == 2){",
47+
"if (p.y < 0.5) p.y = 1.0 - p.y;",
48+
"}else if (side == 3){",
49+
"if (p.y > 0.5) p.y = 1.0 - p.y;",
50+
"} ",
51+
"vec4 color = texture2D(tDiffuse, p);",
52+
"gl_FragColor = color;",
53+
54+
"}"
55+
56+
].join("\n")
57+
58+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @author felixturner / http://airtight.cc/
3+
*
4+
* RGB Shift Shader
5+
* Shifts red and blue channels from center in opposite directions
6+
* Ported from http://kriss.cx/tom/2009/05/rgb-shift/
7+
* by Tom Butterworth / http://kriss.cx/tom/
8+
*
9+
* amount: shift distance (1 is width of input)
10+
* angle: shift angle in radians
11+
*/
12+
13+
THREE.RGBShiftShader = {
14+
15+
uniforms: {
16+
17+
"tDiffuse": { type: "t", value: null },
18+
"amount": { type: "f", value: 0.005 },
19+
"angle": { type: "f", value: 0.0 }
20+
21+
},
22+
23+
vertexShader: [
24+
25+
"varying vec2 vUv;",
26+
27+
"void main() {",
28+
29+
"vUv = uv;",
30+
"gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
31+
32+
"}"
33+
34+
].join("\n"),
35+
36+
fragmentShader: [
37+
38+
"uniform sampler2D tDiffuse;",
39+
"uniform float amount;",
40+
"uniform float angle;",
41+
42+
"varying vec2 vUv;",
43+
44+
"void main() {",
45+
46+
"vec2 offset = amount * vec2( cos(angle), sin(angle));",
47+
"vec4 cr = texture2D(tDiffuse, vUv + offset);",
48+
"vec4 cga = texture2D(tDiffuse, vUv);",
49+
"vec4 cb = texture2D(tDiffuse, vUv - offset);",
50+
"gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);",
51+
52+
"}"
53+
54+
].join("\n")
55+
56+
};

0 commit comments

Comments
 (0)