This browser has no WebGPU, so the sketch cannot run here. The program is below, and it runs in a current Chrome, Edge or Safari.
Image Filters
a collection of image filters over a 3D scene
// ── main ──
///////////////////////////////
// image-filters
// a collection of image filters over a 3D scene
//////////////////////////////
&dim = (256,256);
&original = #img;
&avg1 = #img.AVG((-1,-1), (1,1));
&rad = 6;
&blur = #img.AVG((-&rad,-&rad), (&rad,&rad));
&edges = mlt(4, abs(
sub(#img, &avg1)
));
&sharpen = add(
#img,
abs(
sub(
#img,
&avg1
)
)
);
&emboss = add(
sub(
#img(-1,-1),
#img(1,1)
),
0.5
);
&threshold = lrg(#img, 0.15);
&poster = div(flr(mlt(#img, 4)), 4);
&glow = add(
mlt(#img, 0.5),
mlt(&blur, 0.5)
);
&feedback = add(
mlt(#, 0.01),
mlt(#.AVG((-1,-1), (1,1)), 0.9)
);
///////////////////////////////////////
#img{
dim = &dim;
run = ;
}
#blur{
dim = &dim;
run = &blur;
}
~blur{
col = #blur;
pos = (-1,1,0);
scl = (0.75);
}
#glow{
dim = &dim;
run = add(&glow, mlt(&feedback, 0.5));
}
~glow{
col = #glow;
pos = (1,1,0);
scl = (0.75);
}
#poster{
dim = &dim;
run = &poster;
}
~poster{
col = #poster;
pos = (-1,-1,0);
scl = (0.75);
}
#sobel{
dim = &dim;
run = &sobel;
}
~sobel{
col = #sobel;
pos = (1,-1,0);
scl = (0.75);
}
///////////////////////////////////////
// 3D scene
~mesh{
i_geo = (-0.35, -0.35, 0); // torus
i_res = (4, 16, -0.5);
i_scl = (0.15);
pos = (0, 0, 0);
rot = (mlt(step, 0.004), mlt(step, 0.01), 0);
}
{
= (0,0,0);
= (0,0,0.5);
= (1, 0.5, 0);
= (0.1);
= (0);
}
// ── sobel ──
&gx = add(
mlt(#img(-1,-1), -1),
mlt(#img( 1,-1), 1),
mlt(#img(-1, 0), -2),
mlt(#img( 1, 0), 2),
mlt(#img(-1, 1), -1),
mlt(#img( 1, 1), 1)
);
&gy = add(
mlt(#img(-1,-1), -1),
mlt(#img( 0,-1), -2),
mlt(#img( 1,-1), -1),
mlt(#img(-1, 1), 1),
mlt(#img( 0, 1), 2),
mlt(#img( 1, 1), 1)
);
&sobel = add(abs(&gx), abs(&gy));