Webcam kaleidoscope

glint · Examples · Tutorials · Gallery

Mirrors texture slot 0: attach your webcam, a video or an image in the Inputs panel.

Webcam kaleidoscope: a GLSL shader

An example in glint, a free live shader editor in the browser: the GLSL code floats over the running picture and recompiles as you type.

The code

One pass, in GLSL.

fragment shader

#version 300 es
precision highp float;

uniform float time;
uniform vec2 resolution;
uniform sampler2D texture0;
uniform float segments;

in vec2 v_texcoord;
out vec4 fragColor;

void main() {
    vec2 p = (gl_FragCoord.xy - 0.5 * resolution) / resolution.y;
    float r = length(p);
    float a = atan(p.y, p.x) + time * 0.1;
    float seg = 6.2831 / segments;
    a = mod(a, seg);
    a = abs(a - seg * 0.5);
    vec2 uv = vec2(cos(a), sin(a)) * r * 0.8 + 0.5 + 0.05 * vec2(sin(time * 0.3), cos(time * 0.2));
    vec3 col = texture(texture0, uv).rgb;
    // With nothing attached, show a pattern instead of black.
    if (dot(col, col) == 0.0) col = 0.5 + 0.5 * cos(vec3(0.0, 2.0, 4.0) + uv.xyx * 12.0 + time);
    col *= smoothstep(1.0, 0.2, r);
    fragColor = vec4(col, 1.0);
}

More Starters examples

Feedback trails · Audio spectrum · Vertex art · Lit mesh · Shadertoy style · Plasma · Tunnel · Mandelbrot & Julia