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

Comparing ray/src/cv/bsdfinterp.c (file contents):
Revision 2.13 by greg, Thu Sep 26 17:15:22 2013 UTC vs.
Revision 2.16 by greg, Tue Feb 18 16:06:51 2014 UTC

# Line 94 | Line 94 | on_edge(const MIGRATION *ej, const FVECT ivec)
94          cos_a = DOT(ej->rbfv[0]->invec, ivec);
95          if (cos_a <= 0)
96                  return(0);
97 +        if (cos_a >= 1.)                /* handles rounding error */
98 +                return(1);
99  
100          cos_b = DOT(ej->rbfv[1]->invec, ivec);
101          if (cos_b <= 0)
102                  return(0);
103 +        if (cos_b >= 1.)
104 +                return(1);
105  
106          cos_aplusb = cos_a*cos_b - sqrt((1.-cos_a*cos_a)*(1.-cos_b*cos_b));
107          if (cos_aplusb <= 0)
# Line 204 | Line 208 | get_interp(MIGRATION *miga[3], FVECT invec)
208          if (single_plane_incident) {            /* isotropic BSDF? */
209              RBFNODE     *rbf;                   /* find edge we're on */
210              for (rbf = dsf_list; rbf != NULL; rbf = rbf->next) {
211 <                if (input_orient*rbf->invec[2] < input_orient*invec[2])
211 >                if (input_orient*rbf->invec[2] < input_orient*invec[2]-FTINY)
212                          break;
213                  if (rbf->next != NULL && input_orient*rbf->next->invec[2] <
214 <                                                        input_orient*invec[2]) {
214 >                                                input_orient*invec[2]+FTINY) {
215                      for (miga[0] = rbf->ejl; miga[0] != NULL;
216                                          miga[0] = nextedge(rbf,miga[0]))
217                          if (opp_rbf(rbf,miga[0]) == rbf->next) {
# Line 320 | Line 324 | tryagain:
324              for (j = 0; j < mtx_ncols(mig); j++)
325                  if ((mv = mtx_coef(mig,i,j)) > cthresh) {
326                          const RBFVAL    *rbf1j = &mig->rbfv[1]->rbfa[j];
327 <                        double          rad1 = R2ANG(rbf1j->crad);
327 >                        double          rad2;
328                          FVECT           v;
329                          int             pos[2];
330 <                        rbf->rbfa[n].peak = peak0 * mv * rbf->vtotal;
331 <                        rbf->rbfa[n].crad = ANG2R(sqrt(rad0*rad0*(1.-t) +
332 <                                                        rad1*rad1*t));
330 >                        rad2 = R2ANG(rbf1j->crad);
331 >                        rad2 = rad0*rad0*(1.-t) + rad2*rad2*t;
332 >                        rbf->rbfa[n].peak = peak0 * mv * rbf->vtotal *
333 >                                                rad0*rad0/rad2;
334 >                        rbf->rbfa[n].crad = ANG2R(sqrt(rad2));
335                          ovec_from_pos(v, rbf1j->gx, rbf1j->gy);
336                          geodesic(v, v0, v, t, GEOD_REL);
337                          pos_from_vec(pos, v);
# Line 342 | Line 348 | memerr:
348          return(NULL);   /* pro forma return */
349   }
350  
351 < /* Partially advect between recorded incident angles and allocate new RBF */
351 > /* Advect between recorded incident angles and allocate new RBF */
352   RBFNODE *
353   advect_rbf(const FVECT invec, int lobe_lim)
354   {
# Line 369 | Line 375 | advect_rbf(const FVECT invec, int lobe_lim)
375                  return(rbf);
376          }
377   #ifdef DEBUG
378 <        if (miga[0]->rbfv[0] != miga[2]->rbfv[0] |
379 <                        miga[0]->rbfv[1] != miga[1]->rbfv[0] |
380 <                        miga[1]->rbfv[1] != miga[2]->rbfv[1]) {
378 >        if ((miga[0]->rbfv[0] != miga[2]->rbfv[0]) |
379 >                        (miga[0]->rbfv[1] != miga[1]->rbfv[0]) |
380 >                        (miga[1]->rbfv[1] != miga[2]->rbfv[1])) {
381                  fprintf(stderr, "%s: Triangle vertex screw-up!\n", progname);
382                  exit(1);
383          }
# Line 426 | Line 432 | tryagain:
432              for (j = 0; j < mtx_ncols(miga[0]); j++) {
433                  const float     ma = mtx_coef(miga[0],i,j);
434                  const RBFVAL    *rbf1j;
435 <                double          rad1j, srad2;
435 >                double          srad2;
436                  if (ma <= cthresh)
437                          continue;
438                  rbf1j = &miga[0]->rbfv[1]->rbfa[j];
439 <                rad1j = R2ANG(rbf1j->crad);
440 <                srad2 = (1.-s)*(1.-t)*rad0i*rad0i + s*(1.-t)*rad1j*rad1j;
439 >                srad2 = R2ANG(rbf1j->crad);
440 >                srad2 = (1.-s)*(1.-t)*rad0i*rad0i + s*(1.-t)*srad2*srad2;
441                  ovec_from_pos(v1, rbf1j->gx, rbf1j->gy);
442                  geodesic(v1, v0, v1, s, GEOD_REL);
443                  for (k = 0; k < mtx_ncols(miga[2]); k++) {
444                      float               mb = mtx_coef(miga[1],j,k);
445                      float               mc = mtx_coef(miga[2],i,k);
446                      const RBFVAL        *rbf2k;
447 <                    double              rad2k;
447 >                    double              rad2;
448                      int                 pos[2];
449                      if ((mb <= cthresh) & (mc <= cthresh))
450                          continue;
451                      rbf2k = &miga[2]->rbfv[1]->rbfa[k];
452 <                    rbf->rbfa[n].peak = w0i * ma * (mb*mbfact + mc*mcfact);
453 <                    rad2k = R2ANG(rbf2k->crad);
454 <                    rbf->rbfa[n].crad = ANG2R(sqrt(srad2 + t*rad2k*rad2k));
452 >                    rad2 = R2ANG(rbf2k->crad);
453 >                    rad2 = srad2 + t*rad2*rad2;
454 >                    rbf->rbfa[n].peak = w0i * ma * (mb*mbfact + mc*mcfact) *
455 >                                        rad0i*rad0i/rad2;
456 >                    rbf->rbfa[n].crad = ANG2R(sqrt(rad2));
457                      ovec_from_pos(v2, rbf2k->gx, rbf2k->gy);
458                      geodesic(v2, v1, v2, t, GEOD_REL);
459                      pos_from_vec(pos, v2);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines