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.14 by greg, Sun Aug 21 22:38:12 2011 UTC vs.
Revision 2.21 by greg, Sat Jun 9 07:16:47 2012 UTC

# Line 82 | Line 82 | typedef struct {
82  
83   /* Jitter ray sample according to projected solid angle and specjitter */
84   static void
85 < bsdf_jitter(FVECT vres, BSDFDAT *ndp, int domax)
85 > bsdf_jitter(FVECT vres, BSDFDAT *ndp, double sr_psa)
86   {
87        double  sr_psa = ndp->sr_vpsa[domax];
88
87          VCOPY(vres, ndp->vray);
88          if (specjitter < 1.)
89                  sr_psa *= specjitter;
# Line 100 | Line 98 | bsdf_jitter(FVECT vres, BSDFDAT *ndp, int domax)
98   static int
99   direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp)
100   {
101 <        int     nsamp = 1, ok = 0;
101 >        int     nsamp, ok = 0;
102          FVECT   vsrc, vsmp, vjit;
103          double  tomega;
104 <        double  sf, sd[2];
104 >        double  sf, tsr, sd[2];
105          COLOR   csmp;
106          SDValue sv;
107          SDError ec;
# Line 111 | Line 109 | direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, B
109                                          /* transform source direction */
110          if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone)
111                  return(0);
112 +                                        /* assign number of samples */
113 +        ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd);
114 +        if (ec)
115 +                goto baderror;
116                                          /* check indirect over-counting */
117          if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT)
118                                  && vsrc[2] > 0 ^ ndp->vray[2] > 0) {
119                  double  dx = vsrc[0] + ndp->vray[0];
120                  double  dy = vsrc[1] + ndp->vray[1];
121 <                if (dx*dx + dy*dy <= omega*(1./PI))
121 >                if (dx*dx + dy*dy <= omega+tomega)
122                          return(0);
123          }
124 <        if (specjitter > FTINY) {       /* assign number of samples */
125 <                ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd);
126 <                if (ec)
127 <                        goto baderror;
128 <                sf = specjitter * ndp->pr->rweight;
129 <                if (tomega <= omega*.01)
128 <                        nsamp = 100.*sf + .5;
129 <                else
130 <                        nsamp = 4.*sf*omega/tomega + .5;
131 <                nsamp += !nsamp;
132 <        }
133 <        sf = sqrt(omega);
124 >        sf = specjitter * ndp->pr->rweight;
125 >        if (25.*tomega <= omega)
126 >                nsamp = 100.*sf + .5;
127 >        else
128 >                nsamp = 4.*sf*omega/tomega + .5;
129 >        nsamp += !nsamp;
130          setcolor(cval, .0, .0, .0);     /* sample our source area */
131 +        sf = sqrt(omega);
132 +        tsr = sqrt(tomega);
133          for (i = nsamp; i--; ) {
134                  VCOPY(vsmp, vsrc);      /* jitter query directions */
135                  if (nsamp > 1) {
# Line 143 | Line 141 | direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, B
141                                  continue;
142                          }
143                  }
144 <                bsdf_jitter(vjit, ndp, 0);
144 >                bsdf_jitter(vjit, ndp, tsr);
145                                          /* compute BSDF */
146                  ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd);
147                  if (ec)
# Line 159 | Line 157 | direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, B
157          return(ok);
158   baderror:
159          objerror(ndp->mp, USER, transSDError(ec));
160 +        return(0);                      /* gratis return */
161   }
162  
163   /* Compute source contribution for BSDF (reflected & transmitted) */
# Line 333 | Line 332 | sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int usep
332          }
333                                                  /* run through our samples */
334          for (nsent = 0; nsent < nstarget; nsent++) {
335 <                if (nstarget == 1)              /* stratify random variable */
335 >                if (nstarget == 1) {            /* stratify random variable */
336                          xrand = urand(ilhash(dimlist,ndims)+samplendx);
337 <                else
337 >                        if (specjitter < 1.)
338 >                                xrand = .5 + specjitter*(xrand-.5);
339 >                } else {
340                          xrand = (nsent + frandom())/(double)nstarget;
341 +                }
342                  SDerrorDetail[0] = '\0';        /* sample direction & coef. */
343 <                bsdf_jitter(vsmp, ndp, 0);
343 >                bsdf_jitter(vsmp, ndp, ndp->sr_vpsa[0]);
344                  ec = SDsampComponent(&bsv, vsmp, xrand, dcp);
345                  if (ec)
346                          objerror(ndp->mp, USER, transSDError(ec));
# Line 399 | Line 401 | sample_sdf(BSDFDAT *ndp, int sflags)
401                          FVECT   vjit;
402                          double  d;
403                          COLOR   ctmp;
404 <                        bsdf_jitter(vjit, ndp, 1);
404 >                        bsdf_jitter(vjit, ndp, ndp->sr_vpsa[1]);
405                          d = SDdirectHemi(vjit, sflags, ndp->sd);
406                          if (sflags == SDsampSpT) {
407                                  copycolor(ctmp, ndp->pr->pcol);
# Line 498 | Line 500 | m_bsdf(OBJREC *m, RAY *r)
500          upvec[1] = evalue(mf->ep[2]);
501          upvec[2] = evalue(mf->ep[3]);
502                                                  /* return to world coords */
503 <        if (mf->f != &unitxf) {
504 <                multv3(upvec, upvec, mf->f->xfm);
505 <                nd.thick *= mf->f->sca;
503 >        if (mf->fxp != &unitxf) {
504 >                multv3(upvec, upvec, mf->fxp->xfm);
505 >                nd.thick *= mf->fxp->sca;
506          }
507          raynormal(nd.pnorm, r);
508                                                  /* compute local BSDF xform */
# Line 513 | Line 515 | m_bsdf(OBJREC *m, RAY *r)
515          }
516          if (!ec)
517                  ec = SDinvXform(nd.fromloc, nd.toloc);
516                                                /* determine BSDF resolution */
517        if (!ec)
518                ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL,
519                                                SDqueryMin+SDqueryMax, nd.sd);
518          if (ec) {
519 <                objerror(m, WARNING, transSDError(ec));
522 <                SDfreeCache(nd.sd);
519 >                objerror(m, WARNING, "Illegal orientation vector");
520                  return(1);
521          }
522 +                                                /* determine BSDF resolution */
523 +        ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin+SDqueryMax, nd.sd);
524 +        if (ec)
525 +                objerror(m, USER, transSDError(ec));
526 +
527          nd.sr_vpsa[0] = sqrt(nd.sr_vpsa[0]);
528          nd.sr_vpsa[1] = sqrt(nd.sr_vpsa[1]);
529          if (!hitfront) {                        /* perturb normal towards hit */
# Line 555 | Line 557 | m_bsdf(OBJREC *m, RAY *r)
557                  bnorm[2] = -nd.pnorm[2];
558                  if (nd.thick != 0) {            /* proxy with offset? */
559                          VCOPY(vtmp, r->rop);
560 <                        VSUM(r->rop, vtmp, r->ron, -nd.thick);
560 >                        VSUM(r->rop, vtmp, r->ron, nd.thick);
561                          multambient(ctmp, r, bnorm);
562                          VCOPY(r->rop, vtmp);
563                  } else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines