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.3 by greg, Tue Mar 27 11:39:58 1990 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"
13  
14   #ifdef  DISPERSE
15   #include  "source.h"
16 + static  disperse();
17 + static int  lambda();
18   #endif
19  
20   /*
# Line 49 | Line 48 | static char SCCSid[] = "$SunId$ LBL";
48   #define  MINCOS         0.997           /* minimum dot product for dispersion */
49  
50  
51 < m_dielectric(m, r)      /* color a ray which hit something transparent */
51 > static double
52 > mylog(x)                /* special log for extinction coefficients */
53 > double  x;
54 > {
55 >        if (x < 1e-40)
56 >                return(-100.);
57 >        if (x >= 1.)
58 >                return(0.);
59 >        return(log(x));
60 > }
61 >
62 >
63 > m_dielectric(m, r)      /* color a ray which hit a dielectric interface */
64   OBJREC  *m;
65   register RAY  *r;
66   {
56        double  sqrt(), pow();
67          double  cos1, cos2, nratio;
68 <        COLOR  mcolor;
69 <        double  mabsorp;
68 >        COLOR  ctrans;
69 >        COLOR  talb;
70 >        int  hastexture;
71          double  refl, trans;
72          FVECT  dnorm;
73          double  d1, d2;
# Line 68 | 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 76 | 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];
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 >                setcolor(r->albedo, 0., 0., 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 >                        setcolor(talb, 0., 0., 0.);
111 >                } else {
112 >                        copycolor(ctrans, cextinction);
113 >                        copycolor(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 >                setcolor(talb, 0., 0., 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 >                        setcolor(r->albedo, 0., 0., 0.);
128 >                        r->gecc = 0.;
129 >                }
130          }
95        mabsorp = bright(mcolor);
131  
132          d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1);     /* compute cos theta2 */
133  
# Line 113 | Line 148 | register RAY  *r;
148                  d1 = (d1 - d2) / (d1 + d2);
149                  refl += d1 * d1;
150  
151 <                refl /= 2.0;
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);
182 +                                copycolor(p.albedo, talb);
183                                  rayvalue(&p);
135                                multcolor(mcolor, r->pcol);     /* modify */
184                                  scalecolor(p.rcol, trans);
185                                  addcolor(r->rcol, p.rcol);
186 <                                r->rt = r->rot + p.rt;
186 >                                if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY)
187 >                                        r->rt = r->rot + p.rt;
188                          }
189                  }
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  
205                  scalecolor(p.rcol, refl);       /* color contribution */
206                  addcolor(r->rcol, p.rcol);
154                if (refl > trans)
155                        r->rt = r->rot + p.rt;
207          }
208 <
209 <        multcolor(r->rcol, mcolor);             /* multiply by transmittance */
208 >                                /* rayvalue() computes absorption */
209 >        return(1);
210   }
211  
212  
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   {
171        double  sqrt();
223          RAY  sray, *entray;
224          FVECT  v1, v2, n1, n2;
225          FVECT  dv, v2Xdv;
226          double  v2Xdvv2Xdv;
227 <        int  sn, success = 0;
228 <        double  omega;
227 >        int  success = 0;
228 >        SRCINDEX  si;
229          FVECT  vtmp1, vtmp2;
230          double  dtmp1, dtmp2;
231          int  l1, l2;
# Line 236 | Line 287 | double  tr;
287          v2Xdvv2Xdv = DOT(v2Xdv, v2Xdv);
288  
289                                          /* check sources */
290 <        for (sn = 0; sn < nsources; sn++) {
290 >        initsrcindex(&si);
291 >        while (srcray(&sray, r, &si)) {
292  
293 <                if ((omega = srcray(&sray, r, sn)) == 0.0 ||
242 <                                DOT(sray.rdir, v2) < MINCOS)
293 >                if (DOT(sray.rdir, v2) < MINCOS)
294                          continue;                       /* bad source */
244                
295                                                  /* adjust source ray */
296  
297                  dtmp1 = DOT(v2Xdv, sray.rdir) / v2Xdvv2Xdv;
# Line 254 | 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 */
# Line 266 | Line 318 | double  tr;
318                   */
319                  
320                  fcross(vtmp1, v2Xdv, sray.rdir);
321 <                dtmp1 = sqrt(omega  / v2Xdvv2Xdv / PI);
321 >                dtmp1 = sqrt(si.dom  / v2Xdvv2Xdv / PI);
322  
323                                                          /* compute first ray */
324                  for (i = 0; i < 3; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines