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

Comparing ray/src/rt/aniso.c (file contents):
Revision 2.1 by greg, Sat Jan 4 19:52:49 1992 UTC vs.
Revision 2.5 by greg, Wed Jan 15 11:02:43 1992 UTC

# Line 16 | Line 16 | static char SCCSid[] = "$SunId$ LBL";
16  
17   #include  "random.h"
18  
19 + extern double  specthresh;              /* specular sampling threshold */
20 + extern double  specjitter;              /* specular sampling jitter */
21 +
22   /*
23   *      This anisotropic reflection model uses a variant on the
24   *  exponential Gaussian used in normal.c.
# Line 37 | Line 40 | static char SCCSid[] = "$SunId$ LBL";
40   #define  SP_REFL        01              /* has reflected specular component */
41   #define  SP_TRAN        02              /* has transmitted specular */
42   #define  SP_PURE        010             /* purely specular (zero roughness) */
43 < #define  SP_BADU        020             /* bad u direction calculation */
43 > #define  SP_FLAT        020             /* reflecting surface is flat */
44 > #define  SP_RBLT        040             /* reflection below sample threshold */
45 > #define  SP_TBLT        0100            /* transmission below threshold */
46 > #define  SP_BADU        0200            /* bad u direction calculation */
47  
48   typedef struct {
43        RAY  *rp;               /* ray pointer */
49          OBJREC  *mp;            /* material pointer */
50 +        RAY  *rp;               /* ray pointer */
51          short  specfl;          /* specularity flags, defined above */
52          COLOR  mcolor;          /* color of this material */
53          COLOR  scolor;          /* color of specular component */
# Line 92 | Line 98 | double  omega;                 /* light source size */
98                   *  Compute specular reflection coefficient using
99                   *  anisotropic gaussian distribution model.
100                   */
101 <                                                /* roughness + source */
102 <                au2 = av2 = omega/(4.0*PI);
101 >                                                /* add source width if flat */
102 >                if (np->specfl & SP_FLAT)
103 >                        au2 = av2 = omega/(4.0*PI);
104 >                else
105 >                        au2 = av2 = 0.0;
106                  au2 += np->u_alpha * np->u_alpha;
107                  av2 += np->v_alpha * np->v_alpha;
108                                                  /* half vector */
# Line 160 | Line 169 | register RAY  *r;
169  
170          if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6))
171                  objerror(m, USER, "bad number of real arguments");
163        nd.rp = r;
172          nd.mp = m;
173 +        nd.rp = r;
174                                                  /* get material color */
175          setcolor(nd.mcolor, m->oargs.farg[0],
176                             m->oargs.farg[1],
# Line 196 | Line 205 | register RAY  *r;
205                  for (i = 0; i < 3; i++)
206                          colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
207                  nd.rspec += (1.0-nd.rspec)*dtmp;
208 +                                                /* check threshold */
209 +                if (specthresh > FTINY &&
210 +                                ((specthresh >= 1.-FTINY ||
211 +                                specthresh + (.1 - .2*urand(8199+samplendx))
212 +                                        > nd.rspec)))
213 +                        nd.specfl |= SP_RBLT;
214  
215                  if (!(r->crtype & SHADOW) && nd.specfl & SP_PURE) {
216                          RAY  lr;
# Line 216 | Line 231 | register RAY  *r;
231                  nd.tdiff = nd.trans - nd.tspec;
232                  if (nd.tspec > FTINY) {
233                          nd.specfl |= SP_TRAN;
234 +                                                        /* check threshold */
235 +                        if (specthresh > FTINY &&
236 +                                        ((specthresh >= 1.-FTINY ||
237 +                                        specthresh +
238 +                                            (.1 - .2*urand(7241+samplendx))
239 +                                                > nd.tspec)))
240 +                                nd.specfl |= SP_TBLT;
241                          if (r->crtype & SHADOW ||
242                                          DOT(r->pert,r->pert) <= FTINY*FTINY) {
243                                  VCOPY(nd.prdir, r->rdir);
# Line 251 | Line 273 | register RAY  *r;
273          if (nd.specfl & SP_PURE && nd.rdiff <= FTINY && nd.tdiff <= FTINY)
274                  return;                         /* 100% pure specular */
275  
276 +        if (r->ro->otype == OBJ_FACE || r->ro->otype == OBJ_RING)
277 +                nd.specfl |= SP_FLAT;
278 +
279          getacoords(r, &nd);                     /* set up coordinates */
280  
281          if (nd.specfl & (SP_REFL|SP_TRAN) && !(nd.specfl & (SP_PURE|SP_BADU)))
# Line 258 | Line 283 | register RAY  *r;
283  
284          if (nd.rdiff > FTINY) {         /* ambient from this side */
285                  ambient(ctmp, r);
286 <                scalecolor(ctmp, nd.rdiff);
286 >                if (nd.specfl & SP_RBLT)
287 >                        scalecolor(ctmp, 1.0-nd.trans);
288 >                else
289 >                        scalecolor(ctmp, nd.rdiff);
290                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
291                  addcolor(r->rcol, ctmp);        /* add to returned color */
292          }
293          if (nd.tdiff > FTINY) {         /* ambient from other side */
294                  flipsurface(r);
295                  ambient(ctmp, r);
296 <                scalecolor(ctmp, nd.tdiff);
296 >                if (nd.specfl & SP_TBLT)
297 >                        scalecolor(ctmp, nd.trans);
298 >                else
299 >                        scalecolor(ctmp, nd.tdiff);
300                  multcolor(ctmp, nd.mcolor);     /* modified by color */
301                  addcolor(r->rcol, ctmp);
302                  flipsurface(r);
# Line 316 | Line 347 | register ANISODAT  *np;
347          FVECT  h;
348          double  rv[2];
349          double  d, sinp, cosp;
350 <        int  confuse;
350 >        int  ntries;
351          register int  i;
352                                          /* compute reflection */
353 <        if (np->specfl & SP_REFL &&
353 >        if ((np->specfl & (SP_REFL|SP_RBLT)) == SP_REFL &&
354                          rayorigin(&sr, r, SPECULAR, np->rspec) == 0) {
324                confuse = 0;
355                  dimlist[ndims++] = (int)np->mp;
356 <        refagain:
357 <                dimlist[ndims] = confuse += 3601;
358 <                d = urand(ilhash(dimlist,ndims+1)+samplendx);
359 <                multisamp(rv, 2, d);
360 <                d = 2.0*PI * rv[0];
361 <                cosp = np->u_alpha * cos(d);
362 <                sinp = np->v_alpha * sin(d);
363 <                d = sqrt(cosp*cosp + sinp*sinp);
364 <                cosp /= d;
365 <                sinp /= d;
366 <                if (rv[1] <= FTINY)
367 <                        d = 1.0;
368 <                else
369 <                        d = sqrt( -log(rv[1]) /
370 <                                (cosp*cosp/(np->u_alpha*np->u_alpha) +
371 <                                 sinp*sinp/(np->v_alpha*np->v_alpha)) );
372 <                for (i = 0; i < 3; i++)
373 <                        h[i] = np->pnorm[i] +
356 >                for (ntries = 0; ntries < 10; ntries++) {
357 >                        dimlist[ndims] = ntries * 3601;
358 >                        d = urand(ilhash(dimlist,ndims+1)+samplendx);
359 >                        multisamp(rv, 2, d);
360 >                        d = 2.0*PI * rv[0];
361 >                        cosp = np->u_alpha * cos(d);
362 >                        sinp = np->v_alpha * sin(d);
363 >                        d = sqrt(cosp*cosp + sinp*sinp);
364 >                        cosp /= d;
365 >                        sinp /= d;
366 >                        rv[1] = 1.0 - specjitter*rv[1];
367 >                        if (rv[1] <= FTINY)
368 >                                d = 1.0;
369 >                        else
370 >                                d = sqrt(-log(rv[1]) /
371 >                                        (cosp*cosp/(np->u_alpha*np->u_alpha) +
372 >                                         sinp*sinp/(np->v_alpha*np->v_alpha)));
373 >                        for (i = 0; i < 3; i++)
374 >                                h[i] = np->pnorm[i] +
375                                          d*(cosp*np->u[i] + sinp*np->v[i]);
376 <                d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
377 <                for (i = 0; i < 3; i++)
378 <                        sr.rdir[i] = r->rdir[i] + d*h[i];
379 <                if (DOT(sr.rdir, r->ron) <= FTINY)      /* oops! */
380 <                        goto refagain;
381 <                rayvalue(&sr);
382 <                multcolor(sr.rcol, np->scolor);
383 <                addcolor(r->rcol, sr.rcol);
376 >                        d = -2.0 * DOT(h, r->rdir) / (1.0 + d*d);
377 >                        for (i = 0; i < 3; i++)
378 >                                sr.rdir[i] = r->rdir[i] + d*h[i];
379 >                        if (DOT(sr.rdir, r->ron) > FTINY) {
380 >                                rayvalue(&sr);
381 >                                multcolor(sr.rcol, np->scolor);
382 >                                addcolor(r->rcol, sr.rcol);
383 >                                break;
384 >                        }
385 >                }
386                  ndims--;
387          }
388                                          /* compute transmission */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines