#define C cos
#define R iResolution

void mainImage(out vec4 O, vec2 I) {
    float t = iTime;
    vec3 d = normalize(vec3((2.*I-R.xy)/R.y,-1));// Ray direction
    vec3 p = 5.*(vec3(C(.5*t-1.5), -.5*t, C(.5*t)) + d);// Ray origin
    
    vec4 a = 7.*C(vec4(.2,.3,.5,0)*t);// Palette
    for(O*=0.; O.a<100.; O.a++) {
        float x = dot(sin(p), C(p.yzx));// Gyroid
        O += .003 * (a.w*=.98) * step(0.,x) * (.5+.5*C(t+a*x));// Accumulate color
        //O += .01 * abs(C(2.*x)) * (.5+.5*C(t+a*x));// Accumulate color: alternative
        //O += .003 * (a.w*=.98) * step(abs(mod(x+2.,1.)-1.),.3)*(.5+.5*C(t+a*x));// Accumulate color: alternative
        p += .1*d;// March
    }
}
