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_supertexmap.sl < prev    next >
Encoding:
Text File  |  2008-01-23  |  3.2 KB  |  108 lines

  1. /***************************************************************************
  2.  * supertexmap.sl
  3.  *
  4.  * Description:
  5.  *    Apply a texture map (possibly with associated alpha) 
  6.  *    to a plastic surface.  This is essentially a replacement for the
  7.  *    standard "paintedplastic", but with much more flexibility in the
  8.  *    coordinate mapping of the texture.
  9.  *
  10.  * Parameters:
  11.  *    Ka, Kd, Ks, roughness, specularcolor - the usual meaning.
  12.  *    texturename - the name of the texture file.
  13.  *    projection - specifies the projection type, one of "st", "planar",
  14.  *                 "perspective", "cylindrical", "spherical".
  15.  *    textureprojspace - the space in which the texture projection is
  16.  *                applied; either a standard space like "shader", or a
  17.  *                named coordinate system.
  18.  *    mx - 16 floats giving an 3-D affine transformation to apply to the
  19.  *                projected point before texture coordinates are extracted.
  20.  *    truedisp - 1 for true displacement, 0 for bump mapping
  21.  *
  22.  * Author: Larry Gritz (gritzl@acm.org)
  23.  *
  24.  * Reference:
  25.  *   _Advanced RenderMan: Creating CGI for Motion Picture_, 
  26.  *   by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999.
  27.  *
  28.  ***************************************************************************/
  29.  
  30. #include "k3d_filterwidth.h"
  31. #include "k3d_project.h"
  32. #include "k3d_displace.h"
  33. #include "k3d_material.h"
  34.  
  35.  
  36. surface k3d_supertexmap(float Ka = 1, Kd = .5, Ks = .5, roughness = .1;
  37.             /* base color */
  38.             string Csmapname = "", Csproj = "st", Csspace =
  39.             "shader";
  40.             float Csmx[16] =
  41.             {
  42.             1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
  43.             float Csblur = 0;
  44.             /* opacity */
  45.             string Osmapname = "", Osproj = "st", Osspace =
  46.             "shader";
  47.             float Osmx[16] =
  48.             {
  49.             1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
  50.             float Osblur = 0;
  51.             /* specularity */
  52.             string Ksmapname = "", Ksproj = "st", Ksspace =
  53.             "shader";
  54.             float Ksmx[16] =
  55.             {
  56.             1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
  57.             float Ksblur = 0;
  58.             /* displacement */
  59.             string dispmapname = "", dispproj = "st", dispspace =
  60.             "shader";
  61.             float dispmx[16] =
  62.             {
  63.             1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
  64.             float dispblur = 0;
  65.             float truedisp = 1;
  66.   )
  67. {
  68.   /* Start out with the regular plastic parameters, unless overridden
  69.    * by maps.
  70.    */
  71.   color Ct = Cs, Ot = Os;
  72.   float ks = Ks;
  73.   float disp = 0;
  74.  
  75.   /* Color mapping */
  76.   if(Csmapname != "")
  77.     Ct =
  78.       ApplyColorTextureOver(Ct, Csmapname, Csproj, P, Csspace,
  79.                 array_to_mx(Csmx), Csblur);
  80.  
  81.   /* Opacity mapping */
  82.   if(Osmapname != "")
  83.     Ot =
  84.       ApplyColorTextureOver(Ct, Osmapname, Osproj, P, Osspace,
  85.                 array_to_mx(Osmx), Osblur);
  86.  
  87.   /* specularity mapping */
  88.   if(Ksmapname != "")
  89.     ks =
  90.       ApplyFloatTextureOver(Ks, Ksmapname, Ksproj, P, Ksspace,
  91.                 array_to_mx(Ksmx), Ksblur);
  92.  
  93.   /* displacement mapping */
  94.   if(dispmapname != "")
  95.     {
  96.       disp =
  97.     ApplyFloatTextureOver(disp, dispmapname, dispproj, P, dispspace,
  98.                   array_to_mx(dispmx), dispblur);
  99.       N = Displace(normalize(N), dispspace, disp, truedisp);
  100.     }
  101.  
  102.   /* Illumination model - just use plastic */
  103.   normal Nf = faceforward(normalize(N), I);
  104.   Ci = MaterialPlastic(Nf, Ct, Ka, Kd, ks, roughness);
  105.   Oi = Ot;
  106.   Ci *= Oi;
  107. }
  108.