# Solarization shader

**URL:** <https://discourse.processing.org/t/solarization-shader/21731>\
**Category:** Gallery\
**Created:** [June 10, 2020, 9:39am UTC](https://discourse.processing.org/t/solarization-shader/21731 "2020-06-10T09:39:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [June 10, 2020, 9:39am UTC](https://discourse.processing.org/t/solarization-shader/21731/1 "2020-06-10T09:39:56Z")

</div>

Recently there was a post about creating a [Sabbatier effect in processing](https://discourse.processing.org/t/sabattier-effect-in-processing/21553). It got me thinking about creating a glsl shader filter, so I stole an idea from [shader toy](https://www.shadertoy.com/view/ll2GWc). 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).

 ![solarization](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6ae42ac53eac0821b51bc7a7581ebd61cd582a00.png)

```java
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

```auto
#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.);
}

```

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [June 10, 2020, 1:30pm UTC](https://discourse.processing.org/t/solarization-shader/21731/2 "2020-06-10T13:30:11Z")

</div>

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

```auto
#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.);
}

```

 ![sabbatier](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/8752d145eedf5a41a5f4cc27f16d26392911fee9.png)

---

<div class="post-metadata">

**Author:** ![uheinema](https://avatars.discourse-cdn.com/v4/letter/u/e99b99/32.png) [@uheinema](https://discourse.processing.org/u/uheinema)\
**Post date:** [June 11, 2020, 12:09pm UTC](https://discourse.processing.org/t/solarization-shader/21731/3 "2020-06-11T12:09:45Z")

</div>

Well done.

Had made a GLSL version myself, see

> <https://github.com/Milchreis/processing-imageprocessing/issues/21#issuecomment-641557880>
>
> Hello!
> Thanks for the wonderful and well-made Processing library!
> It's very useful for static images and perhaps will be enough for most use...

Thanks for the example of videocapture

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

---

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [June 11, 2020, 1:03pm UTC](https://discourse.processing.org/t/solarization-shader/21731/4 "2020-06-11T13:03:58Z")

</div>

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