Skip to content

Commit a7d6c38

Browse files
Eugene KoganEugene Kogan
authored andcommitted
added inversion filter
1 parent 07e8c06 commit a7d6c38

File tree

2 files changed

+77
-60
lines changed

2 files changed

+77
-60
lines changed

TextureShaders/TextureShaders.pde

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import processing.video.*;
22

3-
String[] shaders = new String[]{
4-
"wrap.glsl", "deform.glsl", "pixelrolls.glsl", "patches.glsl",
3+
String[] shaders = new String[] {
54
"brcosa.glsl", "hue.glsl", "pixelate.glsl", "blur.glsl",
6-
"channels.glsl", "threshold.glsl", "neon.glsl", "edges.glsl",
7-
"modcolor.glsl", "halftone.glsl" };
5+
"channels.glsl", "threshold.glsl", "neon.glsl", "edges.glsl",
6+
"wrap.glsl", "deform.glsl", "pixelrolls.glsl", "patches.glsl",
7+
"modcolor.glsl", "halftone.glsl", "invert.glsl"};
88

99
PShader shade;
1010
PImage img1, img2, img3;
1111
Movie mov;
1212

13-
// shaders
14-
// - inversion
15-
// - more?
16-
1713
int idxSource = 0;
1814
int idxShader = 0;
1915

