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.66 by greg, Wed Oct 13 20:03:31 2021 UTC vs.
Revision 2.70 by greg, Wed Mar 9 00:27:25 2022 UTC

# Line 135 | Line 135 | compute_through(BSDFDAT *ndp)
135          FVECT           pdir;
136          double          tomega, srchrad;
137          double          tomsum, tomsurr;
138 <        COLOR           vpeak, vsurr;
138 >        COLOR           vpeak, vsurr, btdiff;
139          double          vypeak;
140          int             i, ns;
141          SDError         ec;
# Line 156 | Line 156 | compute_through(BSDFDAT *ndp)
156                  psamp[i].tdir[1] = -ndp->vray[1] + dir2check[i][1]*srchrad;
157                  psamp[i].tdir[2] = -ndp->vray[2];
158                  normalize(psamp[i].tdir);
159 <                ec = SDevalBSDF(&sv, psamp[i].tdir, ndp->vray, ndp->sd);
159 >                ec = SDevalBSDF(&sv, ndp->vray, psamp[i].tdir, ndp->sd);
160                  if (ec)
161                          goto baderror;
162                  cvt_sdcolor(psamp[i].vcol, &sv);
# Line 173 | Line 173 | compute_through(BSDFDAT *ndp)
173                  if (i && psamp[i].vy == psamp[i-1].vy)
174                          continue;               /* assume duplicate sample */
175  
176 <                ec = SDsizeBSDF(&tomega, psamp[i].tdir, ndp->vray,
176 >                ec = SDsizeBSDF(&tomega, ndp->vray, psamp[i].tdir,
177                                                  SDqueryMin, ndp->sd);
178                  if (ec)
179                          goto baderror;
# Line 192 | Line 192 | compute_through(BSDFDAT *ndp)
192                  vypeak += psamp[i].vy;
193                  ++ns;
194          }
195 <        if (tomsurr <= FTINY)                   /* no surround implies no peak */
195 >        if (tomsurr < 0.2*tomsum)               /* insufficient surround? */
196                  return;
197        if ((vypeak/ns - (ndp->vray[2] > 0 ? ndp->sd->tLambFront.cieY
198                        : ndp->sd->tLambBack.cieY)*(1./PI))*tomsum < .0005)
199                return;                         /* < 0.05% transmission */
200        copycolor(ndp->cthru, vpeak);           /* already scaled by omega */
201        multcolor(ndp->cthru, ndp->pr->pcol);   /* modify by pattern */
197          scalecolor(vsurr, 1./tomsurr);          /* surround is avg. BTDF */
198 +        if (ndp->vray[2] > 0)                   /* get diffuse BTDF */
199 +                cvt_sdcolor(btdiff, &ndp->sd->tLambFront);
200 +        else
201 +                cvt_sdcolor(btdiff, &ndp->sd->tLambBack);
202 +        scalecolor(btdiff, (1./PI));
203 +        for (i = 3; i--; ) {                    /* remove diffuse contrib. */
204 +                if ((colval(vpeak,i) -= tomsum*colval(btdiff,i)) < 0)
205 +                        colval(vpeak,i) = 0;
206 +                if ((colval(vsurr,i) -= colval(btdiff,i)) < 0)
207 +                        colval(vsurr,i) = 0;
208 +        }
209 +        if (bright(vpeak) < .0005)              /* < 0.05% specular? */
210 +                return;
211 +        multcolor(vsurr, ndp->pr->pcol);        /* modify by color */
212 +        multcolor(vpeak, ndp->pr->pcol);
213 +        copycolor(ndp->cthru, vpeak);
214          copycolor(ndp->cthru_surr, vsurr);
204        multcolor(ndp->cthru_surr, ndp->pr->pcol);
215          return;
216   baderror:
217          objerror(ndp->mp, USER, transSDError(ec));
# Line 241 | Line 251 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
251                                          /* transform source direction */
252          if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone)
253                  return(0);
254 +                                        /* check indirect over-counting */
255 +        if ((vsrc[2] > 0) ^ (ndp->vray[2] > 0) && bright(ndp->cthru) > FTINY) {
256 +                double          dx = vsrc[0] + ndp->vray[0];
257 +                double          dy = vsrc[1] + ndp->vray[1];
258 +                SDSpectralDF    *dfp = (ndp->pr->rod > 0) ?
259 +                        ((ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb) :
260 +                        ((ndp->sd->tb != NULL) ? ndp->sd->tb : ndp->sd->tf) ;
261 +
262 +                tomega = omega*fabs(vsrc[2]);
263 +                if (dx*dx + dy*dy <= (2.5*4./PI)*(tomega + dfp->minProjSA +
264 +                                                2.*sqrt(tomega*dfp->minProjSA))) {
265 +                        if (bright(ndp->cthru_surr) <= FTINY)
266 +                                return(0);
267 +                        copycolor(cval, ndp->cthru_surr);
268 +                        return(1);      /* return non-zero surround BTDF */
269 +                }
270 +        }
271                                          /* will discount diffuse portion */
272          switch ((vsrc[2] > 0)<<1 | (ndp->vray[2] > 0)) {
273          case 3:
# Line 270 | Line 297 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
297          } else {
298                  diffY = 0;
299                  setcolor(cdiff,  0, 0, 0);
273        }
274                                        /* check indirect over-counting */
275        if ((vsrc[2] > 0) ^ (ndp->vray[2] > 0) && bright(ndp->cthru) > FTINY) {
276                double          dx = vsrc[0] + ndp->vray[0];
277                double          dy = vsrc[1] + ndp->vray[1];
278                SDSpectralDF    *dfp = (ndp->pr->rod > 0) ?
279                        ((ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb) :
280                        ((ndp->sd->tb != NULL) ? ndp->sd->tb : ndp->sd->tf) ;
281
282                tomega = omega*fabs(vsrc[2]);
283                if (dx*dx + dy*dy <= (2.5*4./PI)*(tomega + dfp->minProjSA +
284                                                2.*sqrt(tomega*dfp->minProjSA))) {
285                        if (bright(ndp->cthru_surr) <= FTINY)
286                                return(0);
287                        copycolor(cval, ndp->cthru_surr);
288                        return(1);      /* return non-zero surround BTDF */
289                }
300          }
301          ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd);
302          if (ec)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines