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.21 by greg, Sun Sep 26 15:51:15 2010 UTC vs.
Revision 2.26 by rschregle, Wed May 20 13:12:06 2015 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10   #include  "ray.h"
11   #include  "otypes.h"
12   #include  "rtotypes.h"
13 + #include  "pmapmat.h"
14  
15   #ifdef  DISPERSE
16   #include  "source.h"
# Line 50 | Line 51 | static double mylog(double  x);
51  
52   #define  MINCOS         0.997           /* minimum dot product for dispersion */
53  
54 <
55 < static double
54 > static
55 > double
56   mylog(          /* special log for extinction coefficients */
57          double  x
58   )
# Line 64 | Line 65 | mylog(         /* special log for extinction coefficients */
65   }
66  
67  
68 < extern int
68 > int
69   m_dielectric(   /* color a ray which hit a dielectric interface */
70          OBJREC  *m,
71 <        register RAY  *r
71 >        RAY  *r
72   )
73   {
74          double  cos1, cos2, nratio;
75          COLOR  ctrans;
76          COLOR  talb;
77          int  hastexture;
78 <        double  transdist, transtest=0;
79 <        double  mirdist, mirtest=0;
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  
# Line 94 | Line 100 | m_dielectric(  /* color a ray which hit a dielectric in
100                  VCOPY(dnorm, r->ron);
101                  cos1 = r->rod;
102          }
103 <        flatsurface = !hastexture && r->ro != NULL && isflat(r->ro->otype);
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)
# Line 199 | Line 206 | m_dielectric(  /* color a ray which hit a dielectric in
206                                  addcolor(r->rcol, p.rcol);
207                                                  /* virtual distance */
208                                  if (flatsurface ||
209 <                                        (1.-FTINY <= nratio &&
210 <                                                nratio <= 1.+FTINY)) {
209 >                                        (1.-FTINY <= nratio) &
210 >                                                (nratio <= 1.+FTINY)) {
211                                          transtest = 2*bright(p.rcol);
212                                          transdist = r->rot + p.rt;
213                                  }
# Line 213 | Line 220 | m_dielectric(  /* color a ray which hit a dielectric in
220                          rayorigin(&p, REFLECTED, r, p.rcoef) == 0) {
221  
222                                          /* compute reflected ray */
223 <                for (i = 0; i < 3; i++)
217 <                        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 */
221 <                                p.rdir[i] = r->rdir[i] + 2.0*r->rod*r->ron[i];
226 >                        VSUM(p.rdir, r->rdir, r->ron, 2.*r->rod);
227                  checknorm(p.rdir);
228                  rayvalue(&p);                   /* reflected ray value */
229  
# Line 309 | Line 314 | disperse(  /* check light sources for dispersion */
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 355 | Line 360 | disperse(  /* check light sources for dispersion */
360                  dtmp1 = sqrt(si.dom  / v2Xdvv2Xdv / PI);
361  
362                                                          /* compute first ray */
363 <                for (i = 0; i < 3; i++)
359 <                        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++)
366 <                        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 384 | Line 387 | disperse(  /* check light sources for dispersion */
387  
388   static int
389   lambda(                 /* compute lambda for material */
390 <        register OBJREC  *m,
390 >        OBJREC  *m,
391          FVECT  v2,
392          FVECT  dv,
393          FVECT  lr
# Line 396 | Line 399 | lambda(                        /* compute lambda for material */
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