Files
glsl_playground/weird/flow_noise.glsl
2017-06-12 18:52:32 -04:00

87 lines
1.9 KiB
GLSL

#ifdef GL_ES
precision mediump float;
#endif
#define NUM_OCTAVES 5
#define TAU 6.28318530718
uniform vec2 u_resolution;
uniform float u_time;
float random (vec2 _st) {
return fract(sin(dot(_st.xy, vec2(12.9898,78.233)))*43758.5453123);
}
float noise (vec2 _st) {
vec2 i = floor(_st);
vec2 f = fract(_st);
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
float fbm(vec2 _st) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
mat2 rot = mat2(cos(0.5), sin(0.5),
-sin(0.5), cos(0.50));
for (int i = 0; i < NUM_OCTAVES; ++i) {
v += a * noise(_st);
_st = rot * _st * 2.0 + shift;
a *= 0.5;
}
return v;
}
vec3 polygon(int n, float size, vec2 pos, vec3 color, float rot) {
float e = 0.01;
vec2 st = gl_FragCoord.xy/u_resolution.xy;
st.x *= u_resolution.x/u_resolution.y;
st = (st-pos)*2.;
float a = atan(st.x,st.y)+rot;
float r = TAU/float(n);
float d = cos(floor(.5+a/r)*r-a)*length(st);
return color-smoothstep(size-e,size+e,d);
}
vec3 _m(vec3 c1, vec3 c2, float v) {
return mix(c1, c2, clamp(v, 0., 1.));
}
void main() {
vec2 st = gl_FragCoord.xy/u_resolution.xy*3.;
vec3 color = vec3(0.0);
float _f = fbm(st+u_time*0.2);
vec2 q = vec2(_f);
_f = fbm(st+1.*q);
vec2 r = vec2(_f);
float f = fbm(st+r);
color = _m(vec3(0.1,0.62,0.67),vec3(0.67,0.67,0.5), f);
color = mix(color, vec3(0,0,0.16), length(q));
color = mix(color, vec3(0.67,1,1), length(r.x));
float resmin = min(u_resolution.x, u_resolution.y);
vec2 size = (u_resolution/2.)/resmin;
color += polygon(4, 0.7, size, -vec3(0.3), 0.8);
gl_FragColor = vec4(color,1.);
}