xxxxxxxxxx
157
// https://jowwii.medium.com/shaders-for-liquid-effects-with-three-js-9951b2a45bb3
let circles, maxD;
let fs, fs2;
function setup() {
createCanvas(windowWidth, windowHeight);
maxD = width * 0.2;
circles = [];
for (let _ = 0; _ < 150; _++) {
let d = random(maxD, maxD/2);
let g = createGraphics(d, d);
g.noFill();
g.stroke(0);
for (let _d = d-2; _d > 4; _d -= 8) {
g.circle(g.width / 2, g.height/2, _d);
}
let c = {
x: random(width-1),
y: random(height-1),
d: d,
vx: random(-2,2),
vy: random(-2,2),
g: g,
}
circles.push(c);
}
noFill();
stroke(20);
fs = createFilterShader(fs_src);
fs2 = createFilterShader(rgb_src);
}
function draw() {
background(color(220,220,220,255));//10));
// rect(0,0,width,height);
stroke(0);
// for (let c of circles) {
// circle(c.x, c.y, c.d);
// image(c.g, c.x, c.y);
// fill(220);
// for (let d = c.d; d > 4; d -= 4) {
// circle(c.x, c.y, d);
// noFill();
// }
// c.x += c.vx;
// c.y += c.vy;
// if (c.x < 0 || c.x > width) c.vx *= -1;
// if (c.y < 0 || c.y > height) c.vy *= -1;
// }
fs2.setUniform("_noise", 0.05);
fs.setUniform("u_time", frameCount/100.);
filter(fs);
// filter(fs2);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
let fs_src = `precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D tex0;
uniform float u_time;
void main() {
vec2 uv = vTexCoord;
vec3 col;
vec4 _col = texture2D(tex0, uv);
col = _col.rgb;
// vec2 coord = (gl_FragCoord.xy / _col.xy);
vec2 coord = uv.xy;
float color = 0.0;
for (float i = 0.; i < 10.; i++) {
if (mod(i, 2.)==0.) {
color += sin(coord.x * float(i) * 10.0 + cos(u_time + coord.y * 10.0 + sin(coord.x * 50.0 + u_time * 2.0))) * 2.0;
} else {
color += cos(coord.x * float(i) * 10.0 + sin(u_time + coord.y * 10.0 + cos(coord.x * 50.0 + u_time * 2.0))) * 2.0;
}
}
// color += sin(coord.x * 50.0 + cos(u_time + coord.y * 10.0 + sin(coord.x * 50.0 + u_time * 2.0))) * 2.0;
// color += cos(coord.x * 20.0 + sin(u_time + coord.y * 10.0 + cos(coord.x * 50.0 + u_time * 2.0))) * 2.0;
// color += sin(coord.x * 30.0 + cos(u_time + coord.y * 10.0 + sin(coord.x * 50.0 + u_time * 2.0))) * 2.0;
// color += cos(coord.x * 10.0 + sin(u_time + coord.y * 10.0 + cos(coord.x * 50.0 + u_time * 2.0))) * 2.0;
// color += tan(coord.y);
color = fract(color);
//color /= 24.0;
//if (col.r < 0.1 && col.g < 0.1 && col.b < 0.1) gl_FragColor = vec4(col,1.0);
//else
gl_FragColor = vec4(vec3(color + coord.y, color + coord.x, color + coord.x + coord.y), 0.2);
// gl_FragColor = vec4(col, 1.0);
}`;
let rgb_src = `precision mediump float;
varying vec2 vTexCoord;
uniform sampler2D tex0;
uniform float _noise;
uniform float _g_noise;
uniform bool fractalize;
//https://iquilezles.org/articles/distfunctions2d/
float sdBox( in vec2 p, in vec2 b )
{
vec2 d = abs(p)-b;
return length(max(d,0.0)) + min(max(d.x,d.y),0.0);
}
void main() {
vec2 uv = vTexCoord;
vec3 col;
vec4 _col = texture2D(tex0, uv);
col = _col.rgb;
float noise = 0.25;
// if (sdBox(uv, vec2(1.0,sin(_g_noise*0.15))) > (2.2 * sin(_g_noise*0.5))) {//0.5) {
//if ((sdBox(uv, vec2(0.15,0.31)) > 0.75) || (1./sdBox(uv, vec2(0.85,0.71)) < 0.25)) {
// glitch rgb components
// vec2 offset = vec2(noise * 0.05, 0.0);
vec2 offset = vec2(noise * _noise, noise *_noise);
col.r = texture2D(tex0, uv-offset).r;
col.g = texture2D(tex0, uv+offset).g;
col.b = texture2D(tex0, uv-offset).b;
if (fractalize) col = fract(5.*cos(2.0/col));
//col.g *= tan(4.0*_g_noise);
//col.r = cos(2.8 * _g_noise);
//col.g = pow(step(0.5,col.g),_g_noise);
//}
float alpha = 1.0;
//float alpha = clamp(pow(noise, 2.0),0.0, 0.5);
gl_FragColor = vec4(col, alpha);
}`;