Solarization shader

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.);
}
4 Likes

Interestingly it is possible to combine the solarization shader logic with grayscale to get the Sabbatier effect:-

#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define THRESHOLD vec3(1.,.92,.1)
#define GRAY vec3(0.299, 0.597, 0.114)

uniform sampler2D texture; // iChannel0 in Shadertoy
uniform vec2 sketchSize; // iResolution in Shadertoy
vec3 val;
float gray;

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;
    gray = dot(val, GRAY);
    gl_FragColor = vec4(vec3(gray), 1.);
}

1 Like

Well done.

Had made a GLSL version myself, see

Thanks for the example of videocapture

PS: The function you use is not Sabbatier, you are loosing a lot of dynamic range.

2 Likes

I like it, looks kind of spooky though (Iā€™m not sure there is a need to display original).