Last active
December 13, 2015 23:09
-
-
Save sheepmaster/4989330 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #ifdef GL_ES | |
| precision mediump float; | |
| #endif | |
| uniform float time; | |
| uniform vec2 resolution; | |
| const int k = 3; | |
| const int stripes = 30; | |
| vec3 hsvToRgb(float h, float s, float v) { | |
| float c = s * v; | |
| float hScaled = h / 60.0; | |
| int index = int(h); | |
| float x = c * (1.0 - abs(mod(hScaled, 2.0) - 1.0)); | |
| float m = v - c; | |
| vec3 rgb = vec3(m); | |
| if (index == 0) { | |
| rgb += vec3(c, x, 0); | |
| } else if (index == 1) { | |
| rgb += vec3(x, c, 0); | |
| } else if (index == 2) { | |
| rgb += vec3(0, c, x); | |
| } else if (index == 3) { | |
| rgb += vec3(0, x, c); | |
| } else if (index == 4) { | |
| rgb += vec3(x, 0, c); | |
| } else if (index == 5) { | |
| rgb += vec3(c, 0, x); | |
| } | |
| return rgb; | |
| } | |
| void main( void ) { | |
| float PI = 4.0 * atan(1.0); | |
| vec2 res2 = resolution/2.0; | |
| float phase = 2.0*PI*time/3.0; | |
| vec2 xy = (gl_FragCoord.xy - res2); | |
| float theta = atan(xy.y, xy.x); | |
| float r = log(length(xy*xy)); | |
| vec3 c = vec3(0.0); | |
| for (int t = 0; t < k; t++) { | |
| float tScaled = PI*float(t)/float(k); | |
| float ct = cos(tScaled); | |
| float st = sin(tScaled); | |
| //c+=cos((theta*ct-r*st)*float(stripes)+phase); | |
| // use the following line for cartesian crystals: | |
| vec3 col = hsvToRgb(2.0*degrees(tScaled), 1.0, 1.0); | |
| col *= cos((xy.x*ct+xy.y*st)*2.0*PI*float(stripes)/resolution.x-phase); | |
| col += 1.0; | |
| col /= 2.0; | |
| c += col; | |
| } | |
| c /= float(k); | |
| gl_FragColor = vec4(c, 1.0); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment