"Fossies" - the Fresh Open Source Software Archive

Member "aqsis-1.8.2/shaders/imager/gradient.sl" (24 Aug 2012, 1838 Bytes) of package /linux/privat/aqsis-1.8.2.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  *
    3  * imager gradient
    4  *
    5  * Vertical background gradient between 2 colors TopColor and BottomColor
    6  *
    7  *   This shader produces a gradient background, 
    8  *   TopColor controls the top of the image, 
    9  *   BottomColor controls the bottom of the image 
   10  *   Sharpness controls the narrowness of the transition range.
   11  *   MidPoint controls the approximate location of the midway point of the 
   12  *            transition between colors.
   13  *   Frequency controls the repeat factor; it could be usefull.
   14  *   Angle controls the slope of the transition. (-90.0...90.0)
   15  *
   16  * Author: Michel Joron
   17  */
   18 
   19 imager gradient (
   20   color TopColor=color(0.35,0.35,0.35);
   21   color BottomColor=color(0.85,0.85,0.85);
   22   float Sharpness=0.0;
   23   float MidPoint=0.5;
   24   float Frequency = 1.0;
   25   float Angle = 0.0;
   26 )
   27  {
   28   float diffmid = 1.0 - MidPoint;
   29   float f;
   30   float g;
   31   float x;
   32   float y;
   33   color blend;
   34   color cgc;
   35   uniform float gg[2];
   36 
   37   float lenx, leny;
   38   float resolution[3];
   39 
   40   x = xcomp(P);
   41   y = ycomp(P);
   42   if (Angle != 0.0f) {
   43      float rad = (PI * Angle)/ 180.0; 
   44      float rx = (x * cos(rad)) - (y * sin(rad));
   45      float ry = (x * sin(rad)) + (y * cos(rad));
   46 
   47      x = rx;
   48      y = ry;
   49   }
   50 
   51 
   52   option("Format", resolution); 
   53 
   54   /* El-Cheapo NDC->Raster convertion of P */
   55   lenx = Frequency * x / resolution[0]; 
   56   leny = Frequency * y / resolution[1]; 
   57 
   58   f=pow(leny,log(clamp(diffmid,0.001,0.999))/log(0.5));
   59   g=mix(f,smoothstep(Sharpness*.495,1-Sharpness*.495,f),Sharpness);
   60   blend=mix(TopColor,BottomColor,g);
   61   
   62   gg[0]=1.0; 
   63   cgc=blend;
   64   
   65   if (option("Exposure",gg)==1) {
   66     setcomp(cgc,0,pow(comp(blend,0)*gg[0],1.0/gg[1]));
   67     setcomp(cgc,1,pow(comp(blend,1)*gg[0],1.0/gg[1]));
   68     setcomp(cgc,2,pow(comp(blend,2)*gg[0],1.0/gg[1]));
   69   }
   70 
   71   blend = (1.0 - alpha)  * cgc;
   72   cgc = Ci + blend;
   73   alpha=1.0; Ci=cgc;
   74   Oi=alpha;
   75  }