Last active
September 4, 2018 08:22
-
-
Save native-m/a00d51ee21ee61644691f410976cde05 to your computer and use it in GitHub Desktop.
Glitch with block noise (fractal noise)
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 * 10.); | |
| 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, blockiness); | |
| amp *= 0.5; | |
| uv *= complexity; | |
| count--; | |
| } | |
| return val; | |
| } | |
| // PARAMS | |
| const float glitchFactor = 4.0; // decrease this | |
| void mainImage( out vec4 fragColor, in vec2 fragCoord ) | |
| { | |
| // Normalized pixel coordinates (from 0 to 1) | |
| vec2 uv = fragCoord/iResolution.xy; | |
| vec2 a = vec2(uv.x * (iResolution.x / iResolution.y), uv.y); | |
| vec2 uv2 = vec2(uv.x / 10.0, exp(uv.y)); | |
| // Generate shift factor | |
| float shift = 0.2 * pow(fbm(uv2,5,2.0,3.0),glitchFactor); | |
| // Create a scanline effect | |
| float scanline = abs(cos(uv.y * 400.)); | |
| scanline = smoothstep(0.0, 2.0, scanline); | |
| //shift = smoothstep(0.0, 0.5, shift); | |
| // Glitch 'em | |
| float colR = texture(iChannel0, vec2(uv.x - shift, uv.y)).r; | |
| float colG = texture(iChannel0, vec2(uv.x + shift, uv.y)).g; | |
| float colB = texture(iChannel0, vec2(uv.x + shift, uv.y)).b; | |
| // Mix with the scanline effect | |
| vec3 f = vec3(colR, colG, colB) - (0.1 * scanline); | |
| // Output to screen | |
| fragColor = vec4(f, 1.0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment