98 lines
2.7 KiB
GLSL
98 lines
2.7 KiB
GLSL
#ifdef GL_ES
|
|
precision mediump float;
|
|
#endif
|
|
|
|
|
|
|
|
// always available
|
|
uniform vec2 u_mouse; // mouse pixel coordinates
|
|
uniform vec2 u_resolution; // viewport resolution in pixels
|
|
uniform float u_time; // in seconds
|
|
uniform float u_delta; // delta time between frames (in seconds)
|
|
varying vec2 v_texcoord;
|
|
|
|
// video in - actually, this is just the first texture in. can be anything and is set from commandline.
|
|
uniform sampler2D u_tex0;
|
|
uniform vec2 u_tex0Resolution;
|
|
|
|
|
|
// osc messages in, add `-p 8000 -l` to receive them.
|
|
// their path just needs to match the name
|
|
uniform float osc_val_1;
|
|
uniform float osc_val_2;
|
|
uniform float osc_val_3;
|
|
|
|
|
|
// lygia effects import and setup
|
|
// for some reason the -I flag doesn't do the right thing here
|
|
// common imports:
|
|
#include "../../lib/lygia/math/lerp.glsl"
|
|
|
|
// effect: chromatic aberration
|
|
#define CHROMAAB_TYPE vec4
|
|
#include "../../lib/lygia/distort/chromaAB.glsl"
|
|
|
|
// effect: brightness-contrast
|
|
#include "../../lib/lygia/color/exposure.glsl"
|
|
|
|
// effect: dither
|
|
#define FIND_CLOSER(new) (old = mix(new, old, step(length(old-ref), length(new-ref))));
|
|
vec3 ditherBayerLut(vec3 ref) {
|
|
vec3 old = vec3(1.0);
|
|
FIND_CLOSER(vec3(0.74));
|
|
FIND_CLOSER(vec3(0.47));
|
|
FIND_CLOSER(vec3(0.13));
|
|
FIND_CLOSER(vec3(0.05));
|
|
return old;
|
|
}
|
|
#include "../../lib/lygia/sample/dither.glsl"
|
|
|
|
//custom helpers -- TODO check if lygia can do this?
|
|
// https://gist.github.com/983/e170a24ae8eba2cd174f
|
|
vec3 rgb2hsv(vec3 c)
|
|
{
|
|
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
|
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
|
|
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
|
|
|
|
float d = q.x - min(q.w, q.y);
|
|
float e = 1.0e-10;
|
|
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
|
}
|
|
|
|
vec3 hsv2rgb(vec3 c)
|
|
{
|
|
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
|
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
}
|
|
|
|
|
|
void main() {
|
|
// common setup
|
|
vec4 color = vec4(vec3(0.0), 1.0);
|
|
vec2 pixel = 1.0/u_resolution.xy;
|
|
vec2 st = gl_FragCoord.xy * pixel; // 0-1
|
|
vec2 uv = v_texcoord;
|
|
|
|
// read input texture
|
|
color = texture2D(u_tex0, st, 1.0);
|
|
|
|
// effect: dither
|
|
vec4 fx_dither = vec4(sampleDither(u_tex0, uv, u_resolution * 1.0), 1.0);
|
|
float fx_dither_amount = .0;
|
|
color = lerp(color, fx_dither, fx_dither_amount);
|
|
|
|
// effect: chromatic aberration
|
|
vec4 fx_chroma = chromaAB(u_tex0, uv);
|
|
float fx_chroma_amount = .0;
|
|
color = lerp(color, fx_chroma, fx_chroma_amount);
|
|
|
|
// effect: exposure
|
|
float exposure_val = osc_val_1;
|
|
color = exposure(color,exposure_val);
|
|
|
|
// actually set color
|
|
gl_FragColor = color;
|
|
}
|