ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/dielectric.c
(Generate patch)

Comparing ray/src/rt/dielectric.c (file contents):
Revision 2.11 by greg, Wed Apr 17 14:01:52 1996 UTC vs.
Revision 2.17 by schorsch, Sun Jul 27 22:12:03 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1986 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  dielectric.c - shading function for transparent materials.
9 *
10 *     9/6/85
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  "ray.h"
11  
12   #include  "otypes.h"
# Line 50 | Line 47 | static int  lambda();
47  
48   #define  MINCOS         0.997           /* minimum dot product for dispersion */
49  
53 extern COLOR  cextinction;              /* global coefficient of extinction */
54 extern COLOR  salbedo;                  /* global scattering albedo */
50  
56
51   static double
52   mylog(x)                /* special log for extinction coefficients */
53   double  x;
# Line 73 | Line 67 | register RAY  *r;
67          double  cos1, cos2, nratio;
68          COLOR  ctrans;
69          COLOR  talb;
70 <        double  mabsorp;
70 >        int  hastexture;
71          double  refl, trans;
72          FVECT  dnorm;
73          double  d1, d2;
# Line 85 | Line 79 | register RAY  *r;
79  
80          raytexture(r, m->omod);                 /* get modifiers */
81  
82 <        cos1 = raynormal(dnorm, r);             /* cosine of theta1 */
82 >        if ( (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) )
83 >                cos1 = raynormal(dnorm, r);     /* perturb normal */
84 >        else {
85 >                VCOPY(dnorm, r->ron);
86 >                cos1 = r->rod;
87 >        }
88                                                  /* index of refraction */
89          if (m->otype == MAT_DIELECTRIC)
90                  nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA;
# Line 93 | Line 92 | register RAY  *r;
92                  nratio = m->oargs.farg[3] / m->oargs.farg[7];
93          
94          if (cos1 < 0.0) {                       /* inside */
95 +                hastexture = -hastexture;
96                  cos1 = -cos1;
97                  dnorm[0] = -dnorm[0];
98                  dnorm[1] = -dnorm[1];
# Line 128 | Line 128 | register RAY  *r;
128                          r->gecc = 0.;
129                  }
130          }
131        mabsorp = exp(-bright(r->cext)*r->rot);         /* approximate */
131  
132          d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1);     /* compute cos theta2 */
133  
# Line 152 | Line 151 | register RAY  *r;
151                  refl *= 0.5;
152                  trans = 1.0 - refl;
153  
154 <                if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) {
154 >                trans *= nratio*nratio;         /* solid angle ratio */
155  
156 +                if (rayorigin(&p, r, REFRACTED, trans) == 0) {
157 +
158                                                  /* compute refracted ray */
159                          d1 = nratio*cos1 - cos2;
160                          for (i = 0; i < 3; i++)
161                                  p.rdir[i] = nratio*r->rdir[i] + d1*dnorm[i];
162 <
162 >                                                /* accidental reflection? */
163 >                        if (hastexture &&
164 >                                DOT(p.rdir,r->ron)*hastexture >= -FTINY) {
165 >                                d1 *= (double)hastexture;
166 >                                for (i = 0; i < 3; i++) /* ignore texture */
167 >                                        p.rdir[i] = nratio*r->rdir[i] +
168 >                                                        d1*r->ron[i];
169 >                                normalize(p.rdir);      /* not exact */
170 >                        }
171   #ifdef  DISPERSE
172                          if (m->otype != MAT_DIELECTRIC
173                                          || r->rod > 0.0
174                                          || r->crtype & SHADOW
175                                          || !directvis
176                                          || m->oargs.farg[4] == 0.0
177 <                                        || !disperse(m, r, p.rdir, trans))
177 >                                        || !disperse(m, r, p.rdir,
178 >                                                        trans, ctrans, talb))
179   #endif
180                          {
181                                  copycolor(p.cext, ctrans);
# Line 180 | Line 190 | register RAY  *r;
190          }
191                  
192          if (!(r->crtype & SHADOW) &&
193 <                        rayorigin(&p, r, REFLECTED, mabsorp*refl) == 0) {
193 >                        rayorigin(&p, r, REFLECTED, refl) == 0) {
194  
195                                          /* compute reflected ray */
196                  for (i = 0; i < 3; i++)
197                          p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i];
198 +                                        /* accidental penetration? */
199 +                if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY)
200 +                        for (i = 0; i < 3; i++)         /* ignore texture */
201 +                                p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i];
202  
203                  rayvalue(&p);                   /* reflected ray value */
204  
# Line 199 | Line 213 | register RAY  *r;
213   #ifdef  DISPERSE
214  
215   static
216 < disperse(m, r, vt, tr)          /* check light sources for dispersion */
216 > disperse(m, r, vt, tr, cet, abt)  /* check light sources for dispersion */
217   OBJREC  *m;
218   RAY  *r;
219   FVECT  vt;
220   double  tr;
221 + COLOR  cet, abt;
222   {
223          RAY  sray, *entray;
224          FVECT  v1, v2, n1, n2;
# Line 289 | Line 304 | double  tr;
304                  if (l1 > MAXLAMBDA || l1 < MINLAMBDA)   /* not visible */
305                          continue;
306                                                  /* trace source ray */
307 +                copycolor(sray.cext, cet);
308 +                copycolor(sray.albedo, abt);
309                  normalize(sray.rdir);
310                  rayvalue(&sray);
311                  if (bright(sray.rcol) <= FTINY) /* missed it */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines