Skip to content

Commit 07e8c06

Browse files
Eugene KoganEugene Kogan
authored andcommitted
first upload
0 parents  commit 07e8c06

33 files changed

+1668
-0
lines changed

ColorShaders/ColorShaders.pde

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
String[] shaders = new String[]{
2+
"blobby.glsl", "drip.glsl", "electro.glsl",
3+
"eye.glsl", "bands.glsl", "sinewave.glsl", "noisy.glsl",
4+
"nebula.glsl", "landscape.glsl", "monjori.glsl" };
5+
6+
PShader shade;
7+
int idxShader = 0;
8+
9+
void setup()
10+
{
11+
size(640, 480, P2D);
12+
textSize(22);
13+
fill(255);
14+
shade = loadShader(shaders[idxShader]);
15+
}
16+
17+
void draw()
18+
{
19+
setShaderParameters();
20+
21+
// turn on shader and display movie
22+
shader(shade);
23+
rect(0, 0, width, height);
24+
25+
// turn off shader before displaying filename
26+
resetShader();
27+
text(shaders[idxShader], 5, 20);
28+
}
29+
30+
void setShaderParameters()
31+
{
32+
shade.set("time", (float) millis()/1000.0);
33+
shade.set("resolution", float(width), float(height));
34+
35+
// blobby
36+
if (idxShader == 0) {
37+
shade.set("depth", map(mouseY, 0, height, 0, 2));
38+
shade.set("rate", map(mouseX, 0, width, 0, 2));
39+
}
40+
41+
// drip
42+
else if (idxShader == 1) {
43+
shade.set("intense", 0.5);
44+
shade.set("speed", 0.9);
45+
shade.set("graininess", (float)mouseX/width, (float)mouseY/height);
46+
}
47+
48+
// electro
49+
else if (idxShader == 2) {
50+
shade.set("rings", map(mouseY, 0, height, 5, 40));
51+
shade.set("complexity", map(mouseX, 0, width, 1, 60));
52+
}
53+
54+
// eye
55+
else if (idxShader == 3) {
56+
shade.set("mouse", (float)mouseX, (float)mouseY);
57+
}
58+
59+
// bands
60+
else if (idxShader == 4) {
61+
shade.set("noiseFactor", map(mouseX, 0, width, 5, 100));
62+
shade.set("stripes", map(mouseY, 0, height, 0, 100));
63+
}
64+
65+
// sinewaves
66+
else if (idxShader == 5) {
67+
shade.set("colorMult", 2.5, 1.2);
68+
shade.set("coefficients", 30, map(mouseY, 0, height, 0, 80), map(mouseX, 0, width, 1, 200));
69+
}
70+
71+
// water noise
72+
else if (idxShader == 6) {
73+
shade.set("noiseFactor", map(mouseX, 0, width, 0, 2), map(mouseX, 0, width, 0, 2));
74+
shade.set("noiseFactorTime", map(mouseY, 0, height, 0, 2));
75+
}
76+
77+
// nebula
78+
else if (idxShader == 7) {
79+
shade.set("starspeed", map(mouseX, 0, width, 0, 100));
80+
}
81+
82+
// landscape
83+
else if (idxShader == 8) {
84+
shade.set("dir", map(mouseX, 0, width, 1.5, 5));
85+
}
86+
87+
// monjori
88+
else if (idxShader == 9) {
89+
shade.set("graininess", map(mouseX, 0, width, 10, 100));
90+
shade.set("pace", 50.0);
91+
shade.set("twist", map(mouseY, 0, height, 0, 100));
92+
}
93+
}
94+
95+
void keyPressed() {
96+
if (keyCode==LEFT) {
97+
idxShader = (idxShader + shaders.length - 1) % shaders.length;
98+
shade = loadShader(shaders[idxShader]);
99+
}
100+
else if (keyCode==RIGHT) {
101+
idxShader = (idxShader + 1) % shaders.length;
102+
shade = loadShader(shaders[idxShader]);
103+
}
104+
}

