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.37 by greg, Thu May 18 17:59:37 2017 UTC

# Line 134 | Line 134 | compute_through(BSDFDAT *ndp)
134                  tdir[0] = -ndp->vray[0] + dir2check[i][0]*srchrad;
135                  tdir[1] = -ndp->vray[1] + dir2check[i][1]*srchrad;
136                  tdir[2] = -ndp->vray[2];
137 <                if (normalize(tdir) == 0)
138 <                        continue;
137 >                normalize(tdir);
138                  ec = SDevalBSDF(&sv, tdir, ndp->vray, ndp->sd);
139                  if (ec)
140                          goto baderror;
# Line 188 | Line 187 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
187   {
188          int     nsamp, ok = 0;
189          FVECT   vsrc, vsmp, vjit;
190 <        double  tomega;
190 >        double  tomega, tomega2;
191          double  sf, tsr, sd[2];
192          COLOR   csmp, cdiff;
193          double  diffY;
194          SDValue sv;
195          SDError ec;
196          int     i;
197 +                                        /* in case we fail */
198 +        setcolor(cval, .0, .0, .0);
199                                          /* transform source direction */
200          if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone)
201                  return(0);
# Line 223 | Line 224 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
224                  diffY = .0;
225                  setcolor(cdiff, .0, .0, .0);
226          }
227 <                                        /* assign number of samples */
227 >                                        /* need projected solid angles */
228 >        omega *= fabs(vsrc[2]);
229          ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd);
230          if (ec)
231                  goto baderror;
# Line 233 | Line 235 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
235                                  && (vsrc[2] > 0) ^ (ndp->vray[2] > 0)) {
236                  double  dx = vsrc[0] + ndp->vray[0];
237                  double  dy = vsrc[1] + ndp->vray[1];
238 <                if (dx*dx + dy*dy <= omega+tomega)
238 >                if (dx*dx + dy*dy <= (4./PI)*(omega + tomega +
239 >                                                2.*sqrt(omega*tomega)))
240                          return(0);
241          }
242 +                                        /* assign number of samples */
243          sf = specjitter * ndp->pr->rweight;
244          if (tomega <= .0)
245                  nsamp = 1;
# Line 244 | Line 248 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
248          else
249                  nsamp = 4.*sf*omega/tomega + .5;
250          nsamp += !nsamp;
251 <        setcolor(cval, .0, .0, .0);     /* sample our source area */
248 <        sf = sqrt(omega);
251 >        sf = sqrt(omega);               /* sample our source area */
252          tsr = sqrt(tomega);
253          for (i = nsamp; i--; ) {
254                  VCOPY(vsmp, vsrc);      /* jitter query directions */
# Line 253 | Line 256 | direct_specular_OK(COLOR cval, FVECT ldir, double omeg
256                          multisamp(sd, 2, (i + frandom())/(double)nsamp);
257                          vsmp[0] += (sd[0] - .5)*sf;
258                          vsmp[1] += (sd[1] - .5)*sf;
259 <                        if (normalize(vsmp) == 0) {
257 <                                --nsamp;
258 <                                continue;
259 <                        }
259 >                        normalize(vsmp);
260                  }
261                  bsdf_jitter(vjit, ndp, tsr);
262                                          /* compute BSDF */
263                  ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd);
264                  if (ec)
265                          goto baderror;
266 <                if (sv.cieY - diffY <= FTINY) {
267 <                        addcolor(cval, cdiff);
266 >                if (sv.cieY - diffY <= FTINY)
267                          continue;       /* no specular part */
268 <                }
268 >                                        /* check for variable resolution */
269 >                ec = SDsizeBSDF(&tomega2, vjit, vsmp, SDqueryMin, ndp->sd);
270 >                if (ec)
271 >                        goto baderror;
272 >                if (tomega2 < .12*tomega)
273 >                        continue;       /* not safe to include */
274                  cvt_sdcolor(csmp, &sv);
275                  addcolor(cval, csmp);   /* else average it in */
276                  ++ok;
277          }
278 <        if (!ok) {
279 <                setcolor(cval, .0, .0, .0);
280 <                return(0);              /* no valid specular samples */
281 <        }
278 <        sf = 1./(double)nsamp;
278 >        if (!ok)                        /* no valid specular samples? */
279 >                return(0);
280 >
281 >        sf = 1./(double)ok;             /* compute average BSDF */
282          scalecolor(cval, sf);
283                                          /* subtract diffuse contribution */
284          for (i = 3*(diffY > FTINY); i--; )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines