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.35 by greg, Tue May 16 02:52:15 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 134 | Line 137 | compute_through(BSDFDAT *ndp)
137                  tdir[0] = -ndp->vray[0] + dir2check[i][0]*srchrad;
138                  tdir[1] = -ndp->vray[1] + dir2check[i][1]*srchrad;
139                  tdir[2] = -ndp->vray[2];
140 <                if (normalize(tdir) == 0)
138 <                        continue;
140 >                normalize(tdir);
141                  ec = SDevalBSDF(&sv, tdir, ndp->vray, ndp->sd);
142                  if (ec)
143                          goto baderror;
# Line 188 | Line 190 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
190   {
191          int     nsamp, ok = 0;
192          FVECT   vsrc, vsmp, vjit;
193 <        double  tomega;
193 >        double  tomega, tomega2;
194          double  sf, tsr, sd[2];
195          COLOR   csmp, cdiff;
196          double  diffY;
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 223 | 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 244 | 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 */
248 <        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 253 | Line 259 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
259                          multisamp(sd, 2, (i + frandom())/(double)nsamp);
260                          vsmp[0] += (sd[0] - .5)*sf;
261                          vsmp[1] += (sd[1] - .5)*sf;
262 <                        if (normalize(vsmp) == 0) {
257 <                                --nsamp;
258 <                                continue;
259 <                        }
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) {
267 <                        addcolor(cval, cdiff);
269 >                if (sv.cieY - diffY <= FTINY)
270                          continue;       /* no specular part */
271 <                }
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 */
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)nsamp;
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