home *** CD-ROM | disk | FTP | other *** search
/ Hackers Magazine 57 / CdHackersMagazineNr57.iso / Software / Multimedia / k3d-setup-0.7.11.0.exe / share / k3d / shaders / k3d_pshad.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-01-23  |  3.0 KB  |  86 lines

  1. /************************************************************************
  2.  * pshad.h - define macros for easy use of reference meshes and texture
  3.  *           spaces.
  4.  *
  5.  * This file is meant to be included in shaders which use solid
  6.  * texturing.  It provides two macros:
  7.  *
  8.  * PSHAD_PARAMS(space,freq) - put this macro in the parameter list of 
  9.  *                your shader to declare a shadingspace parameter (and 
  10.  *                optionally Pref, if USE_PREF is nonzero).  Takes as
  11.  *                arguments the default shading space name and frequency.
  12.  *
  13.  * DEFAULT_PSHAD_PARAMS - calls PSHAD_PARAMS with default space "shader"
  14.  *                and default frequency 1.
  15.  *
  16.  * GET_PSHAD    - put this in the body of your shader, near the top.
  17.  *                It sets Pshad to the shading coordinates of P (or Pref,
  18.  *                if provided), and sets dPshad to the expected change
  19.  *                in Pshad between adjacent shading samples.
  20.  *
  21.  * This file expects that the .sl file #define's the symbol USE_PREF
  22.  * _prior_ to inclusion of this header file.  
  23.  *
  24.  * Author: Larry Gritz (gritzl@acm.org)
  25.  *
  26.  * Reference:
  27.  *   _Advanced RenderMan: Creating CGI for Motion Picture_, 
  28.  *   by Anthony A. Apodaca and Larry Gritz, Morgan Kaufmann, 1999.
  29.  *
  30.  * $Revision: 1.1 $    $Date: 2004/05/19 18:15:20 $
  31.  *
  32.  ************************************************************************/
  33.  
  34.  
  35. #ifndef PSHAD_H
  36. #define PSHAD_H 1
  37.  
  38.  
  39. #ifndef FILTERWIDTH_H
  40. #include "k3d_filterwidth.h"    /* Needed for filterwidth and friends */
  41. #endif
  42.  
  43.  
  44.  
  45. /* If USE_PREF is not defined prior to inclusion of this file, assume
  46.  * that Pref will not be used.
  47.  */
  48. #ifndef USE_PREF
  49. #define USE_PREF 0
  50. #endif
  51.  
  52. #if (USE_PREF)
  53.  
  54. /* Pick an unlikely point value to let us recognize an uninitialized,
  55.  * and therefore nonexistant, Pref.
  56.  */
  57. #define UNINITIALIZED_PREF point (-1e10, -1e10, -1e10)
  58.  
  59. #define PSHAD_PARAMS(spacedefault,freqdefault) \
  60.                      varying point Pref = UNINITIALIZED_PREF;           \
  61.                      string shadingspace = spacedefault;                \
  62.                      float shadingfreq = freqdefault
  63.  
  64. #define GET_PSHAD    varying point Pshad;                               \
  65.                      if (Pref != UNINITIALIZED_PREF)                    \
  66.                           Pshad = transform (shadingspace, Pref);       \
  67.                      else Pshad = transform (shadingspace, P);          \
  68.                      Pshad *= shadingfreq;                              \
  69.                      float dPshad = filterwidthp(Pshad)
  70.  
  71. #else /* if (USE_PREF) */
  72.  
  73. #define PSHAD_PARAMS(spacedefault,freqdefault) \
  74.                      string shadingspace = spacedefault;                \
  75.                      float shadingfreq = freqdefault
  76.  
  77. #define GET_PSHAD    varying point Pshad;                               \
  78.                      Pshad = shadingfreq * transform (shadingspace, P); \
  79.                      float dPshad = filterwidthp(Pshad)
  80.  
  81. #endif /* USE_PREF */
  82.  
  83. #define DEFAULT_PSHAD_PARAMS PSHAD_PARAMS("shader",1)
  84.  
  85. #endif /* defined(PSHAD_H) */
  86.