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.12 by greg, Sun Aug 21 16:55:29 2011 UTC vs.
Revision 2.14 by greg, Sun Aug 21 22:38:12 2011 UTC

# Line 68 | Line 68 | typedef struct {
68          FVECT   pnorm;          /* perturbed surface normal */
69          FVECT   vray;           /* local outgoing (return) vector */
70          double  sr_vpsa[2];     /* sqrt of BSDF projected solid angle extrema */
71        double  thru_r2;        /* through rejection angle squared */
71          RREAL   toloc[3][3];    /* world to local BSDF coords */
72          RREAL   fromloc[3][3];  /* local BSDF coords to world */
73          double  thick;          /* surface thickness */
# Line 99 | Line 98 | bsdf_jitter(FVECT vres, BSDFDAT *ndp, int domax)
98  
99   /* Evaluate BSDF for direct component, returning true if OK to proceed */
100   static int
101 < direct_bsdf_OK(COLOR cval, FVECT ldir, BSDFDAT *ndp)
101 > direct_bsdf_OK(COLOR cval, FVECT ldir, double omega, BSDFDAT *ndp)
102   {
103 <        FVECT   vsrc, vjit;
103 >        int     nsamp = 1, ok = 0;
104 >        FVECT   vsrc, vsmp, vjit;
105 >        double  tomega;
106 >        double  sf, sd[2];
107 >        COLOR   csmp;
108          SDValue sv;
109          SDError ec;
110 +        int     i;
111                                          /* transform source direction */
112          if (SDmapDir(vsrc, ndp->toloc, ldir) != SDEnone)
113                  return(0);
114 <                                        /* jitter query direction */
115 <        bsdf_jitter(vjit, ndp, 0);
116 <                                        /* avoid indirect over-counting */
117 <        if (ndp->thru_r2 > FTINY && vsrc[2] > 0 ^ vjit[2] > 0) {
118 <                double  dx = vsrc[0] + vjit[0];
119 <                double  dy = vsrc[1] + vjit[1];
116 <                if (dx*dx + dy*dy <= ndp->thru_r2)
114 >                                        /* check indirect over-counting */
115 >        if (ndp->thick != 0 && ndp->pr->crtype & (SPECULAR|AMBIENT)
116 >                                && vsrc[2] > 0 ^ ndp->vray[2] > 0) {
117 >                double  dx = vsrc[0] + ndp->vray[0];
118 >                double  dy = vsrc[1] + ndp->vray[1];
119 >                if (dx*dx + dy*dy <= omega*(1./PI))
120                          return(0);
121          }
122 <        ec = SDevalBSDF(&sv, vjit, vsrc, ndp->sd);
123 <        if (ec)
124 <                objerror(ndp->mp, USER, transSDError(ec));
125 <
126 <        if (sv.cieY <= FTINY)           /* not worth using? */
127 <                return(0);
128 <                                        /* else we're good to go */
129 <        cvt_sdcolor(cval, &sv);
130 <        return(1);
122 >        if (specjitter > FTINY) {       /* assign number of samples */
123 >                ec = SDsizeBSDF(&tomega, ndp->vray, vsrc, SDqueryMin, ndp->sd);
124 >                if (ec)
125 >                        goto baderror;
126 >                sf = specjitter * ndp->pr->rweight;
127 >                if (tomega <= omega*.01)
128 >                        nsamp = 100.*sf + .5;
129 >                else
130 >                        nsamp = 4.*sf*omega/tomega + .5;
131 >                nsamp += !nsamp;
132 >        }
133 >        sf = sqrt(omega);
134 >        setcolor(cval, .0, .0, .0);     /* sample our source area */
135 >        for (i = nsamp; i--; ) {
136 >                VCOPY(vsmp, vsrc);      /* jitter query directions */
137 >                if (nsamp > 1) {
138 >                        multisamp(sd, 2, (i + frandom())/(double)nsamp);
139 >                        vsmp[0] += (sd[0] - .5)*sf;
140 >                        vsmp[1] += (sd[1] - .5)*sf;
141 >                        if (normalize(vsmp) == 0) {
142 >                                --nsamp;
143 >                                continue;
144 >                        }
145 >                }
146 >                bsdf_jitter(vjit, ndp, 0);
147 >                                        /* compute BSDF */
148 >                ec = SDevalBSDF(&sv, vjit, vsmp, ndp->sd);
149 >                if (ec)
150 >                        goto baderror;
151 >                if (sv.cieY <= FTINY)   /* worth using? */
152 >                        continue;
153 >                cvt_sdcolor(csmp, &sv);
154 >                addcolor(cval, csmp);   /* average it in */
155 >                ++ok;
156 >        }
157 >        sf = 1./(double)nsamp;
158 >        scalecolor(cval, sf);
159 >        return(ok);
160 > baderror:
161 >        objerror(ndp->mp, USER, transSDError(ec));
162   }
163  
164   /* Compute source contribution for BSDF (reflected & transmitted) */
# Line 168 | Line 202 | dir_bsdf(
202          /*
203           *  Compute scattering coefficient using BSDF.
204           */
205 <        if (!direct_bsdf_OK(ctmp, ldir, np))
205 >        if (!direct_bsdf_OK(ctmp, ldir, omega, np))
206                  return;
207          if (ldot > 0) {         /* pattern only diffuse reflection */
208                  COLOR   ctmp1, ctmp2;
# Line 223 | Line 257 | dir_brdf(
257          /*
258           *  Compute reflection coefficient using BSDF.
259           */
260 <        if (!direct_bsdf_OK(ctmp, ldir, np))
260 >        if (!direct_bsdf_OK(ctmp, ldir, omega, np))
261                  return;
262                                          /* pattern only diffuse reflection */
263          dtmp = (np->pr->rod > 0) ? np->sd->rLambFront.cieY
# Line 272 | Line 306 | dir_btdf(
306          /*
307           *  Compute scattering coefficient using BSDF.
308           */
309 <        if (!direct_bsdf_OK(ctmp, ldir, np))
309 >        if (!direct_bsdf_OK(ctmp, ldir, omega, np))
310                  return;
311                                          /* full pattern on transmission */
312          multcolor(ctmp, np->pr->pcol);
# Line 295 | Line 329 | sample_sdcomp(BSDFDAT *ndp, SDComponent *dcp, int usep
329                                                  /* multiple samples? */
330          if (specjitter > 1.5) {
331                  nstarget = specjitter*ndp->pr->rweight + .5;
332 <                if (nstarget < 1)
299 <                        nstarget = 1;
332 >                nstarget += !nstarget;
333          }
334                                                  /* run through our samples */
335          for (nsent = 0; nsent < nstarget; nsent++) {
# Line 484 | Line 517 | m_bsdf(OBJREC *m, RAY *r)
517          if (!ec)
518                  ec = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL,
519                                                  SDqueryMin+SDqueryMax, nd.sd);
487        nd.thru_r2 = .0;
488        if (!ec && nd.thick != 0 && r->crtype & (SPECULAR|AMBIENT)) {
489                FVECT   vthru;
490                vthru[0] = -nd.vray[0];
491                vthru[1] = -nd.vray[1];
492                vthru[2] = -nd.vray[2];
493                ec = SDsizeBSDF(&nd.thru_r2, nd.vray, vthru,
494                                                SDqueryMin, nd.sd);
495                nd.thru_r2 *= 1./PI;
496        }
520          if (ec) {
521                  objerror(m, WARNING, transSDError(ec));
522                  SDfreeCache(nd.sd);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines