/* ***************************   lollipop_swirlLolli_001
 * Copyright (c) 2010 LOLLIPOPSHADERS. All rights reserved.  This program or
 * documentation contains proprietary confidential information and trade
 * secrets of LOLLIPOPSHADERS.  Reverse engineering of object code is prohibited.
 * Use of copyright notice is precautionary and does not imply
 * publication.                  
 *
 *
 *
 * Lollipopshaders
 * www.lollipopshaders.com
 * info@lollipopshaders.com
 *
 *
* lollipop_swirlLolli_001
 *
 * rotates & repeats a simple cross pattern a fixed number of times
 **************************** */


////////// functions

#define pulse(a,b,fuzz,x) (smoothstep((a)-(fuzz),(a),(x)) - smoothstep((b)-(fuzz),(b),(x)))
#define repeat(x,freq)    (mod((x) * (freq), 1.0))
#define rotate2d(x,y,rad,ox,oy,rx,ry) rx = ((x) - (ox)) * cos(rad) - ((y) - (oy)) * sin(rad) + (ox);ry = ((x) - (ox)) * sin(rad) + ((y) - (oy)) * cos(rad) + (oy)
#define blend(a,b,x) ((a) * (1 - (x)) + (b) * (x))

////////// Start shader

surface lollipop_swirlLolli_001 (

    color diffColor = color(0.2,0.3,1.0); /*defaultbasecolor*/
    float diffGain = 1.0;

    color swirlColor = (0.5,0.1,1.0);
    float swirlAngle = 35;
    float swirlFreq = 8;

    color specColor = color(1,1,1);
    float specGain = 1.5;
    float specRoughness = 0.06;


    )
    {
    color surface_color, layer_color;
    color surface_opac, layer_opac;
    float fuzz = 0.05;
    float ss, tt, randRow;

    normal nLocal = normalize(N);
    normal Nf = faceforward(nLocal,I);
    vector vLocal = -normalize(I);

    surface_color = diffColor;
    surface_opac = Os;

    rotate2d(s, t, radians(swirlAngle), 0.5, 0.5, ss, tt);
    ss = repeat(ss, swirlFreq);
    tt = repeat(tt, swirlFreq);

    // vertical

    layer_color = swirlColor;
    layer_opac = pulse(0.35, 0.65, fuzz, ss);
    surface_color = blend(surface_color, layer_color, layer_opac);

    Oi = surface_opac;
    Ci = surface_opac * surface_color;

    // Basic Diffuse Calc //
    if (diffGain > 0)
       {
       Ci = diffuse(nLocal) * Ci * diffGain;
       }


    // Basic Specular Calc //
    if (specGain > 0)
       {
       Ci += specular(Nf,vLocal,specRoughness) * specGain;
       }
    }