sheadernanigans/src/2023-06-21.festl_is/main.frag

77 lines
2.1 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"
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;
}