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.15 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.26 by rschregle, Wed May 20 13:12:06 2015 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  dielectric.c - shading function for transparent materials.
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10   #include  "ray.h"
66
11   #include  "otypes.h"
12 + #include  "rtotypes.h"
13 + #include  "pmapmat.h"
14  
15   #ifdef  DISPERSE
16   #include  "source.h"
17 < static  disperse();
18 < static int  lambda();
17 > static int disperse(OBJREC *m,RAY *r,FVECT vt,double tr,COLOR cet,COLOR abt);
18 > static int lambda(OBJREC  *m, FVECT  v2, FVECT  dv, FVECT  lr);
19   #endif
20  
21 + static double mylog(double  x);
22 +
23 +
24   /*
25   *     Explicit calculations for Fresnel's equation are performed,
26   *  but only one square root computation is necessary.
# Line 102 | Line 51 | static int  lambda();
51  
52   #define  MINCOS         0.997           /* minimum dot product for dispersion */
53  
54 <
55 < static double
56 < mylog(x)                /* special log for extinction coefficients */
57 < double  x;
54 > static
55 > double
56 > mylog(          /* special log for extinction coefficients */
57 >        double  x
58 > )
59   {
60          if (x < 1e-40)
61                  return(-100.);
# Line 115 | Line 65 | double  x;
65   }
66  
67  
68 < m_dielectric(m, r)      /* color a ray which hit a dielectric interface */
69 < OBJREC  *m;
70 < register RAY  *r;
68 > int
69 > m_dielectric(   /* color a ray which hit a dielectric interface */
70 >        OBJREC  *m,
71 >        RAY  *r
72 > )
73   {
74          double  cos1, cos2, nratio;
75          COLOR  ctrans;
76          COLOR  talb;
77          int  hastexture;
78 +        double  transdist=0, transtest=0;
79 +        double  mirdist=0, mirtest=0;
80 +        int     flatsurface;
81          double  refl, trans;
82          FVECT  dnorm;
83          double  d1, d2;
84          RAY  p;
85 <        register int  i;
85 >        int  i;
86  
87 +        /* PMAP: skip refracted shadow or ambient ray if accounted for in
88 +           photon map */
89 +        if (shadowRayInPmap(r) || ambRayInPmap(r))
90 +                return(1);
91 +        
92          if (m->oargs.nfargs != (m->otype==MAT_DIELECTRIC ? 5 : 8))
93                  objerror(m, USER, "bad arguments");
94  
95          raytexture(r, m->omod);                 /* get modifiers */
96  
97 <        if (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY)
97 >        if ( (hastexture = DOT(r->pert,r->pert) > FTINY*FTINY) )
98                  cos1 = raynormal(dnorm, r);     /* perturb normal */
99          else {
100                  VCOPY(dnorm, r->ron);
101                  cos1 = r->rod;
102          }
103 +        flatsurface = r->ro != NULL && isflat(r->ro->otype) &&
104 +                        !hastexture | (r->crtype & AMBIENT);
105 +
106                                                  /* index of refraction */
107          if (m->otype == MAT_DIELECTRIC)
108                  nratio = m->oargs.farg[3] + m->oargs.farg[4]/MLAMBDA;
# Line 208 | Line 171 | register RAY  *r;
171  
172                  trans *= nratio*nratio;         /* solid angle ratio */
173  
174 <                if (rayorigin(&p, r, REFRACTED, trans) == 0) {
174 >                setcolor(p.rcoef, trans, trans, trans);
175  
176 +                if (rayorigin(&p, REFRACTED, r, p.rcoef) == 0) {
177 +
178                                                  /* compute refracted ray */
179                          d1 = nratio*cos1 - cos2;
180                          for (i = 0; i < 3; i++)
# Line 222 | Line 187 | register RAY  *r;
187                                          p.rdir[i] = nratio*r->rdir[i] +
188                                                          d1*r->ron[i];
189                                  normalize(p.rdir);      /* not exact */
190 <                        }
190 >                        } else
191 >                                checknorm(p.rdir);
192   #ifdef  DISPERSE
193                          if (m->otype != MAT_DIELECTRIC
194                                          || r->rod > 0.0
# Line 236 | Line 202 | register RAY  *r;
202                                  copycolor(p.cext, ctrans);
203                                  copycolor(p.albedo, talb);
204                                  rayvalue(&p);
205 <                                scalecolor(p.rcol, trans);
205 >                                multcolor(p.rcol, p.rcoef);
206                                  addcolor(r->rcol, p.rcol);
207 <                                if (nratio >= 1.0-FTINY && nratio <= 1.0+FTINY)
208 <                                        r->rt = r->rot + p.rt;
207 >                                                /* virtual distance */
208 >                                if (flatsurface ||
209 >                                        (1.-FTINY <= nratio) &
210 >                                                (nratio <= 1.+FTINY)) {
211 >                                        transtest = 2*bright(p.rcol);
212 >                                        transdist = r->rot + p.rt;
213 >                                }
214                          }
215                  }
216          }
217 <                
217 >        setcolor(p.rcoef, refl, refl, refl);
218 >
219          if (!(r->crtype & SHADOW) &&
220 <                        rayorigin(&p, r, REFLECTED, refl) == 0) {
220 >                        rayorigin(&p, REFLECTED, r, p.rcoef) == 0) {
221  
222                                          /* compute reflected ray */
223 <                for (i = 0; i < 3; i++)
252 <                        p.rdir[i] = r->rdir[i] + 2.0*cos1*dnorm[i];
223 >                VSUM(p.rdir, r->rdir, dnorm, 2.*cos1);
224                                          /* accidental penetration? */
225                  if (hastexture && DOT(p.rdir,r->ron)*hastexture <= FTINY)
226 <                        for (i = 0; i < 3; i++)         /* ignore texture */
227 <                                p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i];
257 <
226 >                        VSUM(p.rdir, r->rdir, r->ron, 2.*r->rod);
227 >                checknorm(p.rdir);
228                  rayvalue(&p);                   /* reflected ray value */
229  
230 <                scalecolor(p.rcol, refl);       /* color contribution */
230 >                multcolor(p.rcol, p.rcoef);     /* color contribution */
231                  addcolor(r->rcol, p.rcol);
232 +                                                /* virtual distance */
233 +                if (flatsurface) {
234 +                        mirtest = 2*bright(p.rcol);
235 +                        mirdist = r->rot + p.rt;
236 +                }
237          }
238 +                                /* check distance to return */
239 +        d1 = bright(r->rcol);
240 +        if (transtest > d1)
241 +                r->rt = transdist;
242 +        else if (mirtest > d1)
243 +                r->rt = mirdist;
244                                  /* rayvalue() computes absorption */
245          return(1);
246   }
# Line 267 | Line 248 | register RAY  *r;
248  
249   #ifdef  DISPERSE
250  
251 < static
252 < disperse(m, r, vt, tr, cet, abt)  /* check light sources for dispersion */
253 < OBJREC  *m;
254 < RAY  *r;
255 < FVECT  vt;
256 < double  tr;
257 < COLOR  cet, abt;
251 > static int
252 > disperse(  /* check light sources for dispersion */
253 >        OBJREC  *m,
254 >        RAY  *r,
255 >        FVECT  vt,
256 >        double  tr,
257 >        COLOR  cet,
258 >        COLOR  abt
259 > )
260   {
261 <        RAY  sray, *entray;
261 >        RAY  sray;
262 >        const RAY  *entray;
263          FVECT  v1, v2, n1, n2;
264          FVECT  dv, v2Xdv;
265          double  v2Xdvv2Xdv;
# Line 330 | Line 314 | COLOR  cet, abt;
314          VCOPY(n2, r->ron);
315  
316                                          /* first order dispersion approx. */
317 <        dtmp1 = DOT(n1, v1);
318 <        dtmp2 = DOT(n2, v2);
317 >        dtmp1 = 1./DOT(n1, v1);
318 >        dtmp2 = 1./DOT(n2, v2);
319          for (i = 0; i < 3; i++)
320 <                dv[i] = v1[i] + v2[i] - n1[i]/dtmp1 - n2[i]/dtmp2;
320 >                dv[i] = v1[i] + v2[i] - n1[i]*dtmp1 - n2[i]*dtmp2;
321                  
322          if (DOT(dv, dv) <= FTINY)       /* null effect */
323                  return(0);
# Line 376 | Line 360 | COLOR  cet, abt;
360                  dtmp1 = sqrt(si.dom  / v2Xdvv2Xdv / PI);
361  
362                                                          /* compute first ray */
363 <                for (i = 0; i < 3; i++)
380 <                        vtmp2[i] = sray.rdir[i] + dtmp1*vtmp1[i];
363 >                VSUM(vtmp2, sray.rdir, vtmp1, dtmp1);
364  
365                  l1 = lambda(m, v2, dv, vtmp2);          /* first lambda */
366                  if (l1 < 0)
367                          continue;
368                                                          /* compute second ray */
369 <                for (i = 0; i < 3; i++)
387 <                        vtmp2[i] = sray.rdir[i] - dtmp1*vtmp1[i];
369 >                VSUM(vtmp2, sray.rdir, vtmp1, -dtmp1);
370  
371                  l2 = lambda(m, v2, dv, vtmp2);          /* second lambda */
372                  if (l2 < 0)
# Line 404 | Line 386 | COLOR  cet, abt;
386  
387  
388   static int
389 < lambda(m, v2, dv, lr)                   /* compute lambda for material */
390 < register OBJREC  *m;
391 < FVECT  v2, dv, lr;
389 > lambda(                 /* compute lambda for material */
390 >        OBJREC  *m,
391 >        FVECT  v2,
392 >        FVECT  dv,
393 >        FVECT  lr
394 > )
395   {
396          FVECT  lrXdv, v2Xlr;
397          double  dtmp, denom;
# Line 414 | Line 399 | FVECT  v2, dv, lr;
399  
400          fcross(lrXdv, lr, dv);
401          for (i = 0; i < 3; i++)
402 <                if (lrXdv[i] > FTINY || lrXdv[i] < -FTINY)
402 >                if ((lrXdv[i] > FTINY) | (lrXdv[i] < -FTINY))
403                          break;
404          if (i >= 3)
405                  return(-1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines