Skip to content

Instantly share code, notes, and snippets.

@surjikal
Last active November 22, 2018 23:30
Show Gist options
  • Save surjikal/c7c676faf417788cade752e51c0def62 to your computer and use it in GitHub Desktop.
Save surjikal/c7c676faf417788cade752e51c0def62 to your computer and use it in GitHub Desktop.
// Shadertoy Kaleidoscope Shade
// Usage: Pick a texture in channel0
//
// Hacked together using code from:
// https://graphicdesign.stackexchange.com/questions/88165/program-for-image-kaleidoscope-mirror-effect-similar-to-adobe-capture-pattern-tr
precision mediump float;
const float PI = 3.14159265359;
const int numberOfAxis = 6;
int intModulo(float a,float b) {
float m = mod(a, b);
return int(m+0.5);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
float angleFrac = (2.0 * PI) / float(2 * numberOfAxis);
vec2 c = (fragCoord - 0.5 * iResolution.xy) / iResolution.y;
// convert to polar coordinates
float phi = abs(atan(c.y, c.x));
float r = length(c);
int count = int(phi / angleFrac);
phi = mod(phi, angleFrac);
if ( intModulo(float(count),2.0) == 1) {
phi = angleFrac - phi;
}
float x = r * cos(phi);
float y = r * sin(phi);
float frame = iTime * 0.1;
float zoom = 3.5 + cos(iTime * 0.3) / 3.0;
vec2 cc = (vec2(x,y) * zoom) + frame; //map to range [0.0, 1.0]
vec4 color = texture(iChannel0, cc);
fragColor = color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment