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

  1.  
  2.  
  3. surface k3d_mottled_clay (
  4.  
  5. float Ka1=0.8; 
  6. float Kd1=0.5; 
  7. float roughness1=0.1; 
  8. color claycol1=color(0.88,0.74,0.42); 
  9. color claycol2=color(0.59,0.37,0.19); 
  10. float stucco_freq3=15; 
  11. float transp=1; ) 
  12. {
  13. /** Surface main-code start **/
  14.  
  15. point PP6=point(0.0,0.0,0.0); 
  16. /** Basic fractal **/
  17. point temp_PP6;
  18. if (PP6 == point(0.0,0.0,0.0)) {temp_PP6=P;} else {temp_PP6=PP6;}
  19. temp_PP6=transform("shader",P);
  20. uniform float i6;
  21. float size6,sum6,area6;
  22. sum6 = 0;
  23. size6 = 1;
  24. area6 = sqrt(area(temp_PP6));
  25. while(area6<size6)
  26. {
  27. sum6 += size6*noise(temp_PP6/size6);
  28. size6 /= 2;
  29. }
  30. /*** stucco pattern code ***/ 
  31. float magnitude3; 
  32. point PP3; 
  33. PP3 = transform ("shader", P); 
  34. magnitude3 = pow (noise(PP3 * stucco_freq3), sum6);
  35. color
  36. LocIllumOrenNayar (normal N; vector V; float roughness;)
  37. {
  38. /* Surface roughness coefficients for Oren/Nayar's formula */
  39. float sigma2 = roughness * roughness;
  40. float A = 1 - 0.5 * sigma2 / (sigma2 + 0.33);
  41. float B = 0.45 * sigma2 / (sigma2 + 0.09);
  42. /* Useful precomputed quantities */
  43. float theta_r = acos (V . N); /* Angle between V and N */
  44. vector V_perp_N = normalize(V-N*(V.N)); /* Part of V perpendicular to N */
  45.  
  46. /* Accumulate incoming radiance from lights in C */
  47. color C = 0;
  48. extern point P;
  49. illuminance (P, N, PI/2) {
  50. /* Must declare extern L & Cl because we're in a function */
  51. extern vector L; extern color Cl;
  52. float nondiff = 0;
  53. lightsource ("__nondiffuse", nondiff);
  54. if (nondiff < 1) {
  55. vector LN = normalize(L);
  56. float cos_theta_i = LN . N;
  57. float cos_phi_diff = V_perp_N . normalize(LN - N*cos_theta_i);
  58. float theta_i = acos (cos_theta_i);
  59. float alpha = max (theta_i, theta_r);
  60. float beta = min (theta_i, theta_r);
  61. C += (1-nondiff) * Cl * cos_theta_i * 
  62. (A + B * max(0,cos_phi_diff) * sin(alpha) * tan(beta));
  63. }
  64. }
  65. return C;
  66.  
  67. }
  68.  
  69. normal Nf1 = faceforward (normalize(N), I);
  70. color ci1 = (float(magnitude3)*claycol1+(1-float(magnitude3))*claycol2) * (Ka1*ambient() + Kd1*LocIllumOrenNayar(Nf1,-normalize(I),roughness1));
  71.  
  72. /** Surface main-code end **/
  73.  
  74. Ci = ci1;
  75. Oi = color(transp);
  76. }
  77.