@@ -22,7 +18,7 @@ void setup()
2218
size(640, 480, P2D);
2319
textSize(22);
2420
fill(0);
25-
21+
2622
// load sources
2723
img1 = loadImage("hummingbird.jpg");
2824
img2 = loadImage("fruit-stand.jpg");
@@ -35,14 +31,14 @@ void setup()
3531
void draw()
3632
{
3733
setShaderParameters();
38-
34+
3935
// turn on shader and display source
4036
shader(shade);
4137
if (idxSource == 0) image(img1, 0, 0, width, height);
4238
else if (idxSource == 1) image(img2, 0, 0, width, height);
4339
else if (idxSource == 2) image(img3, 0, 0, width, height);
4440
else if (idxSource == 3) image(mov, 0, 0, width, height);
45-
41+
4642
// turn off shader before displaying filename
4743
resetShader();
4844
text(shaders[idxShader], 5, 20);
@@ -51,104 +47,109 @@ void draw()
5147
void setupShader()
5248
{
5349
shade = loadShader(shaders[idxShader]);
54-
50+
5551
// shader 3 works better on paused movie
5652
if (idxShader == 3) {
5753
mov.pause();
58-
} else {
54+
}
55+
else {
5956
mov.loop();
6057
}
6158
}
6259

6360
void setShaderParameters()
6461
{
65-
// wrap
66-
if (idxShader == 0) {
67-
shade.set("radius", map(mouseX, 0, width, 0, 2));
68-
shade.set("radTwist", map(mouseY, 0, height, 1.0, 10));
69-
}
70-
71-
// deform
72-
else if (idxShader == 1) {
73-
shade.set("time", (float) millis()/1000.0);
74-
shade.set("mouse", (float) mouseX/width, (float) mouseY/height);
75-
shade.set("turns", map(sin(0.01*frameCount), -1, 1, 2.0, 10.0));
76-
}
77-
78-
// pixelRolls
79-
else if (idxShader == 2) {
80-
shade.set("time", (float) millis()/1000.0);
81-
shade.set("pixels", mouseX/5, 250.0);
82-
shade.set("rollRate", map(mouseY, 0, height, 0, 10.0));
83-
shade.set("rollAmount", 0.25);
84-
}
85-
86-
// patches
87-
else if (idxShader == 3) {
88-
shade.set("time", (float) millis()/1000.0);
89-
shade.set("row", map(mouseX, 0, width, 0, 1));
90-
shade.set("col", map(mouseY, 0, height, 0, 1));
91-
}
92-
9362
// brcosa
94-
else if (idxShader == 4) {
63+
if (idxShader == 0) {
9564
shade.set("brightness", 1.0);
9665
shade.set("contrast", map(mouseX, 0, width, -5, 5));
9766
shade.set("saturation", map(mouseY, 0, height, -5, 5));
9867
}
9968

10069
// hue
101-
else if (idxShader == 5) {
70+
else if (idxShader == 1) {
10271
shade.set("hue", map(mouseX, 0, width, 0, TWO_PI));
10372
}
10473

10574
// pixelate
106-
else if (idxShader == 6) {
75+
else if (idxShader == 2) {
10776
shade.set("pixels", 0.1 * mouseX, 0.1 * mouseY);
10877
}
109-
78+
11079
// blur
111-
else if (idxShader == 7) {
80+
else if (idxShader == 3) {
11281
shade.set("sigma", map(mouseX, 0, width, 0, 10.0));
11382
shade.set("blurSize", (int) map(mouseY, 0, height, 0, 30.0));
11483
shade.set("texOffset", 1.0, 1.0);
11584
}
116-
85+
11786
// channels
118-
else if (idxShader == 8) {
87+
else if (idxShader == 4) {
11988
shade.set("rbias", 0.0, 0.0);
12089
shade.set("gbias", map(mouseY, 0, height, -0.2, 0.2), 0.0);
12190
shade.set("bbias", 0.0, 0.0);
12291
shade.set("rmult", map(mouseX, 0, width, 0.8, 1.5), 1.0);
12392
shade.set("gmult", 1.0, 1.0);
12493
shade.set("bmult", 1.0, 1.0);
12594
}
126-
127-
// edges
128-
else if (idxShader == 9) {
129-
shade.set("threshold", map(mouseX, 0, width, 0, 1));
130-
}
13195

96+
// threshold
97+
else if (idxShader == 5) {
98+
shade.set("threshold", map(mouseX, 0, width, 0, 1));
99+
}
100+
132101
// neon
133-
else if (idxShader == 10) {
102+
else if (idxShader == 6) {
134103
shade.set("brt", map(mouseX, 0, width, 0, 0.5));
135-
shade.set("rad", (int) map(mouseY, 0, height, 0, 3));
104+
shade.set("rad", (int) map(mouseY, 0, height, 0, 3));
136105
}
137-
106+
138107
// edges (no parameters)
139-
108+
else if (idxShader == 7) {
109+
}
110+
111+
// wrap
112+
else if (idxShader == 8) {
113+
shade.set("radius", map(mouseX, 0, width, 0, 2));
114+
shade.set("radTwist", map(mouseY, 0, height, 1.0, 10));
115+
}
116+
117+
// deform
118+
else if (idxShader == 9) {
119+
shade.set("time", (float) millis()/1000.0);
120+
shade.set("mouse", (float) mouseX/width, (float) mouseY/height);
121+
shade.set("turns", map(sin(0.01*frameCount), -1, 1, 2.0, 10.0));
122+
}
123+
124+
// pixelRolls
125+
else if (idxShader == 10) {
126+
shade.set("time", (float) millis()/1000.0);
127+
shade.set("pixels", mouseX/5, 250.0);
128+
shade.set("rollRate", map(mouseY, 0, height, 0, 10.0));
129+
shade.set("rollAmount", 0.25);
130+
}
131+
132+
// patches
133+
else if (idxShader == 11) {
134+
shade.set("row", map(mouseX, 0, width, 0, 1));
135+
shade.set("col", map(mouseY, 0, height, 0, 1));
136+
}
137+
140138
// modcolor
141139
else if (idxShader == 12) {
142140
shade.set("modr", map(mouseX, 0, width, 0, 0.5));
143141
shade.set("modg", 0.3);
144142
shade.set("modb", map(mouseY, 0, height, 0, 0.5));
145143
}
146-
144+
147145
// halftone
148146
else if (idxShader == 13) {
149147
shade.set("pixelsPerRow", (int) map(mouseX, 0, width, 2, 100));
150148
}
151-
149+
150+
// inversion (no parameters)
151+
else if (idxShader == 14) {
152+
}
152153
}
153154

154155
void keyPressed() {
@@ -167,7 +168,7 @@ void keyPressed() {
167168
idxSource = (idxSource + 1) % 4;
168169
}
169170
}
170-
171+
171172
void movieEvent(Movie m) {
172173
m.read();
173174
}

TextureShaders/data/invert.glsl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifdef GL_ES
2+
precision mediump float;
3+
precision mediump int;
4+
#endif
5+
6+
#define PROCESSING_TEXTURE_SHADER
7+
8+
varying vec4 vertTexCoord;
9+
uniform sampler2D texture;
10+
11+
void main(void)
12+
{
13+
vec2 p = vertTexCoord.st;
14+
vec3 col = vec3(1.0) - texture2D(texture, p).rgb;
15+
gl_FragColor = vec4(col, 1.0);
16+
}

0 commit comments

Comments
 (0)