Adding a few more shader examples

This commit is contained in:
codeanticode
2012-09-03 01:31:49 +00:00
parent d09d1d461f
commit 7709d70d47
10 changed files with 526 additions and 0 deletions
@@ -0,0 +1,19 @@
PImage tex;
PShader deform;
void setup() {
size(512, 384, P2D);
textureWrap(REPEAT);
tex = loadImage("tex1.jpg");
deform = loadShader("deform.glsl");
deform.set("resolution", float(width), float(height));
}
void draw() {
deform.set("time", millis() / 1000.0);
deform.set("mouse", float(mouseX), float(mouseY));
shader(deform);
image(tex, 0, 0, width, height);
}
@@ -0,0 +1,24 @@
uniform sampler2D textureSampler;
uniform float time;
uniform vec2 resolution;
uniform vec2 mouse;
void main(void) {
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
vec2 m = -1.0 + 2.0 * mouse.xy / resolution.xy;
float a1 = atan(p.y - m.y, p.x - m.x);
float r1 = sqrt(dot(p - m, p - m));
float a2 = atan(p.y + m.y, p.x + m.x);
float r2 = sqrt(dot(p + m, p + m));
vec2 uv;
uv.x = 0.2 * time + (r1 - r2) * 0.25;
uv.y = sin(2.0 * (a1 - a2));
float w = r1 * r2 * 0.8;
vec3 col = texture2D(textureSampler, 0.5 - 0.495 * uv).xyz;
gl_FragColor = vec4(col / (0.1 + w), 1.0);
}