// created by florian berger (flockaroo) - 2021
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
//
// tiny voxels
//
// ...not quite as minimal as on twigl (266 chars)
// https://twitter.com/flockaroo/status/1466494447525539843
//

/*
void mainImage( out vec4 o, in vec2 F )
{
#define C(p) max(c=abs(p),max(c.y,c.z)).x
#define L(N) for(int i=0;i<N;i++){
// had to trick a bit on the rotation - only diagonal rotation (full blown up rotate/axis func is quite big)
   //vec3 e=cos(iTime-vec3(0,1.6,-1.6));e.yz/=sqrt(3.); mat3 R=mat3(e,e.zxy,e.yzx)+(1.-e.x)/3.;
   float e=cos(iTime),a=sin(iTime)*.58; mat3 R=mat3(e,a,-a,-a,e,a,a,-a,e)+(1.-e)/3.;
   vec3 p=R*vec3(0,0,40),v=R*vec3(F/iResolution.y-.5,1),m,c,d;
   L(99)
       d.x=9.;
       L(8)
           m=floor(p)+vec3(i&1,i/2&1,i/4&1);
           d=min(d,C(R*m)>9.?.5:C(p-m)-.4);
       }
       p-=d.x*v;
   }
   o=abs(p*R).zzzz*.07;
}
*/

// fabrice's breakdown - minus another 6 chars (vec3 d now float (prev e))
#define C(p) max(c = abs(p), max(c.y, c.z)).x//
#define L for(int i=0; i++ <

void mainImage(out vec4 o, vec2 F)
{
    float d = cos(iTime), a = sin(iTime) * .58;
    mat3 R = mat3(d, a, -a, -a, d, a, a, -a, d) + (1. - d) / 3.;
    vec3 p = R * vec3(0, 0, 40),
    v = R * vec3(F / iResolution.y - .5, 1), m, c;
    L 99; p -= d * v ) {
        d = 9.;
        L 8; d = min(d, C(R * m) > 9. ? .5 : C(p - m) - .4) )
          m = floor(p) + vec3(i&1,i/2&1,i/4&1);
    }

    //o += abs(p * R).z * .07 - o;
    o = abs(p * R).zzzz * .07;
    // bit longer, but i also like this one - gives some central gradent on the depth field
    //o += abs(dot(p,v)) * .07 - o;
}
