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_woodcut.sl < prev   
Encoding:
Text File  |  2008-01-23  |  2.0 KB  |  97 lines

  1. /*
  2.  * 2006-03-13 dan@3-e.net
  3.  *
  4.  */
  5.  
  6. #include "k3d_rmannotes.h"
  7. #include "k3d_noises.h"
  8.   
  9.  surface k3d_woodcut (
  10. string up="y"; 
  11. float ringscale=5; 
  12. float contrast=0.3; 
  13. float brightness=0.75; 
  14. float random=0; 
  15. float nsize=5; ) { 
  16.  
  17. color surface_color, layer_color;
  18. color surface_opac, layer_opac, Cr;
  19. float fuzz = 0.3;
  20. float stripemin, stripemax, tt;
  21. float y, z, i, n, ns;
  22. float tfreq = 50;
  23.  
  24. color illumcolor = 0.0;
  25. float illumination = 0.0;
  26. float Ka = 0.10;
  27. float Kd = 0.70;
  28. float Ks = 0.20;
  29. vector Nf, V; 
  30. point Psh;
  31. float roughness = 0.2;
  32.  
  33. Psh = transform("shader", P);
  34.  
  35. Nf = faceforward( normalize(N), I );
  36. V = -normalize(I); 
  37.  
  38. if (up == "z") { 
  39. z = zcomp(Psh);
  40. z *= ringscale;
  41. tt = mod(z,1);
  42. }
  43. else {
  44. y = ycomp(Psh);
  45. y *= ringscale;
  46. tt = mod(y,1);
  47. }
  48.  
  49. illumcolor = (Ka*ambient() + Kd*diffuse(Nf) + Ks*specular(Nf,V,roughness));
  50. illumination = max(max(comp(illumcolor, 0), comp(illumcolor, 1)), comp(illumcolor, 2));
  51.  
  52. n = 0;
  53. ns = nsize;
  54. for (i = 0; i < 6.0; i += 1.0) {
  55.  
  56. n += snoise(Psh * ns) / ns;
  57. ns *= 2.17;
  58. }
  59.  
  60. illumination = (illumination * contrast) + (1.0 - contrast)/2.0 + 
  61. (brightness - 1.0) + n*random;
  62.  
  63. if (illumination < 0.01) {
  64. surface_color = color (0.0, 0.0, 0.0);
  65. layer_color = 0.0; 
  66. }
  67. else if (illumination > 0.99) {
  68. surface_color = color (1.0, 1.0, 1.0);
  69. layer_color = 1.0;
  70. }
  71. else {
  72. surface_color = color (0.0, 0.0, 0.0);
  73. layer_color = 1.0;
  74. }
  75. surface_opac = 1.0;
  76.  
  77.  
  78. stripemin = 0.5 - smoothstep(0.0, 1.0, illumination)/2.0;
  79. stripemax = 0.5 + smoothstep(0.0, 1.0, illumination)/2.0;
  80. float val = pulse(stripemin, stripemax, fuzz, tt);
  81. layer_opac = color val;
  82. surface_color = blend(surface_color, layer_color, layer_opac);
  83. float color_val = mix(0.0, 1.0, val);
  84. Cr = spline (color_val,
  85. color (0.0, 0.0, 0.0),
  86. color (0.1, 0.05, 0.0),
  87. color (0.8, 0.6, 0.4),
  88. color (1.0, 1.0, 0.8),
  89. color (1.0, 1.0, 1.0),
  90. color (1.0, 1.0, 1.0));
  91.  float spacescale = length(vtransform("shader", normalize(N)));
  92.  vector Ndisp = normalize(N) * (0 / max(spacescale,1e-6));
  93.  P += 0 * Ndisp;
  94.  N = normalize (calculatenormal (P + (1-0)*Ndisp)); 
  95.  Ci = surface_opac * Cr; Oi = 1; }
  96.  
  97.