@xdadda/mini-gl
Version:
webgl image editing library with filters and effects
53 lines (42 loc) • 1.51 kB
Plain Text
VIGNETTES
//natural vignette
//modified from https://www.shadertoy.com/view/4lSXDm
float Falloff = 0.95; //
float radius = 0.75; //
vec2 pos = vec2(0.5,0.5); //center of vignette
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 color = texture(iChannel0, uv);
//vec4 color = vec4(1.,1.,1.,1.);
vec2 coord = (uv - pos) * vec2(iResolution.x/iResolution.y,1.) / radius;
float rf = 1.0 + dot(coord, coord) * Falloff*Falloff;
float e = 1.0 / (rf*rf);
fragColor = vec4(color.rgb * e, 1.0);
}
//
// modified https://www.shadertoy.com/view/MsySzy
float rand(vec2 uv) {
float a = dot(uv, vec2(92., 80.));
float b = dot(uv, vec2(41., 62.));
float x = sin(a) + cos(b) * 51.;
return fract(x);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 uv = fragCoord.xy / iResolution.xy;
vec4 d = texture(iChannel1, uv);
vec2 rnd = vec2(rand(uv+d.r*.05), rand(uv+d.b*.05));
//vignette
const vec2 lensRadius = vec2(0.35*1.42, 0.25);
//float dist = distance(uv.xy, vec2(0.5,0.5));
float dist = distance(uv.xy, iMouse.xy/ iResolution.xy );
float vigfin = pow(1.-smoothstep(lensRadius.x, lensRadius.y, dist),2.);
rnd *= .035*vigfin;
uv += rnd;
//uv += rnd + vigfin; //give lens distorsion around circle
fragColor = mix(texture(iChannel0, uv),vec4(COLOR_RGB,1.0),0.);
}