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 1.1 by greg, Thu Feb 2 10:41:21 1989 UTC vs.
Revision 2.10 by greg, Thu Feb 22 16:56:39 1996 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #ifdef  DISPERSE
18   #include  "source.h"
19 + static  disperse();
20 + static int  lambda();
21   #endif
22  
23   /*
# Line 48 | Line 50 | static char SCCSid[] = "$SunId$ LBL";
50  
51   #define  MINCOS         0.997           /* minimum dot product for dispersion */
52  
53 + extern COLOR  cextinction;              /* global coefficient of extinction */
54 + extern double  salbedo;                 /* global scattering albedo */
55  
56 < m_dielectric(m, r)      /* color a ray which hit something transparent */
56 >
57 > static double
58 > mylog(x)                /* special log for extinction coefficients */
59 > double  x;
60 > {
61 >        if (x < 1e-40)
62 >                return(-100.);
63 >        if (x >= 1.)
64 >                return(0.);
65 >        return(log(x));
66 > }
67 >
68 >
69 > m_dielectric(m, r)      /* color a ray which hit a dielectric interface */
70   OBJREC  *m;
71   register RAY  *r;
72   {
56        double  sqrt(), pow();
73          double  cos1, cos2, nratio;
74 <        COLOR  mcolor;
74 >        COLOR  ctrans;
75 >        double  talb;
76          double  mabsorp;
77          double  refl, trans;
78          FVECT  dnorm;
# Line 80 | Line 97 | register RAY  *r;
97                  dnorm[0] = -dnorm[0];
98                  dnorm[1] = -dnorm[1];
99                  dnorm[2] = -dnorm[2];
100 <                setcolor(mcolor, pow(m->oargs.farg[0], r->rot),
101 <                                 pow(m->oargs.farg[1], r->rot),
102 <                                 pow(m->oargs.farg[2], r->rot));
100 >                setcolor(r->cext, -mylog(m->oargs.farg[0]*colval(r->pcol,RED)),
101 >                                 -mylog(m->oargs.farg[1]*colval(r->pcol,GRN)),
102 >                                 -mylog(m->oargs.farg[2]*colval(r->pcol,BLU)));
103 >                r->albedo = 0.;
104 >                r->gecc = 0.;
105 >                if (m->otype == MAT_INTERFACE) {
106 >                        setcolor(ctrans,
107 >                                -mylog(m->oargs.farg[4]*colval(r->pcol,RED)),
108 >                                -mylog(m->oargs.farg[5]*colval(r->pcol,GRN)),
109 >                                -mylog(m->oargs.farg[6]*colval(r->pcol,BLU)));
110 >                        talb = 0.;
111 >                } else {
112 >                        copycolor(ctrans, cextinction);
113 >                        talb = salbedo;
114 >                }
115          } else {                                /* outside */
116                  nratio = 1.0 / nratio;
117 <                if (m->otype == MAT_INTERFACE)
118 <                        setcolor(mcolor, pow(m->oargs.farg[4], r->rot),
119 <                                         pow(m->oargs.farg[5], r->rot),
120 <                                         pow(m->oargs.farg[6], r->rot));
121 <                else
122 <                        setcolor(mcolor, 1.0, 1.0, 1.0);
117 >
118 >                setcolor(ctrans, -mylog(m->oargs.farg[0]*colval(r->pcol,RED)),
119 >                                 -mylog(m->oargs.farg[1]*colval(r->pcol,GRN)),
120 >                                 -mylog(m->oargs.farg[2]*colval(r->pcol,BLU)));
121 >                talb = 0.;
122 >                if (m->otype == MAT_INTERFACE) {
123 >                        setcolor(r->cext,
124 >                                -mylog(m->oargs.farg[4]*colval(r->pcol,RED)),
125 >                                -mylog(m->oargs.farg[5]*colval(r->pcol,GRN)),
126 >                                -mylog(m->oargs.farg[6]*colval(r->pcol,BLU)));
127 >                        r->albedo = 0.;
128 >                        r->gecc = 0.;
129 >                }
130          }
131 <        mabsorp = intens(mcolor);
131 >        mabsorp = exp(-bright(r->cext)*r->rot);         /* approximate */
132  
133          d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1);     /* compute cos theta2 */
134  
# Line 113 | Line 149 | register RAY  *r;
149                  d1 = (d1 - d2) / (d1 + d2);
150                  refl += d1 * d1;
151  
152 <                refl /= 2.0;
152 >                refl *= 0.5;
153                  trans = 1.0 - refl;
154  
155                  if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) {
# Line 127 | Line 163 | register RAY  *r;
163                          if (m->otype != MAT_DIELECTRIC
164                                          || r->rod > 0.0
165                                          || r->crtype & SHADOW
166 +                                        || !directvis
167                                          || m->oargs.farg[4] == 0.0
168                                          || !disperse(m, r, p.rdir, trans))
169   #endif
170                          {
171 +                                copycolor(p.cext, ctrans);
172 +                                p.albedo = talb;
173                                  rayvalue(&p);
135                                multcolor(mcolor, r->pcol);     /* modify */
174                                  scalecolor(p.rcol, trans);
175                                  addcolor(r->rcol, p.rcol);
176 +                                if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY)
177 +                                        r->rt = r->rot + p.rt;
178                          }
179                  }
180          }
# Line 151 | Line 191 | register RAY  *r;
191                  scalecolor(p.rcol, refl);       /* color contribution */
192                  addcolor(r->rcol, p.rcol);
193          }
194 <
195 <        multcolor(r->rcol, mcolor);             /* multiply by transmittance */
194 >                                /* rayvalue() computes absorption */
195 >        return(1);
196   }
197  
198  
# Line 165 | Line 205 | RAY  *r;
205   FVECT  vt;
206   double  tr;
207   {
168        double  sqrt();
208          RAY  sray, *entray;
209          FVECT  v1, v2, n1, n2;
210          FVECT  dv, v2Xdv;
211          double  v2Xdvv2Xdv;
212 <        int  sn, success = 0;
213 <        double  omega;
212 >        int  success = 0;
213 >        SRCINDEX  si;
214          FVECT  vtmp1, vtmp2;
215          double  dtmp1, dtmp2;
216          int  l1, l2;
# Line 233 | Line 272 | double  tr;
272          v2Xdvv2Xdv = DOT(v2Xdv, v2Xdv);
273  
274                                          /* check sources */
275 <        for (sn = 0; sn < nsources; sn++) {
275 >        initsrcindex(&si);
276 >        while (srcray(&sray, r, &si)) {
277  
278 <                if ((omega = srcray(&sray, r, sn)) == 0.0 ||
239 <                                DOT(sray.rdir, v2) < MINCOS)
278 >                if (DOT(sray.rdir, v2) < MINCOS)
279                          continue;                       /* bad source */
241                
280                                                  /* adjust source ray */
281  
282                  dtmp1 = DOT(v2Xdv, sray.rdir) / v2Xdvv2Xdv;
# Line 253 | Line 291 | double  tr;
291                                                  /* trace source ray */
292                  normalize(sray.rdir);
293                  rayvalue(&sray);
294 <                if (intens(sray.rcol) <= FTINY) /* missed it */
294 >                if (bright(sray.rcol) <= FTINY) /* missed it */
295                          continue;
296                  
297                  /*
# Line 263 | Line 301 | double  tr;
301                   */
302                  
303                  fcross(vtmp1, v2Xdv, sray.rdir);
304 <                dtmp1 = sqrt(omega  / v2Xdvv2Xdv / PI);
304 >                dtmp1 = sqrt(si.dom  / v2Xdvv2Xdv / PI);
305  
306                                                          /* compute first ray */
307                  for (i = 0; i < 3; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines