home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 2 / LSD and 17bit Compendium Deluxe - Volume II.iso / a / prog / cprog / illum.lha / G.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-05-11  |  2.7 KB  |  91 lines

  1. /* ****************************************************************
  2.  *                            G.c
  3.  * ****************************************************************
  4.  *  MODULE PURPOSE:
  5.  *      This module contains geometric attenuation
  6.  *      functions
  7.  *
  8.  *  MODULE CONTENTS:
  9.  *      D_torrance      - function by Torrance and Sparrow
  10.  *      D_Sancer        - function by Sancer
  11.  */
  12. #include <math.h>
  13. #include "geo.h"
  14.  
  15. #define ROOT_PI     1.7724538509055159
  16.  
  17. /* ****************************************************************
  18.  * double G_torrance (N, L, V)
  19.  *  DIR_VECT    *N, *L, *V  (in) - N, L, V vectors
  20.  *  double      dummy       (in) - just to make the
  21.  *                              calls identical
  22.  *
  23.  *  Returns geometric attenuation (Torrance and Sparrow
  24.  *   1967), refer to Eq.(\*(eS).  The direction vectors
  25.  *   N, V, and L are assumed to be oriented to the same
  26.  *   side of the surface.
  27.  */
  28. double G_torrance (N, L, V, dummy)
  29. DIR_VECT        *N, *L, *V;
  30. double          dummy;
  31. {
  32.     double      N_dot_H, V_dot_H;
  33.     double      N_dot_V, N_dot_L;
  34.     double      g1, g2;
  35.     DIR_VECT    *H;
  36.  
  37.     H = geo_H(V,L);
  38.     N_dot_H = geo_dot (N,H);
  39.     V_dot_H = geo_dot (V,H);
  40.     N_dot_V = geo_dot (N,V);
  41.     N_dot_L = geo_dot (N,L);
  42.  
  43.     if ((g1 = (2.0 * N_dot_H * N_dot_V) /
  44.     V_dot_H) > 1.0) g1 = 1.0;
  45.     if ((g2 = (2.0 * N_dot_H * N_dot_L) /
  46.     V_dot_H) < g1) return g2;
  47.     else return g1;
  48. }
  49.  
  50.  
  51.  
  52. /* ****************************************************************
  53.  * double G_sancer (N, L, V, m_2)
  54.  *  DIR_VECT    *N, *L, *V  (in) - N, L, V vectors
  55.  *  double      m_2         (in) - m squared
  56.  *
  57.  *  Returns geometric attenuation (Sancer 1969), refer to Eq.(\*(rT).
  58.  *   The direction vectors N, V, and L are assumed to be oriented
  59.  *   to the same side of the surface.
  60.  *
  61.  *  NOTE:
  62.  *   > m can be related to beta using D_cook_init()
  63.  *   > This implementation assumes slope relates roughness and
  64.  *      correlation distance as described by Beckmann. This
  65.  *      explains the missing factor of 2 with m_2 when compared
  66.  *      to Eq.(\*(rT).
  67.  */
  68. double G_sancer (N, L, V, m_2)
  69. DIR_VECT        *N, *L, *V;
  70. double          m_2;
  71. {
  72.     double      N_dot_L, N_dot_V;
  73.     double      c1, c2, root_c1, root_c2, ci, cr;
  74.  
  75.     if (m_2 <= 0.0) return 1.0;
  76.     if ((N_dot_L = geo_dot(N,L)) <= 0.0) return 0.0;
  77.     c1 = (N_dot_L * N_dot_L) / (m_2 * (1.0 - (N_dot_L * N_dot_L)));
  78.     root_c1 = sqrt(c1);
  79.     ci = (exp(-c1) /
  80.     (2.0 * ROOT_PI * root_c1)) - (erfc(root_c1) / 2.0);
  81.  
  82.     if ((N_dot_V = geo_dot(N,V)) <= 0.0) return 0.0;
  83.     c2 = (N_dot_V * N_dot_V) / (m_2 * (1.0 - (N_dot_V * N_dot_V)));
  84.     root_c2 = sqrt(c2);
  85.     cr = (exp(-c2) /
  86.     (2.0 * ROOT_PI * root_c2)) - (erfc(root_c2) / 2.0);
  87.  
  88.     return 1.0/(1.0 + ci + cr);
  89. }
  90. /* ************************************************************* */
  91.