ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/ashikhmin.c
(Generate patch)

Comparing ray/src/rt/ashikhmin.c (file contents):
Revision 2.1 by greg, Sun Jul 29 19:01:39 2012 UTC vs.
Revision 2.6 by greg, Wed Sep 2 18:59:01 2015 UTC

# Line 14 | Line 14 | static const char RCSid[] = "$Id$";
14   #include  "source.h"
15   #include  "func.h"
16   #include  "random.h"
17 + #include  "pmapmat.h"
18  
19   #ifndef  MAXITER
20   #define  MAXITER        10              /* maximum # specular ray attempts */
# Line 32 | Line 33 | static const char RCSid[] = "$Id$";
33   #define  SPA_REFL       01              /* has reflected specular component */
34   #define  SPA_FLAT       02              /* reflecting surface is flat */
35   #define  SPA_RBLT       010             /* reflection below sample threshold */
35 #define  SPA_BADU       020             /* bad u direction calculation */
36  
37   typedef struct {
38          OBJREC  *mp;            /* material pointer */
# Line 47 | Line 47 | typedef struct {
47          double  pdot;           /* perturbed dot product */
48   }  ASHIKDAT;            /* anisotropic material data */
49  
50 < static void getacoords_as(RAY *r, ASHIKDAT *np);
51 < static void ashiksamp(RAY *r, ASHIKDAT *np);
50 > static void getacoords_as(ASHIKDAT *np);
51 > static void ashiksamp(ASHIKDAT *np);
52  
53 + #undef MAX
54 + #define MAX(a,b)        ((a)>(b) ? (a) : (b))
55  
54 static double
55 max(double a, double b) {
56        if (a > b)
57                return(a);
58        return(b);
59 }
56  
61
57   static double
58   schlick_fres(double dprod)
59   {
# Line 98 | Line 93 | dirashik(              /* compute source contribution */
93          scalecolor(ctmp, dtmp);        
94          addcolor(cval, ctmp);
95  
96 <        if ((np->specfl & (SPA_REFL|SPA_BADU)) != SPA_REFL)
96 >        if (!(np->specfl & SPA_REFL) || ambRayInPmap(np->rp))
97                  return;
98          /*
99           *  Compute specular reflection coefficient
# Line 115 | Line 110 | dirashik(              /* compute source contribution */
110          dtmp = DOT(np->pnorm, h);
111          dtmp = pow(dtmp, (dtmp1+dtmp2)/(1.-dtmp*dtmp));
112          dtmp *= sqrt((np->u_power+1.)*(np->v_power+1.));
113 <        dtmp /= 8.*PI * DOT(ldir,h) * max(ldot,np->pdot);
113 >        dtmp /= 8.*PI * DOT(ldir,h) * MAX(ldot,np->pdot);
114                                          /* worth using? */
115          if (dtmp > FTINY) {
116                  copycolor(ctmp, np->scolor);
# Line 183 | Line 178 | m_ashikhmin(                   /* shade ray that hit something anisotr
178          if (r->ro != NULL && isflat(r->ro->otype))
179                  nd.specfl |= SPA_FLAT;
180                                                  /* set up coordinates */
181 <        getacoords_as(r, &nd);
181 >        getacoords_as(&nd);
182                                                  /* specular sampling? */
183          if ((nd.specfl & (SPA_REFL|SPA_RBLT)) == SPA_REFL)
184 <                ashiksamp(r, &nd);
184 >                ashiksamp(&nd);
185                                                  /* diffuse interreflection */
186          if (bright(nd.mcolor) > FTINY) {
187                  copycolor(ctmp, nd.mcolor);     /* modified by material color */                
# Line 203 | Line 198 | m_ashikhmin(                   /* shade ray that hit something anisotr
198  
199   static void
200   getacoords_as(          /* set up coordinate system */
206        RAY  *r,
201          ASHIKDAT  *np
202   )
203   {
# Line 211 | Line 205 | getacoords_as(         /* set up coordinate system */
205          int  i;
206  
207          mf = getfunc(np->mp, 3, 0x7, 1);
208 <        setfunc(np->mp, r);
208 >        setfunc(np->mp, np->rp);
209          errno = 0;
210          for (i = 0; i < 3; i++)
211                  np->u[i] = evalue(mf->ep[i]);
212 <        if ((errno == EDOM) | (errno == ERANGE)) {
213 <                objerror(np->mp, WARNING, "compute error");
220 <                np->specfl |= SPA_BADU;
221 <                return;
222 <        }
212 >        if ((errno == EDOM) | (errno == ERANGE))
213 >                np->u[0] = np->u[1] = np->u[2] = 0.0;
214          if (mf->fxp != &unitxf)
215                  multv3(np->u, np->u, mf->fxp->xfm);
216          fcross(np->v, np->pnorm, np->u);
217          if (normalize(np->v) == 0.0) {
218 <                objerror(np->mp, WARNING, "illegal orientation vector");
219 <                np->specfl |= SPA_BADU;
220 <                return;
221 <        }
222 <        fcross(np->u, np->v, np->pnorm);
218 >                if (fabs(np->u_power - np->v_power) > 0.1)
219 >                        objerror(np->mp, WARNING, "bad orientation vector");
220 >                getperpendicular(np->u, np->pnorm, 1);  /* punting */
221 >                fcross(np->v, np->pnorm, np->u);
222 >                np->u_power = np->v_power =
223 >                        2./(1./(np->u_power+1e-5) + 1./(np->v_power+1e-5));
224 >        } else
225 >                fcross(np->u, np->v, np->pnorm);
226   }
227  
228  
229   static void
230   ashiksamp(              /* sample anisotropic Ashikhmin-Shirley specular */
237        RAY  *r,
231          ASHIKDAT  *np
232   )
233   {
# Line 242 | Line 235 | ashiksamp(             /* sample anisotropic Ashikhmin-Shirley sp
235          FVECT  h;
236          double  rv[2], dtmp;
237          double  cosph, sinph, costh, sinth;
245        COLOR   scol;
238          int  maxiter, ntrials, nstarget, nstaken;
239          int  i;
240  
241 <        if (np->specfl & SPA_BADU ||
250 <                        rayorigin(&sr, SPECULAR, r, np->scolor) < 0)
241 >        if (rayorigin(&sr, SPECULAR, np->rp, np->scolor) < 0)
242                  return;
243  
244          nstarget = 1;
245          if (specjitter > 1.5) {                 /* multiple samples? */
246 <                nstarget = specjitter*r->rweight + .5;
246 >                nstarget = specjitter*np->rp->rweight + .5;
247                  if (sr.rweight <= minweight*nstarget)
248                          nstarget = sr.rweight/minweight;
249                  if (nstarget > 1) {
# Line 269 | Line 260 | ashiksamp(             /* sample anisotropic Ashikhmin-Shirley sp
260                  if (ntrials)
261                          dtmp = frandom();
262                  else
263 <                        dtmp = urand(ilhash(dimlist,ndims)+1823+samplendx);
263 >                        dtmp = urand(ilhash(dimlist,ndims)+647+samplendx);
264                  multisamp(rv, 2, dtmp);
265                  dtmp = 2.*PI * rv[0];
266 <                cosph = sqrt(np->u_power + 1.) * tcos(dtmp);
267 <                sinph = sqrt(np->v_power + 1.) * tsin(dtmp);
268 <                dtmp = 1./(cosph*cosph + sinph*sinph);
266 >                cosph = sqrt(np->v_power + 1.) * tcos(dtmp);
267 >                sinph = sqrt(np->u_power + 1.) * tsin(dtmp);
268 >                dtmp = 1./sqrt(cosph*cosph + sinph*sinph);
269                  cosph *= dtmp;
270                  sinph *= dtmp;
271                  costh = pow(rv[1], 1./(np->u_power*cosph*cosph+np->v_power*sinph*sinph+1.));
# Line 286 | Line 277 | ashiksamp(             /* sample anisotropic Ashikhmin-Shirley sp
277  
278                  if (nstaken)
279                          rayclear(&sr);
280 <                dtmp = -2.*DOT(h, r->rdir);
281 <                VSUM(sr.rdir, r->rdir, h, dtmp);                                
280 >                dtmp = -2.*DOT(h, np->rp->rdir);
281 >                VSUM(sr.rdir, np->rp->rdir, h, dtmp);                          
282                                                  /* sample rejection test */
283 <                if (DOT(sr.rdir, r->ron) <= FTINY)
283 >                if (DOT(sr.rdir, np->rp->ron) <= FTINY)
284                          continue;
285 +                checknorm(sr.rdir);
286                  rayvalue(&sr);
287                  multcolor(sr.rcol, sr.rcoef);
288 <                addcolor(r->rcol, sr.rcol);
288 >                addcolor(np->rp->rcol, sr.rcol);
289                  ++nstaken;
290          }
291          ndims--;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines