Skip to content

Instantly share code, notes, and snippets.

@genekogan
Created July 18, 2016 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save genekogan/e5072dc842b41f7126bab04dec7186a5 to your computer and use it in GitHub Desktop.
Save genekogan/e5072dc842b41f7126bab04dec7186a5 to your computer and use it in GitHub Desktop.
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 resolution;
uniform float time;
uniform vec4 m;
void main(void) {
vec2 p = gl_FragCoord.xy / resolution.xy;
p.x -= mod(p.x, m.x);
p.y -= mod(p.y, m.y);
p.y = mod(p.y + m.z*sin(m.a * time * p.x + p.x), 1.0);
p.y = 1.0-p.y;
float r = texture2D(texture, p).r;
float g = texture2D(texture, p).g;
float b = texture2D(texture, p).b;
gl_FragColor = vec4(r, g, b, 1.0);
}
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform sampler2D texture;
uniform vec2 resolution;
uniform float time;
uniform vec3 m;
void main(void) {
vec2 p = gl_FragCoord.xy / resolution.xy;
vec2 p1 = vec2(p.x, mod(time*m.x, 1.0));
vec2 p2 = vec2(mod(time*m.y, 1.0), p.y);
float mode = floor(m.z);
float rx = texture2D(texture, p1).r;
float ry = texture2D(texture, p2).r;
float gx = texture2D(texture, p1).g;
float gy = texture2D(texture, p2).g;
float bx = texture2D(texture, p1).b;
float by = texture2D(texture, p2).b;
float r, g, b;
if (mode==0.0) {
r = rx * ry;
g = gx * gy;
b = bx * by;
} else if (mode==1.0) {
r = rx * ry;
g = gx * by;
b = bx * gy;
} else if (mode==2.0) {
r = rx * gy;
g = gx * ry;
b = bx * by;
} else if (mode==3.0) {
r = rx * gy;
g = gx * by;
b = bx * ry;
} else if (mode==4.0) {
r = rx * by;
g = gx * ry;
b = bx * gy;
} else if (mode==5.0) {
r = rx * by;
g = gx * gy;
b = bx * ry;
} else if (mode==6.0) {
r = 0.3333333 * (rx*ry + gx*gy + bx*by);
g = r;
b = r;
}
gl_FragColor = vec4(r, g, b, 1.0);
}
// you need to put the glsl files into the sketch's data folder
String[] shaders = new String[] {
"vert1.glsl", "vert2.glsl", "wrap.glsl" };
PGraphics pg;
PImage img;
PShader myShader;
int idx, nextIdx;
boolean isImage = true;
import oscP5.*;
import netP5.*;
OscP5 oscP5;
void setup() {
size(828, 648, P2D);
textureWrap(REPEAT);
oscP5 = new OscP5(this,12000);
idx = 0;
nextIdx = 0;
setupShader(idx);
// load image
img = loadImage("/Users/gene/Desktop/discoball/DSC_0228.JPG");
// create pgraphics
pg = createGraphics(width, height, P2D);
pg.beginDraw();
pg.background(0, 255, 0);
for (int i=0; i<100; i++) {
pg.fill(random(255), random(255), random(255));
pg.ellipse(random(pg.width), random(pg.height), 100, 100);
}
pg.endDraw();
}
void draw() {
if (nextIdx != idx) {
idx = nextIdx;
setupShader(idx);
}
setShaderParameters();
if (isImage) image(img, 0, 0, width, height);
else image(pg, 0, 0, width, height);
}
void setupShader(int idx) {
myShader = loadShader(shaders[idx]);
myShader.set("resolution", float(width), float(height));
shader(myShader);
}
void setShaderParameters() {
myShader.set("time", millis()/1000.0);
// vert1
if (idx==0) {
myShader.set("m", 0.2, 0.1, 0.3, 0.2);
}
// vert2
else if (idx==1) {
myShader.set("m", 0.2, 0.1, 0.3);
}
// wrap
else if (idx==2) {
myShader.set("mouse", float(mouseX), float(mouseY));
}
}
void keyPressed() {
if (keyCode==LEFT) idx = (shaders.length + idx - 1) % shaders.length;
else if (keyCode==RIGHT) idx = (idx + 1) % shaders.length;
setupShader(idx);
}
void oscEvent(OscMessage theOscMessage) {
String address = theOscMessage.addrPattern();
if (address.equals("/wek/outputs")) {
float myClass = theOscMessage.get(0).floatValue();
if (myClass == 1.0) {
nextIdx = 0;
}
else if (myClass == 2.0) {
nextIdx = 1;
}
else if (myClass == 3.0) {
nextIdx = 2;
}
}
}
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define PROCESSING_TEXTURE_SHADER
uniform vec2 resolution;
uniform sampler2D texture;
void main(void) {
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
float a = atan(p.y,p.x);
float r = sqrt(dot(p,p));
vec2 uv;
uv.x = (a + 3.14159265359)/6.28318530718;
uv.y = r / sqrt(2.0);
vec3 col = texture2D(texture, uv).rgb;
gl_FragColor = vec4(col, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment