ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/m_bsdf.c
(Generate patch)

Comparing ray/src/rt/m_bsdf.c (file contents):
Revision 2.40 by greg, Mon Jul 17 00:14:28 2017 UTC vs.
Revision 2.48 by greg, Fri May 11 14:26:24 2018 UTC

# Line 106 | Line 106 | compute_through(BSDFDAT *ndp)
106                                          {0, -1.6},
107                                          {1.6, 0},
108                                  };
109 <        const double    peak_over = 2.0;
109 >        const double    peak_over = 1.5;
110          SDSpectralDF    *dfp;
111          FVECT           pdir;
112          double          tomega, srchrad;
# Line 128 | Line 128 | compute_through(BSDFDAT *ndp)
128          srchrad = sqrt(dfp->minProjSA);         /* else search for peak */
129          setcolor(vpeak, 0, 0, 0);
130          setcolor(vsum, 0, 0, 0);
131 +        pdir[2] = 0.0;
132          for (i = 0; i < NDIR2CHECK; i++) {
133                  FVECT   tdir;
134                  SDValue sv;
# Line 141 | Line 142 | compute_through(BSDFDAT *ndp)
142                          goto baderror;
143                  cvt_sdcolor(vcol, &sv);
144                  addcolor(vsum, vcol);
145 <                if (bright(vcol) > bright(vpeak)) {
145 >                if (sv.cieY > bright(vpeak)) {
146                          copycolor(vpeak, vcol);
147                          VCOPY(pdir, tdir);
148                  }
149          }
150 +        if (pdir[2] == 0.0)
151 +                return;                         /* zero neighborhood */
152          ec = SDsizeBSDF(&tomega, pdir, ndp->vray, SDqueryMin, ndp->sd);
153          if (ec)
154                  goto baderror;
155          if (tomega > 1.5*dfp->minProjSA)
156                  return;                         /* not really a peak? */
157 +        tomega /= fabs(pdir[2]);                /* remove cosine factor */
158          if ((bright(vpeak) - ndp->sd->tLamb.cieY*(1./PI))*tomega <= .001)
159                  return;                         /* < 0.1% transmission */
160          for (i = 3; i--; )                      /* remove peak from average */
# Line 184 | Line 188 | bsdf_jitter(FVECT vres, BSDFDAT *ndp, double sr_psa)
188   static int
189   direct_specular_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp)
190   {
191 <        int     nsamp, ok = 0;
191 >        int     nsamp;
192 >        double  wtot = 0;
193          FVECT   vsrc, vsmp, vjit;
194          double  tomega, tomega2;
195          double  sf, tsr, sd[2];
# Line 232 | Line 237 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
237          if ((vsrc[2] > 0) ^ (ndp->vray[2] > 0) && bright(ndp->cthru) > FTINY) {
238                  double  dx = vsrc[0] + ndp->vray[0];
239                  double  dy = vsrc[1] + ndp->vray[1];
240 <                if (dx*dx + dy*dy <= (4./PI)*(omega + tomega +
240 >                if (dx*dx + dy*dy <= (1.5*4./PI)*(omega + tomega +
241                                                  2.*sqrt(omega*tomega)))
242                          return(0);
243          }
# Line 269 | Line 274 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
274                  if (tomega2 < .12*tomega)
275                          continue;       /* not safe to include */
276                  cvt_sdcolor(csmp, &sv);
277 <                addcolor(cval, csmp);   /* else average it in */
278 <                ++ok;
277 >
278 >                if (sf < 2.5*tsr) {     /* weight by Y for small sources */
279 >                        scalecolor(csmp, sv.cieY);
280 >                        wtot += sv.cieY;
281 >                } else
282 >                        wtot += 1.;
283 >                addcolor(cval, csmp);
284          }
285 <        if (!ok)                        /* no valid specular samples? */
285 >        if (wtot <= FTINY)              /* no valid specular samples? */
286                  return(0);
287  
288 <        sf = 1./(double)ok;             /* compute average BSDF */
288 >        sf = 1./wtot;                   /* weighted average BSDF */
289          scalecolor(cval, sf);
290                                          /* subtract diffuse contribution */
291          for (i = 3*(diffY > FTINY); i--; )
# Line 431 | Line 441 | dir_btdf(
441   static int
442   sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int xmit)
443   {
444 <        int     hasthru = (xmit && !(ndp->pr->crtype & (SPECULAR|AMBIENT))
445 <                                && bright(ndp->cthru) > FTINY);
446 <        int     nstarget = 1;
447 <        int     nsent = 0;
448 <        int     n;
449 <        SDError ec;
450 <        SDValue bsv;
451 <        double  xrand;
452 <        FVECT   vsmp, vinc;
453 <        RAY     sr;
444 >        const int       hasthru = (xmit &&
445 >                                        !(ndp->pr->crtype & (SPECULAR|AMBIENT))
446 >                                        && bright(ndp->cthru) > FTINY);
447 >        int             nstarget = 1;
448 >        int             nsent = 0;
449 >        int             n;
450 >        SDError         ec;
451 >        SDValue         bsv;
452 >        double          xrand;
453 >        FVECT           vsmp, vinc;
454 >        RAY             sr;
455                                                  /* multiple samples? */
456          if (specjitter > 1.5) {
457                  nstarget = specjitter*ndp->pr->rweight + .5;
# Line 479 | Line 490 | sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int xmit
490                  if (xmit)                       /* apply pattern on transmit */
491                          multcolor(sr.rcoef, ndp->pr->pcol);
492                  if (rayorigin(&sr, SPECULAR, ndp->pr, sr.rcoef) < 0) {
493 <                        if (maxdepth > 0)
494 <                                break;
495 <                        continue;               /* Russian roulette victim */
493 >                        if (!n & (nstarget > 1)) {
494 >                                nstarget = nstarget*sr.rweight/minweight;
495 >                                n = -1;         /* moved target */
496 >                        }
497 >                        continue;               /* try again */
498                  }
499                  if (xmit && ndp->thick != 0)    /* need to offset origin? */
500                          VSUM(sr.rorg, sr.rorg, ndp->pr->ron, -ndp->thick);
# Line 497 | Line 510 | sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int xmit
510   static int
511   sample_sdf(BSDFDAT *ndp, int sflags)
512   {
513 <        int             hasthru = (sflags == SDsampSpT
514 <                                    && !(ndp->pr->crtype & (SPECULAR|AMBIENT))
515 <                                    && bright(ndp->cthru) > FTINY);
513 >        int             hasthru = (sflags == SDsampSpT &&
514 >                                        !(ndp->pr->crtype & (SPECULAR|AMBIENT))
515 >                                        && bright(ndp->cthru) > FTINY);
516          int             n, ntotal = 0;
517          double          b = 0;
518          SDSpectralDF    *dfp;
# Line 522 | Line 535 | sample_sdf(BSDFDAT *ndp, int sflags)
535          if (dfp == NULL)                        /* no specular component? */
536                  return(0);
537  
525        dimlist[ndims++] = (int)(size_t)ndp->mp;
538          if (hasthru) {                          /* separate view sample? */
539                  RAY     tr;
540                  if (rayorigin(&tr, TRANS, ndp->pr, ndp->cthru) == 0) {
# Line 535 | Line 547 | sample_sdf(BSDFDAT *ndp, int sflags)
547                  } else
548                          hasthru = 0;
549          }
550 <        ndims--;
539 <        if (dfp->maxHemi - b <= FTINY) {        /* how specular to sample? */
550 >        if (dfp->maxHemi - b <= FTINY) {        /* have specular to sample? */
551                  b = 0;
552          } else {
553                  FVECT   vjit;
# Line 554 | Line 565 | sample_sdf(BSDFDAT *ndp, int sflags)
565                  }
566                  return(ntotal);
567          }
568 <        ndims += 2;                             /* else sample specular */
568 >        dimlist[ndims] = (int)(size_t)ndp->mp;  /* else sample specular */
569 >        ndims += 2;
570          for (n = dfp->ncomp; n--; ) {           /* loop over components */
571                  dimlist[ndims-1] = n + 9438;
572                  ntotal += sample_sdcomp(ndp, &dfp->comp[n], sflags==SDsampSpT);
# Line 666 | Line 678 | m_bsdf(OBJREC *m, RAY *r)
678          if (r->crtype & SHADOW) {
679                  RAY     tr;                     /* attempt to pass shadow ray */
680                  if (rayorigin(&tr, TRANS, r, nd.cthru) < 0)
681 <                        return(1);              /* blocked */
681 >                        return(1);              /* no through component */
682                  VCOPY(tr.rdir, r->rdir);
683                  rayvalue(&tr);                  /* transmit with scaling */
684                  multcolor(tr.rcol, tr.rcoef);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines