Recently there was a post about creating a Sabbatier effect in processing. It got me thinking about creating a glsl shader filter, so I stole an idea from shader toy. Needed a bit of hacking to run with processing, here I am showing off with a video capture sketch using processing-4.0 beta on raspberryPI4 (Manjaro 64 bit).
import processing.video.Capture;
PShader solarization;
Capture cam;
void setup() {
size(640, 480, P2D);
solarization = loadShader("solarization.glsl");
solarization.set("sketchSize", (float)width, (float)height);
startCapture(width, height);
}
void startCapture(int w, int h) {
cam = new Capture(this, w, h, "UVC Camera (046d:0825)");
cam.start();
}
void draw(){
image(cam, 0, 0);
if (!mousePressed) {
filter(solarization);
}
}
void captureEvent(Capture c) {
c.read();
}
The shader
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define THRESHOLD vec3(1.,.92,.1)
uniform sampler2D texture; // iChannel0 in Shadertoy
uniform vec2 sketchSize; // iResolution in Shadertoy
vec3 val;
void main() {
vec2 uv = gl_FragCoord.xy / sketchSize.xy;
val = vec3(texture2D(texture, uv));
if (val.x < THRESHOLD.x) val.x = 1. - val.x;
if (val.y < THRESHOLD.y) val.y = 1. - val.y;
if (val.z < THRESHOLD.z) val.z = 1. - val.z;
gl_FragColor = vec4(val, 1.);
}