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.5 by greg, Mon Oct 15 20:39:30 1990 UTC vs.
Revision 2.14 by gwlarson, Fri Jun 19 12:01:15 1998 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1986 Regents of the University of California */
1 > /* Copyright (c) 1998 Silicon Graphics, Inc. */
2  
3   #ifndef lint
4 < static char SCCSid[] = "$SunId$ LBL";
4 > static char SCCSid[] = "$SunId$ SGI";
5   #endif
6  
7   /*
# 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 COLOR  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;
75 <        double  mabsorp;
74 >        COLOR  ctrans;
75 >        COLOR  talb;
76 >        int  hastexture;
77          double  refl, trans;
78          FVECT  dnorm;
79          double  d1, d2;
# Line 66 | Line 83 | register RAY  *r;
83          if (m->oargs.nfargs != (m->otype==MAT_DIELECTRIC ? 5 : 8))
84                  objerror(m, USER, "bad arguments");
85  
69        r->rt = r->rot;                         /* just use ray length */
70
86          raytexture(r, m->omod);                 /* get modifiers */
87  
88 <        cos1 = raynormal(dnorm, r);             /* cosine of theta1 */
88 >        if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY)
89 >                cos1 = raynormal(dnorm, r);     /* perturb normal */
90 >        else {
91 >                VCOPY(dnorm, r->ron);
92 >                cos1 = r->rod;
93 >        }
94                                                  /* index of refraction */
95          if (m->otype == MAT_DIELECTRIC)
96                  nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA;
# Line 78 | Line 98 | register RAY  *r;
98                  nratio = m->oargs.farg[3] / m->oargs.farg[7];
99          
100          if (cos1 < 0.0) {                       /* inside */
101 +                hastexture = -hastexture;
102                  cos1 = -cos1;
103                  dnorm[0] = -dnorm[0];
104                  dnorm[1] = -dnorm[1];
105                  dnorm[2] = -dnorm[2];
106 <                setcolor(mcolor, pow(m->oargs.farg[0], r->rot),
107 <                                 pow(m->oargs.farg[1], r->rot),
108 <                                 pow(m->oargs.farg[2], r->rot));
106 >                setcolor(r->cext, -mylog(m->oargs.farg[0]*colval(r->pcol,RED)),
107 >                                 -mylog(m->oargs.farg[1]*colval(r->pcol,GRN)),
108 >                                 -mylog(m->oargs.farg[2]*colval(r->pcol,BLU)));
109 >                setcolor(r->albedo, 0., 0., 0.);
110 >                r->gecc = 0.;
111 >                if (m->otype == MAT_INTERFACE) {
112 >                        setcolor(ctrans,
113 >                                -mylog(m->oargs.farg[4]*colval(r->pcol,RED)),
114 >                                -mylog(m->oargs.farg[5]*colval(r->pcol,GRN)),
115 >                                -mylog(m->oargs.farg[6]*colval(r->pcol,BLU)));
116 >                        setcolor(talb, 0., 0., 0.);
117 >                } else {
118 >                        copycolor(ctrans, cextinction);
119 >                        copycolor(talb, salbedo);
120 >                }
121          } else {                                /* outside */
122                  nratio = 1.0 / nratio;
123 <                if (m->otype == MAT_INTERFACE)
124 <                        setcolor(mcolor, pow(m->oargs.farg[4], r->rot),
125 <                                         pow(m->oargs.farg[5], r->rot),
126 <                                         pow(m->oargs.farg[6], r->rot));
127 <                else
128 <                        setcolor(mcolor, 1.0, 1.0, 1.0);
123 >
124 >                setcolor(ctrans, -mylog(m->oargs.farg[0]*colval(r->pcol,RED)),
125 >                                 -mylog(m->oargs.farg[1]*colval(r->pcol,GRN)),
126 >                                 -mylog(m->oargs.farg[2]*colval(r->pcol,BLU)));
127 >                setcolor(talb, 0., 0., 0.);
128 >                if (m->otype == MAT_INTERFACE) {
129 >                        setcolor(r->cext,
130 >                                -mylog(m->oargs.farg[4]*colval(r->pcol,RED)),
131 >                                -mylog(m->oargs.farg[5]*colval(r->pcol,GRN)),
132 >                                -mylog(m->oargs.farg[6]*colval(r->pcol,BLU)));
133 >                        setcolor(r->albedo, 0., 0., 0.);
134 >                        r->gecc = 0.;
135 >                }
136          }
97        mabsorp = bright(mcolor);
137  
138          d2 = 1.0 - nratio*nratio*(1.0 - cos1*cos1);     /* compute cos theta2 */
139  
# Line 115 | Line 154 | register RAY  *r;
154                  d1 = (d1 - d2) / (d1 + d2);
155                  refl += d1 * d1;
156  
157 <                refl /= 2.0;
157 >                refl *= 0.5;
158                  trans = 1.0 - refl;
159  
160 <                if (rayorigin(&p, r, REFRACTED, mabsorp*trans) == 0) {
160 >                if (rayorigin(&p, r, REFRACTED, trans) == 0) {
161  
162                                                  /* compute refracted ray */
163                          d1 = nratio*cos1 - cos2;
164                          for (i = 0; i < 3; i++)
165                                  p.rdir[i] = nratio*r->rdir[i] + d1*dnorm[i];
166 <
166 >                                                /* accidental reflection? */
167 >                        if (hastexture &&
168 >                                DOT(p.rdir,r->ron)*hastexture >= -FTINY) {
169 >                                d1 *= (double)hastexture;
170 >                                for (i = 0; i < 3; i++) /* ignore texture */
171 >                                        p.rdir[i] = nratio*r->rdir[i] +
172 >                                                        d1*r->ron[i];
173 >                                normalize(p.rdir);      /* not exact */
174 >                        }
175   #ifdef  DISPERSE
176                          if (m->otype != MAT_DIELECTRIC
177                                          || r->rod > 0.0
178                                          || r->crtype & SHADOW
179 +                                        || !directvis
180                                          || m->oargs.farg[4] == 0.0
181 <                                        || !disperse(m, r, p.rdir, trans))
181 >                                        || !disperse(m, r, p.rdir,
182 >                                                        trans, ctrans, talb))
183   #endif
184                          {
185 +                                copycolor(p.cext, ctrans);
186 +                                copycolor(p.albedo, talb);
187                                  rayvalue(&p);
137                                multcolor(mcolor, r->pcol);     /* modify */
188                                  scalecolor(p.rcol, trans);
189                                  addcolor(r->rcol, p.rcol);
190 +                                if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY)
191 +                                        r->rt = r->rot + p.rt;
192                          }
193                  }
194          }
195                  
196          if (!(r->crtype & SHADOW) &&
197 <                        rayorigin(&p, r, REFLECTED, mabsorp*refl) == 0) {
197 >                        rayorigin(&p, r, REFLECTED, refl) == 0) {
198  
199                                          /* compute reflected ray */
200                  for (i = 0; i < 3; i++)
201                          p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i];
202 +                                        /* accidental penetration? */
203 +                if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY)
204 +                        for (i = 0; i < 3; i++)         /* ignore texture */
205 +                                p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i];
206  
207                  rayvalue(&p);                   /* reflected ray value */
208  
209                  scalecolor(p.rcol, refl);       /* color contribution */
210                  addcolor(r->rcol, p.rcol);
211          }
212 <
213 <        multcolor(r->rcol, mcolor);             /* multiply by transmittance */
212 >                                /* rayvalue() computes absorption */
213 >        return(1);
214   }
215  
216  
217   #ifdef  DISPERSE
218  
219   static
220 < disperse(m, r, vt, tr)          /* check light sources for dispersion */
220 > disperse(m, r, vt, tr, cet, abt)  /* check light sources for dispersion */
221   OBJREC  *m;
222   RAY  *r;
223   FVECT  vt;
224   double  tr;
225 + COLOR  cet, abt;
226   {
170        double  sqrt();
227          RAY  sray, *entray;
228          FVECT  v1, v2, n1, n2;
229          FVECT  dv, v2Xdv;
230          double  v2Xdvv2Xdv;
231 <        int  sn, success = 0;
232 <        double  omega;
231 >        int  success = 0;
232 >        SRCINDEX  si;
233          FVECT  vtmp1, vtmp2;
234          double  dtmp1, dtmp2;
235          int  l1, l2;
# Line 235 | Line 291 | double  tr;
291          v2Xdvv2Xdv = DOT(v2Xdv, v2Xdv);
292  
293                                          /* check sources */
294 <        for (sn = 0; sn < nsources; sn++) {
294 >        initsrcindex(&si);
295 >        while (srcray(&sray, r, &si)) {
296  
297 <                if ((omega = srcray(&sray, r, sn)) == 0.0 ||
241 <                                DOT(sray.rdir, v2) < MINCOS)
297 >                if (DOT(sray.rdir, v2) < MINCOS)
298                          continue;                       /* bad source */
243                
299                                                  /* adjust source ray */
300  
301                  dtmp1 = DOT(v2Xdv, sray.rdir) / v2Xdvv2Xdv;
# Line 253 | Line 308 | double  tr;
308                  if (l1 > MAXLAMBDA || l1 < MINLAMBDA)   /* not visible */
309                          continue;
310                                                  /* trace source ray */
311 +                copycolor(sray.cext, cet);
312 +                copycolor(sray.albedo, abt);
313                  normalize(sray.rdir);
314                  rayvalue(&sray);
315                  if (bright(sray.rcol) <= FTINY) /* missed it */
# Line 265 | Line 322 | double  tr;
322                   */
323                  
324                  fcross(vtmp1, v2Xdv, sray.rdir);
325 <                dtmp1 = sqrt(omega  / v2Xdvv2Xdv / PI);
325 >                dtmp1 = sqrt(si.dom  / v2Xdvv2Xdv / PI);
326  
327                                                          /* compute first ray */
328                  for (i = 0; i < 3; i++)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines