Skip to content

Instantly share code, notes, and snippets.

@haxiomic
Last active August 25, 2019 14:20
Show Gist options
  • Save haxiomic/500beb62cdf666f6d56eb980d915e02d to your computer and use it in GitHub Desktop.
Save haxiomic/500beb62cdf666f6d56eb980d915e02d to your computer and use it in GitHub Desktop.
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
vec2 rotate(vec2 p, float radians) {
float c = cos(radians);
float s = sin(radians);
return vec2(p.x * c - p.y * s, p.x * s + p.y * c);
}
// iq's color palette functions: https://www.shadertoy.com/view/ll2GD3
vec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ){
return a + b*cos( 6.28318*(c*t+d) );
}
vec3 rainbow(float x) {
return pal(x, vec3(0.5,0.5,0.5),vec3(0.5,0.5,0.5),vec3(1.0,1.0,1.0),vec3(0.0,0.33,0.67));
}
vec3 g1(float x) {
return pal(x, vec3(0.5,0.5,0.5),vec3(0.5,0.5,0.5),vec3(2.0,1.0,0.0),vec3(0.5,0.20,0.25));
}
vec3 g2(float x) {
return pal(x, vec3(0.5,0.5,0.5),vec3(0.5,0.5,0.5),vec3(1.0,1.0,1.0),vec3(0.0,0.10,0.20));
}
void main() {
float time_s = u_time;
float aspect = u_resolution.x / u_resolution.y;
vec2 uv = gl_FragCoord.xy/u_resolution.xy;
vec2 p = (uv - 0.5) * vec2(aspect, 1.0) * 2.;
// try tweaking these values
float t = time_s * 0.056;
float pScale = 0.424;
float colScale = 2.192;
vec2 q = p * pScale;
// try changing the < 8 to a different number
// sine wave warp, inspried by the amazing @tadokoro
for (int j = 1; j < 8; j++) {
float i = float(j);
q = rotate(q, t * 0.1);
q.x += 0.3 / i * sin(i * 3. * q.y + t + cos((t / 120. * i) * i));
q.y += 0.3 / i * sin(i * 3. * q.x + t + sin((t / 200. * i) * i));
}
// try replacing rainbow with g1 and g2 (these are other color palettes – )
vec3 color = rainbow((q.x + q.y) / colScale);
float gamma = 0.376;
gl_FragColor = vec4(
pow(color, vec3(gamma)),
1.0
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment