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_translucency.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.7 KB  |  131 lines

  1. /*
  2. *
  3. *
  4. * Shader: Double side translucency shader
  5. *
  6. * Author: Xavier Matia Bernasconi - The Chimney Pot -
  7. *
  8. *
  9. *
  10. *
  11. * Description:  It's possible to use one different color and
  12. *        translucency texture for each side of a flat object
  13. *        It also implement the Stephen H. Westin velvet
  14. *        illuminance loop.    
  15. *        
  16. *
  17. * Tips & Tricks: The transTx and TransTx2 values can be used,
  18. *         when a texture is present, as scale value for the texture.
  19. *         Don't use white on the translucency texture.
  20. *         It burns out the surface color.
  21. *         
  22. * Notes: Please send me any kind of suggestions or bugs.
  23. *     If you use it in some production please email me the result.
  24. *     I'll really appriciate it.
  25. *
  26. * Shader birthdate: 31-08-2000
  27. *
  28. *
  29. */
  30.  
  31. #include "k3d_functions.h"
  32.  
  33. surface k3d_translucency(float Ka = 1;
  34.             float Kd = 1;
  35.             float Ks = 0.5;
  36.             float roughness = 0.1;
  37.             color specularcolor = 1;
  38.             color sheen = 0.25;
  39.             float blurcolorTx = 0;
  40.             string colorTx = "";
  41.             float blurcolorTx2 = 0;
  42.             string colorTx2 = "";
  43.             float colorS = 0;
  44.             float colorT = 0;
  45.             float colorScaleS = 1;
  46.             float colorScaleT = 1;
  47.             float transTx = 0.8;
  48.             float transblurTx = 0;
  49.             string transTex = "";
  50.             float transTx2 = 0.8;
  51.             float transblurTx2 = 0;
  52.             string transTex2 = "";
  53.             )
  54. {
  55.     /*XMB VARIABLE */
  56.     
  57.     float ss = (s - colorS) / colorScaleS;
  58.     float tt = (t - colorT) / colorScaleT;
  59.     
  60.     /*Velvet illuminance loop variable*/
  61.  
  62.     vector H;
  63.     vector ln;
  64.     color shiny;
  65.     float cosine, sine;
  66.  
  67.  
  68.  
  69.     /*XMB vector assignment*/
  70.     
  71.     normal Nf = faceforward(normalize(N),I);
  72.     vector V = -normalize(I);
  73.     
  74.     /*Color texturing of different side*/
  75.     
  76.     color Ct;
  77.  
  78.     if (Nf.N>0)
  79.     {
  80.         if (colorTx != ""){
  81.             float opac = float texture(colorTx[3], ss, tt);
  82.             Ct = color texture(colorTx, ss, tt, "blur", blurcolorTx) + (1-opac)*Cs;
  83.         } else Ct = Cs;
  84.     }else
  85.     {
  86.          if (colorTx2 != ""){
  87.             float opac = float texture(colorTx2[3], ss, tt);
  88.             Ct = color texture(colorTx2, ss, tt, "blur", blurcolorTx2) + (1-opac)*Cs;
  89.         } else Ct = Cs;
  90.     }
  91.     
  92.     float Kt;
  93.     
  94.     /*Translucency texturing of different side*/
  95.  
  96.     if (Nf.N>0)
  97.     {
  98.         if (transTex != ""){
  99.              Kt = float texture(transTex[0], ss, tt, "blur", transblurTx);
  100.              Kt = Kt * transTx;
  101.         } else Kt = transTx;
  102.     }else
  103.     {
  104.         if (transTex2 != ""){
  105.              Kt = float texture(transTex2[0], ss, tt, "blur", transblurTx2);
  106.              Kt = Kt * transTx2;
  107.         } else Kt = transTx2;
  108.     }
  109.     
  110.     
  111.     
  112.  
  113.     /*Velvet illuminance loop*/
  114.     
  115.     shiny = 0;
  116.     
  117.     illuminance (P, Nf, 1.57079632679489661923){
  118.         ln = normalize(L);
  119.         cosine = max (-Nf.V,0);
  120.         shiny += pow (cosine, 1.0/roughness) / (ln.Nf) * Cl * sheen;
  121.         cosine = max (Nf.V, 0);
  122.         sine = sqrt (1.0-sqr(cosine));
  123.         shiny += pow(sine, 10.0)*ln.Nf * Cl*sheen;
  124.     }
  125.  
  126.         
  127.     Ci = Ct * (Ka*ambient() + Kd*diffuse(Nf) + Kt*diffuse(-Nf)) + Ks*specular(Nf,V,roughness) + shiny;
  128.     
  129.     Oi = Os; Ci *= Oi;
  130. }    
  131.