Last active
July 29, 2022 23:39
-
-
Save keijiro/07eea800c0758a7f81871fb9d81f7cc1 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; | |
mat2 rotate(float x) | |
{ | |
vec2 sc = vec2(sin(x), cos(x)); | |
return mat2(sc.y, sc.x, -sc.x, sc.y); | |
} | |
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 aspect = resolution.x / resolution.y; | |
// ellipse | |
float r = length((uv - 0.5) * vec2(aspect, 1)); | |
float c = 1 - step(spectrum.x, r); | |
// displacement | |
vec2 d = vec2(cnoise(vec3(0.13 - uv * 9, +time)), | |
cnoise(vec3(3.17 + uv * 9, -time))) * 0.275; | |
d = rotate(time + uv.y * 7) * d; | |
uv += d / vec2(aspect, 1); | |
// feedback | |
vec3 duv = vec3(4, 4, 0) / resolution.xyy; | |
float fb = texture(prevFrame, uv).r; | |
fb += texture(prevFrame, uv - duv.xz).r; | |
fb += texture(prevFrame, uv + duv.xz).r; | |
fb += texture(prevFrame, uv - duv.zy).r; | |
fb += texture(prevFrame, uv + duv.zy).r; | |
c += fb / 5.03; | |
// color gradient | |
float c1 = 0.5 - cos(c * 8.12 + 0.12 + time * 1.21) * 0.5; | |
float c2 = 0.5 - sin(c * 9.33 + 1.34 + time * 0.73) * 0.5; | |
fragColor = vec4(1, c1, c2, 0) * c; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awsome. Thanks i play the code on @kodelife