Last active
October 13, 2019 15:20
-
-
Save native-m/80449341be5e82813659b45c406f3b40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float rand(vec2 p) | |
{ | |
float t = floor(iTime * 20.) / 10.; // limit glitch FPS | |
//t = exp(t); | |
return fract(sin(dot(p, vec2(t * 12.9898, t * 78.233))) * 43758.5453); | |
} | |
float noise(vec2 uv, float blockiness) | |
{ | |
vec2 lv = fract(uv); | |
vec2 id = floor(uv); | |
float n1 = rand(id); | |
float n2 = rand(id+vec2(1,0)); | |
float n3 = rand(id+vec2(0,1)); | |
float n4 = rand(id+vec2(1,1)); | |
vec2 u = smoothstep(0.0, 1.0 + blockiness, lv); | |
return mix(mix(n1, n2, u.x), mix(n3, n4, u.x), u.y); | |
} | |
float fbm(vec2 uv, int count, float blockiness, float complexity) | |
{ | |
float val = 0.0; | |
float amp = 0.5; | |
while(count != 0) | |
{ | |
val += amp * noise(uv + (rand(ceil(uv * 3.) / 3.) * 2. - 1.), blockiness); | |
amp *= 0.5; | |
uv *= complexity; | |
count--; | |
} | |
return val; | |
} | |
void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
{ | |
// Normalized pixel coordinates (from 0 to 1) | |
vec2 uv = fragCoord/iResolution.xy; | |
vec2 uv2 = uv; | |
uv *= 5.; | |
uv.x *= noise((ceil(uv * 5.) / 5.) * 0.3, 3.0); // should i? | |
float noiseVal = (smoothstep(0.5, 1.0, fbm(uv, 2, 3.0, 1.5))); // take the noise | |
// Time varying pixel color | |
vec3 col = vec3(texture(iChannel0, vec2(uv2.x + noiseVal * 0.1, uv2.y)).r, | |
texture(iChannel0, vec2(uv2.x - noiseVal * 0.1, uv2.y)).g, | |
texture(iChannel0, vec2(uv2.x, uv2.y)).b); // adjust amplitude | |
//vec3 col = vec3(noiseVal); | |
// Output to screen | |
fragColor = vec4(col,1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment