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_starfield.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  1.0 KB  |  33 lines

  1. /* DESCRIPTION:
  2.     Makes a star field.  Best when used as a surface shader for the inside    of a large sphere.
  3.     
  4.     We partition space into a 1x1x1 grid, rendering one solid spherical "star" per cell.
  5.  
  6.     PARAMETERS:
  7.  
  8.     AUTHOR: written by Timothy M. Shead
  9. */
  10.  
  11. surface k3d_starfield(float intensity = 2.0; float frequency = 0.1; float size = 0.3; float irregularity = 2.0)
  12. {
  13.     // Work in object coordinates ...
  14.     point PP = transform("object", frequency * P);
  15.     
  16.     // Get the nearest star ...
  17.     point star_center = point(0.5 * (floor(xcomp(PP)) + ceil(xcomp(PP))), 0.5 * (floor(ycomp(PP)) + ceil(ycomp(PP))), 0.5 * (floor(zcomp(PP)) + ceil(zcomp(PP))));
  18.  
  19.     star_center += irregularity * (point noise(star_center) - point(0.5, 0.5, 0.5));
  20.  
  21.     // Calculate the distance to the nearest star ...
  22.     float star_distance = distance(PP, star_center);
  23.     
  24.     float inside_star = 1 - smoothstep(0.0, size, star_distance);
  25.     
  26.     // Give stars relative intensities ...
  27.     float star_intensity = float cellnoise(star_center);
  28.     
  29.     Ci = intensity * star_intensity * inside_star * inside_star;
  30. }
  31.  
  32.  
  33.