// Fork of "XOR Towers in Fog & Rain" by GregRostami. https://shadertoy.com/view/7lsXR2
// Thanks to P_Malin's SmallStars code for the rain.
// Place a "//" in front of each line with a "*" in the comments to turn that feature off. 

void mainImage(out vec4 o, vec2 u)
{
     vec2 R = iResolution.xy;
    ivec4 b = ivec4(o -= o);                   // Initialize b=0
    float t = .1*iTime, B, h, z, i=0.;
     vec4 g;
            
    u =
        (2. + cos(t)) *                        // * Camera push in/out 
        (u+u-R)/R.y                            //   Center coordinates
        * mat2( cos( vec4(0,33,55,0) - .1*t))  // * Rotate camera
        ;
        
    z = (h = cos(B = ceil(atan(u.x, u.y) * 2e2))) / dot(u,u);  //Variables for Rain
    
    for (;i<3.;)
    g += pow(texture(iChannel2,.5*u + .1*sin(t/.1+(i+=.04)+3.*u) ),g-g+8.); // Ground ghosts
            
    for (; (b.x^b.y^b.z)%99 > b.z-8 ; )        // The XOR function for towers!!
        b = ivec4(u * o.a + 2e2
                + vec2(7,30)*t                 // * Move camera (x,y)
                , o+=.1 );                     // Increment layer
                
    o =
        o.a < 8.1 ? .1+sin(t/.1)*vec4(b%32 & b.x%9 & b.z%9) :  // * Blinking lights
        o/80. - .02 *                                          // * Distance fog
        vec4(b%3)                                              // * Building colors
        + .2*(o.a > 17. ? vec4( int(.5+sin(float(b.x/2 + b.y + 2*b.z))) & b.x & b.y & int(.5+sin(4.*o.a-3.4)) ) : g-g) // * Windows
        + (o.a > 50. ? g*vec4(.15,.4,1,0) : g-g)               // * Ground ghosts
        + .06*texture( iChannel1, .02*u - .03*t ).r            // * Moving fog
        + .01*max(exp(fract(h * B - z + t+t) * -1e2) / z,0.)   // * Rain
        ;
}
