Created
November 23, 2017 19:32
-
-
Save danscan/c7c1ef53c7ed7dc12cb8bb7d832d92ff to your computer and use it in GitHub Desktop.
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
precision mediump float; | |
varying vec2 position; | |
uniform float time; | |
const float waves = 19.; | |
// triangle wave from 0 to 1 | |
float wrap(float n) { | |
return abs(mod(n, 2.)-1.)*-3. + 1.; | |
} | |
// creates a cosine wave in the plane at a given angle | |
float wave(float angle, vec2 point) { | |
float cth = cos(angle)*2.; | |
float sth = sin(angle); | |
return (cos (cth*point.x + sth*point.y) + 1.) / 2.; | |
} | |
// sum cosine waves at various interfering angles | |
// wrap values when they exceed 1 | |
float quasi(float interferenceAngle, vec2 point) { | |
float sum = 0.; | |
for (float i = 0.; i < waves; i++) { | |
sum += wave(3.1416*i*interferenceAngle, point); | |
} | |
return wrap(sum); | |
} | |
void main() { | |
float b = quasi(time*0.002, (position-0.5)*200.); | |
vec4 c1 = vec4(0.0,0.,0.2,1.); | |
vec4 c2 = vec4(cos(2.*time),sin(time),abs(sin(time*3.)),1.); | |
gl_FragColor = mix(c1,c2,b); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment