/*
    "LED" by @XorDev
    
    A little shader inspired by LED cubes.
    
    Tweet: twitter.com/XorDev/status/1588987185763880961
    Twigl: t.co/wJxCI4wLwa
    
    <300 chars playlist: shadertoy.com/playlist/fXlGDN
*/

void mainImage(out vec4 O, vec2 I)
{
    //Clear fragColor
    O = vec4(0);
    
    //Initialize LED position and rotated position vectors
    vec3 p, q,
    //Save resolution for scaling/centering
    r = iResolution,
    //Time (yz are approximate ratios of pi/2)
    t = iTime+vec3(0,11,33);
    
    //Loop through 64 LEDs, adding LED color
    for(int i=0; i<64; O.rgb+=(sin(p.x+t*vec3(3,4,5))+1.)*
        //Brightness with flickering from 3D texture
        texture(iChannel0,(p+t)*.2).r/5e2*(2.3-q.z)/
        //Diminish with linear distance (and project 3D LED to 2D)
        length((I+I-r.xy)/r.y+q.xy/(4.+q.z)))
        
        //Compute LED 3D position from i
        p = vec3(i&3,i/4&3,i++/16) - 1.5,
        //Rotate about y-axis
        q = p, q.zx*=mat2(cos(t.xyzx));
}
