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

  1. /*Environment Light to project an environment map onto 3D geometry - designed
  2. * to work with 32 bit floating point TIFF environment maps to give a higher 
  3. * dynamic range 
  4. *
  5. *Created by Simon Bunker 27th September 2001
  6. *simon@rendermania.com http://www.rendermania.com/HDRI/
  7. *
  8. *This shader is made freely available under the proviso that this copyright
  9. *notice remain intact and that I am acknowledged as the original author. Please
  10. *post links back to the above address*or get in contact if you have any queries
  11. *or bug reports related to this shader 
  12. *
  13. */
  14.  
  15. color hdrenv(string envname;vector R;float blur)
  16. {
  17.     color hdrtex;
  18.  
  19.     vector D = normalize(vtransform("world",R));
  20.  
  21.     float Dx = xcomp(D);
  22.     float Dy = ycomp(D);
  23.     float Dz = zcomp(D);
  24.  
  25.     float r = 0.159154943 * acos(Dz) / sqrt((Dx * Dx) + (Dy * Dy));
  26.  
  27.     float ss = 0.5 + (Dx * r);
  28.     float tt = 0.5 + (Dy * r);
  29.     ss = 1 - ss;
  30.  
  31.     if(envname !=""){
  32.         hdrtex = texture(envname,ss,tt,"blur",blur);
  33.     }
  34.  
  35.     return hdrtex;
  36. }
  37.  
  38.  
  39. surface k3d_hdr_surface (
  40.     float intensity =1.0;
  41.     float exposure_compensation_stops = 0.0;
  42.     string envname = "";
  43.     string envspace = "shader";
  44.     string mappingtype = "probe";
  45.     point origin = (0,0,0);
  46.     float blur = 0.0;
  47. )
  48. {
  49.  
  50.     color Ct;
  51.  
  52.     vector R = normalize(vtransform(envspace,(origin - P)));
  53.  
  54.     if (mappingtype == "probe"){
  55.         if(envname != ""){
  56.             Ct = hdrenv(envname,R,blur);
  57.         }
  58.     }
  59.     else if (mappingtype == "environment"){
  60.         if(envname != ""){
  61.             Ct = environment(envname,R,"blur",blur);
  62.         }
  63.     }
  64.     else if (mappingtype == "planar"){
  65.         if(envname != ""){
  66.             Ct = texture(envname,s,t,"blur",blur);
  67.         }
  68.     }
  69.  
  70.     float exposure = pow(2,exposure_compensation_stops);
  71.  
  72.     Oi = Os;
  73.     Ci = Cs * Oi * Ct * intensity * exposure;
  74.  
  75. }
  76.