Skip to content

Instantly share code, notes, and snippets.

@shakesoda
Last active January 19, 2017 01:57
Show Gist options
  • Save shakesoda/3a41ffae3aadd71ecc9d43f8e9dbbdc4 to your computer and use it in GitHub Desktop.
Save shakesoda/3a41ffae3aadd71ecc9d43f8e9dbbdc4 to your computer and use it in GitHub Desktop.
noise blur experiment based on https://www.shadertoy.com/view/XtGGzz
#define SPREAD 10.0
#define OFFSET 1.0
vec2 hash23(vec3 p3) {
p3 = fract(p3 * vec3(443.897, 441.423, 437.195));
p3 += dot(p3, p3.yzx+19.19);
return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y))*2.0-1.0;
}
vec4 sample(vec2 uv, float offset, float n, bool dancing) {
float z_offset = 0.0;
if (dancing)
z_offset = mod(iGlobalTime, 1.0);
vec2 p0 = uv+hash23(vec3(uv,z_offset+offset))/iResolution.xy*(SPREAD+OFFSET*n);
return texture2D(iChannel0, p0);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = fragCoord.xy / iResolution.xy;
bool dancing = uv.y < 0.5;
// 1, 2 and 4 samples respectively.
if (uv.x <= 1.0/3.0) {
fragColor = sample(uv, 0.0, 0.0, dancing);
}
else if (uv.x > 1.0/3.0 && uv.x < 2.0/3.0) {
fragColor = sample(uv, 0.0, 0.0, dancing);
fragColor += sample(uv, 0.5, 1.0, dancing);
fragColor /= 2.0;
}
else {
fragColor = sample(uv, 0.0, 0.0, dancing);
fragColor += sample(uv, 0.5, 1.0, dancing);
fragColor += sample(uv, 1.0, 2.0, dancing);
fragColor += sample(uv, 1.5, 3.0, dancing);
fragColor /= 4.0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment