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_light.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  2.4 KB  |  101 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 and more realistic colours.
  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.  
  16. color hdrenv(string envname;vector R;float blur)
  17. {
  18.     color hdrtex;
  19.  
  20.     vector D = normalize(vtransform("world",R));
  21.  
  22.     float Dx = xcomp(D);
  23.     float Dy = ycomp(D);
  24.     float Dz = zcomp(D);
  25.  
  26.     float r = 0.159154943 * acos(Dz) / sqrt((Dx * Dx) + (Dy * Dy));
  27.  
  28.     float ss = 0.5 + (Dx * r);
  29.     float tt = 0.5 + (Dy * r);
  30.     ss = 1 - ss;
  31.  
  32.     if(envname !="") {
  33.         hdrtex = texture(envname,ss,tt,"blur",blur);
  34.     }
  35.  
  36.     return hdrtex;
  37. }
  38.  
  39.  
  40. light k3d_hdr_light (
  41.     float intensity =1.0;
  42.     float exposure_compensation_stops = 0.0;
  43.     string envname = "";
  44.     string envspace = "shader";
  45.     string mappingtype = "probe";
  46.     point origin = (0,0,0);
  47.     float blur = 0.0;
  48.     float shadowmapping = 0.0;
  49.     string shadowname = "";
  50.     float shadowsamples = 16.0;
  51.     float shadowblur = 0.0;
  52.     float shadowbias = 0.0;
  53.     )
  54. {
  55.  
  56. /* Code based off of Larry Gritz's Uberlight Shader */
  57.  
  58. vector axis = normalize(vector "shader" (0,0,1));
  59.  
  60.     solar (-axis, 1.570796327) {
  61.         color Ct;
  62.  
  63.         /*Use light ray direction as map lookup NB L points from surface to lightsource*/
  64.         vector R = normalize(vtransform(envspace,L));
  65.  
  66.         /*Else bright red colour warns if light is not picking up texture*/
  67.         if (mappingtype == ""){
  68.             Ct = color (1,0,0);
  69.             printf("Please select mapping type probe,environment or planar");
  70.         }
  71.  
  72.         if (mappingtype == "probe"){
  73.             if(envname != ""){
  74.                 Ct = hdrenv(envname,R,blur);
  75.             }
  76.         }
  77.         else if (mappingtype == "environment"){
  78.             if(envname != ""){
  79.                 Ct = environment(envname,R,"blur",blur);
  80.             }
  81.         }
  82.         else if (mappingtype == "planar"){
  83.             if(envname != ""){
  84.                 Ct = texture(envname,s,t,"blur",blur);
  85.             }
  86.         }
  87.  
  88.         float exposure = pow(2,exposure_compensation_stops);
  89.  
  90.         if (shadowmapping == 1){
  91.                 if (shadowname != "") {
  92.                     Cl *= 1 - shadow(shadowname, Ps, "samples", shadowsamples, "blur", shadowblur, "bias", shadowbias);
  93.             }
  94.         }
  95.        
  96.         Cl = Ct * intensity * exposure;
  97.  
  98.     }
  99.  
  100. }
  101.