home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / surface / k3d_leather.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  6.7 KB  |  218 lines

  1. /*
  2.  * JexSkin.sl
  3.  *
  4.  * I have done this shader from JMredapple.sl for RMR
  5.  *
  6.  * add some parameter, change many thing
  7.  *
  8.  *and offer you this shader, it was done (JMredapple.sl) by Jonathan Merritt
  9.  *without hes shader i wouldnt be able to do mine so send him flowers :)
  10.  *
  11.  *    re-autor istarion@3dvf.net    web site http://istarion.3dvf.net
  12.  *
  13.  *     old-autor jmerritt@warpax.com   :-)
  14. */
  15.  
  16.  
  17. surface
  18. k3d_leather (
  19.     float Ks = .2;           /* Specular reflection coeff.    */
  20.     float Kd = 1;            /* Diffuse reflection coeff.     */
  21.     float Ka = 1;             /* Ambient light coeff.          */
  22.     float Kr = .2;             /* Mirror-like reflection coeff. */
  23.     float roughness = .1;     /* Specular roughness param.     */          
  24.     color red   = color(0.8,0.6,0.4);
  25.     color dred  = color(0.5,0.3,0.10);
  26.     color green = color(0.8,0.6,0.4);
  27.     color brown = color(0.5,0.3,0.10);
  28.     color black = color(0.5,0.3,0.10);
  29.     
  30.     /*BLOTCH sont les zebrure*/
  31.     
  32.     float BLOTCH_TCF = 5;        /*zebrure sur la peau*/
  33.     float BLOTCH_SF = 5;        /*definis le s */
  34.     float BLOTCH_TF = 5;        /*definis le s */
  35.     float paramdisp = 1;
  36.     float txtscale = .05;         /* Ugly kludge (see above...)    */
  37.     color specularcolor = 1;      /* Specular reflection color     */
  38.  
  39.     
  40. )
  41. {
  42.     /*
  43.      * Shader variables
  44.      */
  45.     vector Nf, V, Rdir;
  46.     point PP, newP;
  47.     float base_turb, blotch_turb, disp_turb;
  48.     float small_noise, blotch, speck, disp = 0, blackness;
  49.     color cs, small_speckle, base_color, reflect;
  50.  
  51.  
  52.  
  53.  
  54.  
  55.     /*
  56.      * Standard settings
  57.      */
  58.     PP = transform("shader", P);
  59.     V = normalize(-I);
  60.  
  61.  
  62.     /*
  63.      * Pick the base color for the apple.
  64.      *
  65.      * The base color consists of patches of pure green,
  66.      * and patches of finely speckled red and green. These
  67.      * are set up so that the poles of the apple (as "t"
  68.      * goes to 1 or 0) are colored more and more green.
  69.      *
  70.      * The apple geometry is such that lines of constant
  71.      * "t" are lines of longditude (from pole to pole).
  72.      * The constants T1 - T4 specify locations of the
  73.      * start of 'greenness' toward the poles.
  74.      */
  75.     #define BASE_SF          1      /* s-factor for big noise          */
  76.     #define BASE_TF          1      /* t-factor for big noise          */
  77.     #define BASE_NF          100    /* scaling factor for small noise  */
  78.     #define BASE_NOISE_AMP   0.2    /* small noise color mix amplitude */
  79.     #define BASE_GRC         0.4    /* shift factor for more red       */
  80.     #define T1               0.0    /* t < T1 is pure green            */
  81.     #define T2               0.18   /* lerp s.t. T1->T2 => green->red  */
  82.     #define T3               0.8    /* T2->T3 => red can exist here    */
  83.     #define T4               1.0    /* lerp s.t. T3->T4 => red->green  */
  84.                                     /* t > T4 is pure green            */
  85.     base_turb = noise(BASE_SF*sin(2*PI*s) + PI + label,
  86.                       BASE_TF*t + label);
  87.     base_turb = pow(base_turb, (1/redness));
  88.     small_noise = snoise(BASE_NF*PP*txtscale/TSCALE);
  89.     small_speckle = mix(red, green, BASE_GRC+
  90.                         (small_noise*BASE_NOISE_AMP));
  91.     if (t < T1)
  92.         base_turb = 0;
  93.     else if (t >= T1 && t < T2)
  94.         base_turb *= (t-T1)/(T2-T1);
  95.     else if (t >= T3 && t < T4)
  96.         base_turb *= (T4-t)/(T4-T3);
  97.     else if (t >= T4)
  98.         base_turb = 0;
  99.     base_color = spline(base_turb, green, green,
  100.                         small_speckle, small_speckle,
  101.                         small_speckle);
  102.  
  103.  
  104.     /*
  105.      * Pick the blotch color.
  106.      *
  107.      * The blotch color is finally determined by mixing,
  108.      * using the blotching coefficient "blotch". This
  109.      * section sets that coefficient, using a funky yet
  110.      * really simple noise routine.
  111.      */
  112.     /*#define BLOTCH_SF          20   s-factor for blotches  */
  113.     /*#define BLOTCH_TF          15   t-factor for blotches  */
  114.     /*#define BLOTCH_TCF         0     zebrure                */
  115.     #define BLOTCH_DELTA       0.1  /* 'nother scaling kludge */
  116.     #define BLOTCH_SPECK_COEFF 0.3  /* blotch specking coeff  */
  117.     blotch_turb = noise(BLOTCH_SF*sin(2*PI*(s+.1234)) + PI + label,
  118.                         BLOTCH_TF*t + label) + BLOTCH_DELTA;
  119.     blotch = pow(blotch_turb, 1.3) * BLOTCH_TCF * 
  120.              pow(base_turb, 2);
  121.     blotch = blotch * (1+small_noise) +
  122.              small_noise * BLOTCH_SPECK_COEFF;
  123.     if (blotch > 1) blotch = 1;
  124.  
  125.  
  126.     /*
  127.      * Set the brown specking.
  128.      *
  129.      * The apple has brown speckles on it, set by mixing
  130.      * using the speckling coefficient "speck". These
  131.      * specks are very dot-like in nature, and this
  132.      * dottiness technique is stolen from LG's starfield 
  133.      * shader.
  134.      */
  135.     #define SPECK_NF        0     /* un dented dessus que je met a zero*/    
  136.     #define SPECK_CUTOFF    .45   /*Cutoff for 'tops' of specks*/ 
  137.     speck = pow(smoothstep(SPECK_CUTOFF, 1,
  138.                 noise(SPECK_NF*PP*txtscale/TSCALE)), 3);
  139.  
  140.     /*
  141.      * Determine where the apple goes black at the poles.
  142.      * This simulates the spots where the stalk would be
  143.      * attached, and where the wierd bit at the very bottom
  144.      * is.
  145.      */
  146.     #define BEDGE  .0
  147.     #define BWIDTH .0
  148.     blackness = 1-(smoothstep(BEDGE, BEDGE+BWIDTH, t)*
  149.                    smoothstep(BEDGE, BEDGE+BWIDTH, 1-t));
  150.  
  151.  
  152.     /*
  153.      * Combine what we have so far to set the surface
  154.      * color.
  155.      */
  156.     cs = mix(base_color, dred, blotch);
  157.     cs = mix(cs, brown, speck);
  158.     cs = mix(cs, black, blackness);
  159.  
  160.  
  161.     /*
  162.      * Set the shading surface normal.
  163.      *
  164.      * Here we set the surface normal to fix up the specular
  165.      * highlights. We'd like them perturbed by the small
  166.      * noise, affected a little by the brown specks, and
  167.      * also dented a bit (alas, no real apples are perfectly
  168.      * un-dented).
  169.      */
  170.     #define DISP_SF     10             /* s-factor for dent noise */
  171.     #define DISP_TF     30             /* t-factor for dent noise */
  172.     #define DISP_DENT_AMP     (1/15)   /* dent amplitude          */
  173.     #define DISP_SMNOISE_AMP  (1/1000) /* small noise amplitude   */
  174.     #define DISP_SPECK_AMP    (1/40)   /* speckle disp. amplitude */
  175.     disp += noise(DISP_SF*sin(2*PI*s) + PI + label,
  176.                   DISP_TF*t + label) * DISP_DENT_AMP * txtscale / TSCALE;
  177.     disp += small_noise * DISP_SMNOISE_AMP * txtscale / TSCALE;
  178.     disp -= speck * DISP_SPECK_AMP * txtscale / TSCALE;
  179.     disp = paramdisp * disp;
  180.     newP = calculatenormal(P + disp * normalize(N));
  181.     Nf = faceforward(normalize(newP), I);
  182.  
  183.  
  184.     /*
  185.      * 'Mirror' reflections
  186.      *
  187.      * Here, we raytrace for the slight mirrored reflections
  188.      * in the surface of an apple. They don't add much, but
  189.      * may be needed for the 'perfect' apple :-).
  190.      *
  191.      * Note: You'll need Larry Gritz's raytrace helper files
  192.      * for this bit!
  193.      */
  194. #ifdef USE_LG_RAYTRACE
  195.     if (Kr > .01) {
  196.         Rdir = normalize(reflect(normalize(I), Nf));
  197.         reflect = RayTrace(P, Rdir, 0, 1, 1);
  198.     } else {
  199.         reflect = 0;
  200.     }
  201. #else
  202.     reflect = 0;
  203. #endif
  204.  
  205.  
  206.     /*
  207.      * Combine everything to get Ci, in the standard form.
  208.      */
  209.     Oi = Os;
  210.     Ci = Os * (cs * (Ka*ambient() + Kd*diffuse(Nf)) +
  211.                specularcolor * (Kr * reflect +
  212.                                 Ks * specular(Nf, V, roughness)));
  213.         
  214. }
  215.  
  216.  
  217.  
  218.