ColorShaders/data/bands.glsl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#define PROCESSING_COLOR_SHADER
2+
3+
#ifdef GL_ES
4+
precision mediump float;
5+
#endif
6+
7+
uniform float time;
8+
uniform float noiseFactor;
9+
uniform vec2 resolution;
10+
uniform float stripes;
11+
12+
// Gradient Noise (http://en.wikipedia.org/wiki/Gradient_noise)
13+
// Created by inigo quilez - iq/2013
14+
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
15+
// Noise implementation from https://www.shadertoy.com/view/XdXGW8
16+
vec2 hash( vec2 p )
17+
{
18+
p = vec2( dot(p,vec2(127.1,311.7)),
19+
dot(p,vec2(269.5,183.3)) );
20+
21+
return -1.0 + 2.0*fract(sin(p)*43758.5453123);
22+
}
23+
24+
float noise( in vec2 p )
25+
{
26+
vec2 i = floor( p );
27+
vec2 f = fract( p );
28+
29+
vec2 u = f*f*(3.0-2.0*f);
30+
31+
return mix( mix( dot( hash( i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
32+
dot( hash( i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
33+
mix( dot( hash( i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
34+
dot( hash( i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
35+
}
36+
37+
38+
void main( void ) {
39+
vec2 position = ( gl_FragCoord.xy / resolution.xy );
40+
41+
float stripeNumber = floor(position.x * stripes);
42+
float stripePosition = fract(position.x * stripes);
43+
44+
float color = (noise(vec2(position.y * noiseFactor - 2.0*time, stripeNumber+noise(vec2(5.0*stripeNumber, time*0.1))*time*0.2)) + 1.0) / 2.0;
45+
color = smoothstep(color, 0.2, 0.4);
46+
color -= 0.2*mod(color, 0.2*position.x*position.y);
47+
//color = (noise(vec2(position.y * 0.1 + time * 0.2 * fract(stripeNumber * 1.3), stripeNumber)) + 1.0) / 2.0;
48+
if (stripePosition < 0.3)
49+
color -=0.9;
50+
51+
vec3 col = vec3(color);
52+
col.r = mod(col.g, position.x);
53+
col.g = mod(col.b, position.y);
54+
gl_FragColor = vec4(col, 1.0);
55+
56+
}

ColorShaders/data/blobby.glsl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#define PROCESSING_COLOR_SHADER
2+
3+
#ifdef GL_ES
4+
precision mediump float;
5+
#endif
6+
7+
uniform float time;
8+
uniform vec2 resolution;
9+
uniform float depth;
10+
uniform float rate;
11+
12+
#define N 16
13+
14+
void main( void ) {
15+
vec2 v=(gl_FragCoord.xy-(resolution*0.5))/min(resolution.y,resolution.x)*10.0;
16+
float t=time * 0.3,r=2.0;
17+
for (int i=1;i<N;i++){
18+
float d=(3.14159265 / float(N))*(float(i)*14.0);
19+
r+=length(vec2(rate*v.y,rate*v.x))+1.21;
20+
v = vec2(v.x+cos(v.y+cos(r)+d)+cos(t),v.y-sin(v.x+cos(r)+d)+sin(t));
21+
}
22+
r = (sin(r*0.09)*0.5)+0.5;
23+
r = pow(r, depth);
24+
gl_FragColor = vec4(r,pow(max(r-0.55,0.0)*2.2,2.0),pow(max(r-4.875,0.1)*3.0,6.0), 1.0 );
25+
}

ColorShaders/data/drip.glsl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#define PROCESSING_COLOR_SHADER
2+
3+
#ifdef GL_ES
4+
precision mediump float;
5+
#endif
6+
7+
uniform vec2 resolution;
8+
uniform float time;
9+
uniform float intense;
10+
uniform float speed;
11+
uniform vec2 graininess;
12+
13+
const float offset = 20.0;
14+
const int complexity = 38;
15+
const float Pi = 3.14159;
16+
17+
void main()
18+
{
19+
vec2 p=(2.0*gl_FragCoord.xy-resolution)/max(resolution.x,resolution.y);
20+
21+
for(int i=1;i<complexity;i++)
22+
{
23+
vec2 newp=p;
24+
newp.x+=graininess.x/float(i)*sin(float(i)*p.y+time/speed+0.3*float(i))+offset;
25+
newp.y+=graininess.y/float(i)*sin(float(i)*p.x+time/speed+0.3*float(i+100))+offset;
26+
p=newp;
27+
}
28+
vec3 col=vec3(intense*sin(3.0*p.x)+intense,intense*sin(3.0*p.y)+intense,intense*sin(p.x+p.y)+intense);
29+
col.g = col.r;
30+
// col.b = col.r;
31+
gl_FragColor=vec4(col, 1.0);
32+
}

ColorShaders/data/electro.glsl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Electrocardiogram Effect
2+
// Imported from http://www.geeks3d.com/20111223/shader-library-electrocardiogram-effect-glsl/
3+
4+
#define PROCESSING_COLOR_SHADER
5+
6+
#ifdef GL_ES
7+
precision mediump float;
8+
#endif
9+
10+
uniform vec2 resolution;
11+
uniform float time;
12+
uniform float complexity;
13+
uniform float rings;
14+
15+
float viewAngle = 0.0;//0.040*sin(0.1*time);
16+
float speed = -1.0;
17+
float rate = .50;
18+
float baseamp = 0.10;
19+
20+
void main(void)
21+
{
22+
vec2 p = -1.0 + 2.0 * (gl_FragCoord.xy / resolution.xy);
23+
vec2 op = p;
24+
p = vec2(distance(p, vec2(0, 0)), sin(0.40*time+atan(p.x, p.y) * complexity));
25+
float x = speed * viewAngle * time + rate * p.x;
26+
float base = (0.1 + 3.0*tan(x*0.7 + time)) * (2.37 + 2.5*sin(x*rings + time));
27+
float z = fract(0.05*x);
28+
z = max(z, 100.0-z);
29+
z = pow(z, 50.0);
30+
float pulse = exp(-1000000.0 * z);
31+
vec4 ecg_color = vec4(0.3, 1.0, 0.4, 1.0);
32+
vec4 c = pow(1.0-abs(p.y-(baseamp*base+pulse-0.5)), 4.0) * ecg_color;
33+
vec3 d = 1.0-vec3(c.r, c.r, c.r);
34+
gl_FragColor = vec4(d, 1.0);
35+
}

ColorShaders/data/eye.glsl

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#define PROCESSING_COLOR_SHADER
2+
3+
#ifdef GL_ES
4+
precision mediump float;
5+
#endif
6+
7+
8+
uniform float time;
9+
uniform vec2 resolution;
10+
uniform vec2 mouse;
11+
12+
mat2 m = mat2( 0.8, 0.6, -0.6, 0.6 );
13+
14+
float hash( float n )
15+
{
16+
return fract(sin(n)*43758.5453);
17+
}
18+
19+
float noise( in vec2 x )
20+
{
21+
vec2 p = floor(x);
22+
vec2 f = fract(x);
23+
f = f*f*(3.0-2.0*f);
24+
float n = p.x + p.y*57.0;
25+
float res = mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
26+
return res;
27+
}
28+
29+
float fbm( vec2 p )
30+
{
31+
float f = 0.0;
32+
f += 0.50000*noise( p ); p = m*p*2.02;
33+
f += 0.25000*noise( p ); p = m*p*2.03;
34+
f += 0.12500*noise( p ); p = m*p*2.01;
35+
f += 0.06250*noise( p ); p = m*p*2.04;
36+
f += 0.03125*noise( p );
37+
return f/0.984375;
38+
}
39+
40+
float length2( vec2 p )
41+
{
42+
float ax = abs(p.x);
43+
float ay = abs(p.y);
44+
return pow( pow(ax,4.0) + pow(ay,4.0), 1.0/4.0 );
45+
}
46+
47+
void main(void)
48+
{
49+
vec2 q = gl_FragCoord.xy / resolution.xy;
50+
vec2 p = -1.0 + 2.0 * q;
51+
vec2 m = -1.0 + 2.0 * mouse.xy / resolution.xy;
52+
m.y = -m.y;
53+
p.x *= (resolution.x/resolution.y);
54+
55+
float rad_eye = 0.94;
56+
float rad_iris = 0.6 + 0.05 * sin(time);
57+
float rad_pupil = 0.4 + 0.03 * sin(0.5*time);
58+
59+
vec2 ctr1 = 0.55 * m;
60+
vec2 ctr2 = 0.40 * m;
61+
vec2 ctr3 = 0.03 * m;
62+
63+
float r1 = length(p-ctr1);
64+
float r2 = length(p-ctr2);
65+
float r3 = length(p-ctr3);
66+
67+
// start with base color of iris
68+
vec3 col = vec3( 0.0, 0.3, 0.4 );
69+
70+
// colors for iris/pupils
71+
// vec3 iris1, iris2; = vec3(0.2, 0.5, 0.4);
72+
// vec3 iris2 = vec3(0.9, 0.6, 0.2);
73+
vec3 iris1, iris2;
74+
75+
iris1.x = 0.1 + 0.3*fbm(2.3*p + vec2(time*0.4, time*0.5));
76+
iris1.y = 0.3 + 0.4*fbm(4.3*p + vec2(time*0.1, time*0.2));
77+
iris1.z = 0.2 + 0.4*fbm(1.3*p + vec2(time*0.3, time*0.3));
78+
79+
iris2.x = 0.8 + 0.2*fbm(1.7*p + vec2(time*0.2, time*0.3));
80+
iris2.y = 0.4 + 0.4*fbm(3.1*p + vec2(time*0.3, time*0.4));
81+
iris2.z = 0.0 + 0.4*fbm(2.3*p + vec2(time*0.1, time*0.2));
82+
83+
84+
// add some noise to iris
85+
float f = fbm( 5.0*(p-ctr2)+time );
86+
col = mix( col, iris1, f );
87+
88+
// add yellow
89+
col = mix( col, iris2, smoothstep(0.6,0.2, (r1+r2)/2.0) );
90+
91+
// add some white streaks to iris
92+
float a = atan( abs(p.y-ctr1.y), p.x-ctr1.x );
93+
a += 0.05*fbm( 10.0*p+time*0.5 );
94+
f = smoothstep( 0.3, 1.0, fbm( vec2(20.0*a,6.0*r2) ) );
95+
col = mix( col, vec3(0.8, 0.85, 0.93), f );
96+
97+
98+
// add light reflection to top right
99+
f = smoothstep( 0.4, 0.9, fbm( vec2(15.0*a,10.0*((r1+r3)/2.0)) ) );
100+
col *= 1.0-0.5*f;
101+
col *= 1.0-0.25*smoothstep( 0.6,0.8, r2 );
102+
103+
// add pupil
104+
col = mix(col, vec3(0.0, 0.0, 0.0), smoothstep(rad_pupil, rad_pupil - 0.25, r1) );
105+
106+
// add light reflection to top right
107+
f = 1.0 - smoothstep( 0.0, 0.6, length2( mat2(0.6,0.8,-0.8,0.6)*(p-ctr1-vec2(0.35,0.4) )*vec2(1.0,2.0)) );
108+
col += vec3(1.0,0.9,0.9)*f*0.985;
109+
col *= vec3(0.8+0.2*cos(r2*a));
110+
111+
col = mix(col, vec3(1.0, 1.0, 1.0), smoothstep(rad_iris , rad_iris + 0.09, r2) );
112+
col = mix(col, vec3(0.0, 0.0, 0.0), smoothstep(rad_eye , rad_eye + 0.05, r3) );
113+
114+
gl_FragColor = vec4(col,1.0);
115+
}

0 commit comments

Comments
 (0)