-
-
Save 4ydx/02ac123bfd60cc41b812f304d373d853 to your computer and use it in GitHub Desktop.
KodeLife fragment shader sketch
This file contains 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
#version 150 | |
uniform float time; | |
uniform sampler2D prevFrame; | |
uniform vec2 resolution; | |
uniform vec3 spectrum; | |
out vec4 fragColor; | |
vec3 fade(vec3 x) { return x * x * x * (x * (x * 6 - 15) + 10); } | |
vec3 phash(vec3 p) | |
{ | |
p = fract(mat3(1.2989833, 7.8233198, 2.3562332, | |
6.7598192, 3.4857334, 8.2837193, | |
2.9175399, 2.9884245, 5.4987265) * p); | |
p = ((2384.2345 * p - 1324.3438) * p + 3884.2243) * p - 4921.2354; | |
return normalize(fract(p) * 2 - 1); | |
} | |
float cnoise(vec3 p) | |
{ | |
vec3 ip = floor(p); | |
vec3 fp = fract(p); | |
float d000 = dot(phash(ip), fp); | |
float d001 = dot(phash(ip + vec3(0, 0, 1)), fp - vec3(0, 0, 1)); | |
float d010 = dot(phash(ip + vec3(0, 1, 0)), fp - vec3(0, 1, 0)); | |
float d011 = dot(phash(ip + vec3(0, 1, 1)), fp - vec3(0, 1, 1)); | |
float d100 = dot(phash(ip + vec3(1, 0, 0)), fp - vec3(1, 0, 0)); | |
float d101 = dot(phash(ip + vec3(1, 0, 1)), fp - vec3(1, 0, 1)); | |
float d110 = dot(phash(ip + vec3(1, 1, 0)), fp - vec3(1, 1, 0)); | |
float d111 = dot(phash(ip + vec3(1, 1, 1)), fp - vec3(1, 1, 1)); | |
fp = fade(fp); | |
return mix(mix(mix(d000, d001, fp.z), mix(d010, d011, fp.z), fp.y), | |
mix(mix(d100, d101, fp.z), mix(d110, d111, fp.z), fp.y), fp.x); | |
} | |
void main(void) | |
{ | |
vec2 uv = gl_FragCoord.xy / resolution; | |
float amp = spectrum.x; | |
// horizontal line | |
float c = 1 - step(0.1 * amp, abs(uv.y - 0.5)); | |
c *= amp * 2 * abs(cnoise(vec3(uv.xx, time * 8))); | |
// displacement | |
amp += 0.2; | |
uv += vec2( | |
cnoise(vec3(uv * 4, -time * 2)) * 0.08 * amp, | |
cnoise(vec3(uv.x * 7, time * 2, time * 2)) * 0.15 * amp | |
); | |
// feedback | |
c += texture(prevFrame, uv).b * 0.997; | |
// color gradient | |
float c1 = 0.5 + sin(c * 12.12 + time * 1.11) * 0.5; | |
float c2 = 0.5 + sin(c * 17.33 + time * 1.73) * 0.5; | |
fragColor = vec4(c1, c2, 1, 0) * c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment