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.36 by greg, Tue May 16 20:06:40 2017 UTC vs.
Revision 2.38 by greg, Fri May 19 15:13:41 2017 UTC

# Line 114 | Line 114 | compute_through(BSDFDAT *ndp)
114  
115          setcolor(ndp->cthru, .0, .0, .0);       /* starting assumption */
116  
117 +        if (!(ndp->pr->crtype & (SPECULAR|AMBIENT|SHADOW)))
118 +                return;                         /* simply don't need to know */
119 +
120          if (ndp->pr->rod > 0)
121                  dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb;
122          else
# Line 194 | Line 197 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
197          SDValue sv;
198          SDError ec;
199          int     i;
200 +                                        /* in case we fail */
201 +        setcolor(cval, .0, .0, .0);
202                                          /* transform source direction */
203          if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone)
204                  return(0);
# Line 222 | Line 227 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
227                  diffY = .0;
228                  setcolor(cdiff, .0, .0, .0);
229          }
230 <                                        /* assign number of samples */
230 >                                        /* need projected solid angles */
231 >        omega *= fabs(vsrc[2]);
232          ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd);
233          if (ec)
234                  goto baderror;
235                                          /* check indirect over-counting */
236 <        if ((ndp->thick != 0 || bright(ndp->cthru) > FTINY)
237 <                                && ndp->pr->crtype & (SPECULAR|AMBIENT)
238 <                                && (vsrc[2] > 0) ^ (ndp->vray[2] > 0)) {
236 >        if (ndp->pr->crtype & (SPECULAR|AMBIENT)
237 >                                && (vsrc[2] > 0) ^ (ndp->vray[2] > 0)
238 >                                && bright(ndp->cthru) > FTINY) {
239                  double  dx = vsrc[0] + ndp->vray[0];
240                  double  dy = vsrc[1] + ndp->vray[1];
241 <                if (dx*dx + dy*dy <= omega+tomega)
241 >                if (dx*dx + dy*dy <= (4./PI)*(omega + tomega +
242 >                                                2.*sqrt(omega*tomega)))
243                          return(0);
244          }
245 +                                        /* assign number of samples */
246          sf = specjitter * ndp->pr->rweight;
247          if (tomega <= .0)
248                  nsamp = 1;
# Line 243 | Line 251 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
251          else
252                  nsamp = 4.*sf*omega/tomega + .5;
253          nsamp += !nsamp;
254 <        setcolor(cval, .0, .0, .0);     /* sample our source area */
247 <        sf = sqrt(omega);
254 >        sf = sqrt(omega);               /* sample our source area */
255          tsr = sqrt(tomega);
256          for (i = nsamp; i--; ) {
257                  VCOPY(vsmp, vsrc);      /* jitter query directions */
# Line 255 | Line 262 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
262                          normalize(vsmp);
263                  }
264                  bsdf_jitter(vjit, ndp, tsr);
265 +                                        /* compute BSDF */
266 +                ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd);
267 +                if (ec)
268 +                        goto baderror;
269 +                if (sv.cieY - diffY <= FTINY)
270 +                        continue;       /* no specular part */
271                                          /* check for variable resolution */
272                  ec = SDsizeBSDF(&tomega2, vjit, vsmp, SDqueryMin, ndp->sd);
273                  if (ec)
274                          goto baderror;
275                  if (tomega2 < .12*tomega)
276                          continue;       /* not safe to include */
264                                        /* else compute BSDF */
265                ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd);
266                if (ec)
267                        goto baderror;
268                if (sv.cieY - diffY <= FTINY)
269                        continue;       /* no specular part */
277                  cvt_sdcolor(csmp, &sv);
278                  addcolor(cval, csmp);   /* else average it in */
279                  ++ok;
280          }
281 <        if (!ok) {
282 <                setcolor(cval, .0, .0, .0);
283 <                return(0);              /* no valid specular samples */
284 <        }
278 <        sf = 1./(double)ok;
281 >        if (!ok)                        /* no valid specular samples? */
282 >                return(0);
283 >
284 >        sf = 1./(double)ok;             /* compute average BSDF */
285          scalecolor(cval, sf);
286                                          /* subtract diffuse contribution */
287          for (i = 3*(diffY > FTINY); i--; )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines