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

  1. /*
  2.  * TLd_cell1
  3.  *
  4.  * Simple displacement shader using Voronoi cell noise
  5.  * Uses noises.h from ARMAN
  6.  *
  7.  * Tal Lancater 12/15/01
  8.  *
  9.  * History
  10.  *   01/12/15  Created
  11.  *
  12.  */
  13.  
  14. #include "k3d_noises.h"
  15.  
  16. displacement k3d_celld (
  17.         float Kvoro = 0;        /* desc {amount to displace. } */
  18.     float voro_freq = 1;    /* desc {Feature size } */
  19.     float voro_step = 0.05; /* desc {Step value size.  If the difference
  20.                    between f2 and f1 is less then this value
  21.                    then the result is 0. } */
  22.     float voro_jitter = 0;  /* desc { Amount to perturb the voroni 
  23.                    function } */
  24.     string PSpace = "shader";  /* desc {Space to transform P for shading calculations } */
  25.     float usePref = 0;   /* type switch */
  26.     varying point __Pref = point (1000, 0, -1000); /* vis hidden */
  27.        output varying float VoroVal = 0; /* vis hidden */
  28. )
  29. {
  30.     point objP = transform (PSpace, P);
  31.     point noiseP = (usePref != 0)? transform (PSpace, __Pref): objP;
  32.     normal Nn = ntransform (PSpace, N);
  33.     Nn = normalize (Nn);
  34.  
  35.     float voro_f1 = 0, voro_f2 = 0;
  36.     point voro_pos1 = 0, voro_pos2 = 0;
  37.  
  38.     voronoi_f1f2_3d (noiseP*voro_freq, voro_jitter, 
  39.              voro_f1, voro_pos1, voro_f2,
  40.              voro_pos2);
  41.  
  42.     float voro_dist = 1 - step (voro_step, voro_f2 - voro_f1);
  43. #if 0
  44.     if (acos(N.I) >= 90)
  45.         voro_dist = 0;
  46. #endif
  47.     VoroVal = voro_dist;
  48.     objP += Kvoro * voro_dist * Nn;
  49.  
  50. #pragma nolint 1
  51.     P = transform (PSpace, "current", objP);
  52.     N = calculatenormal (P);
  53. }
  54.