/* This is the Final Palm Shader! */
surface
finalPalmShader(float    Ka = 1,            /* ambient brightness */
                    Kd = 0.5,        /* basic brightness */
                    Ks = 0.9,        /* hilite brightness */
                    Km = 8,
                    roughness = .13,/* hilite spread */
                    translucency = .75,
                    veinFreq = 35, /* [0 50] */ 
                    veinIntensity = .09,
                    noiseFreq = 300,
                    noiseAmp = 2,
                    bumpFeq = 50,
                    bumpAmp = 2
                    ;
            color     hilitecolor = 1,    /* hilite color */
                    baseColor = (0.772,0.835,0.462),
                    frontColor = (0.654,0.835,0.309),
                    backColor = (0.513,0.843,0.572),
                    tipColor = (0.909,0.768,0.333)
                    
             )
{
color    ambientcolor, diffusecolor, speccolor,
        surfcolor = .9,
/*---------------------  Color Ramps  ----------------------------------------------*/
        backRamp = spline
                (t, baseColor, baseColor,
                backColor, backColor, backColor, backColor, backColor, 
                tipColor, tipColor, tipColor, tipColor, tipColor, tipColor, tipColor),
        frontRamp = spline
                (t, baseColor, baseColor,
                frontColor, frontColor, frontColor, frontColor, frontColor, 
                tipColor, tipColor, tipColor, tipColor, tipColor, tipColor, tipColor);
                ;
/* Veins */
float ss = mod(s * veinFreq,1);                
varying float stripes = (smoothstep(0.2,0.25,ss) - smoothstep(0.75,1,ss)) * veinIntensity;
  
/* STEP 1 - make a copy of the surface normal one unit in length */
normal    n = normalize( N);
normal    nf = faceforward(n, I);
  
/* STEP 2 - set the apparent surface opacity */
Oi = Os;
  
/* STEP 3 - calculate the lighting components */
  
diffusecolor = Kd * diffuse(nf);
  
/* Translucency effects are calculated here_______*/
color    diffuseFront = diffuse(nf);
color    diffuseRear = diffuse(-nf);
color    diffuseTotal = (diffuseFront * frontRamp) + 
        (diffuseRear * translucency * backRamp - (stripes * 1.01));
  
vector    i = normalize(-I);
  
/* --------------  Adding Noise to Speular to break it up  ------------ */
float specNoise = noise (s * noiseFreq, t * noiseFreq) * noiseAmp;
speccolor = Ks * specular(nf, i, roughness) * hilitecolor * specNoise;
  
/*  -------------------------- Bump ----------------------------------- */
float bumpNoise = noise (s * bumpFeq, t * bumpFeq) * bumpAmp;
N = calculatenormal(P + normalize(N) * bumpNoise * Km);
  
/* STEP 4 - calculate the apparent surface color */
Ci = Oi * Cs * surfcolor * ( diffuseTotal + speccolor + stripes)+ stripes;
  
}