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.18 by greg, Tue May 19 17:09:06 1992 UTC vs.
Revision 2.25 by greg, Thu May 27 15:27:57 1993 UTC

# Line 19 | Line 19 | static char SCCSid[] = "$SunId$ LBL";
19   extern double  specthresh;              /* specular sampling threshold */
20   extern double  specjitter;              /* specular sampling jitter */
21  
22 + static  agaussamp();
23 +
24   /*
25 < *      This anisotropic reflection model uses a variant on the
26 < *  exponential Gaussian used in normal.c.
25 > *      This routine implements the anisotropic Gaussian
26 > *  model described by Ward in Siggraph `92 article.
27   *      We orient the surface towards the incoming ray, so a single
28   *  surface can be used to represent an infinitely thin object.
29   *
# Line 34 | Line 36 | extern double  specjitter;             /* specular sampling jitte
36   *  8  red      grn     blu     rspec   u-rough v-rough trans   tspec
37   */
38  
37 #define  BSPEC(m)       (6.0)           /* specularity parameter b */
38
39                                  /* specularity flags */
40   #define  SP_REFL        01              /* has reflected specular component */
41   #define  SP_TRAN        02              /* has transmitted specular */
# Line 109 | Line 109 | double  omega;                 /* light source size */
109                  h[0] = ldir[0] - np->rp->rdir[0];
110                  h[1] = ldir[1] - np->rp->rdir[1];
111                  h[2] = ldir[2] - np->rp->rdir[2];
112                normalize(h);
112                                                  /* ellipse */
113                  dtmp1 = DOT(np->u, h);
114                  dtmp1 *= dtmp1 / au2;
115                  dtmp2 = DOT(np->v, h);
116                  dtmp2 *= dtmp2 / av2;
117                                                  /* gaussian */
118 <                dtmp = (dtmp1 + dtmp2) / (1.0 + DOT(np->pnorm, h));
119 <                dtmp = exp(-2.0*dtmp) * 1.0/(4.0*PI)
118 >                dtmp = DOT(np->pnorm, h);
119 >                dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp);
120 >                dtmp = exp(-dtmp) * (0.25/PI)
121                                  * sqrt(ldot/(np->pdot*au2*av2));
122                                                  /* worth using? */
123                  if (dtmp > FTINY) {
# Line 149 | Line 149 | double  omega;                 /* light source size */
149                  h[0] = ldir[0] - np->prdir[0];
150                  h[1] = ldir[1] - np->prdir[1];
151                  h[2] = ldir[2] - np->prdir[2];
152 <                dtmp = DOT(h,np->pnorm);
153 <                dtmp = DOT(h,h) - dtmp*dtmp;
152 >                dtmp = DOT(h,h);
153                  if (dtmp > FTINY*FTINY) {
154 <                        dtmp1 = DOT(h,np->u);
155 <                        dtmp1 = dtmp1*dtmp1 / (au2*dtmp);
156 <                        dtmp2 = DOT(h,np->v);
157 <                        dtmp2 = dtmp2*dtmp2 / (av2*dtmp);
158 <                        dtmp = 2. - 2.*DOT(ldir,np->prdir);
159 <                        dtmp *= dtmp1 + dtmp2;
154 >                        dtmp1 = DOT(h,np->pnorm);
155 >                        dtmp = 1.0 - dtmp1*dtmp1/dtmp;
156 >                        if (dtmp > FTINY*FTINY) {
157 >                                dtmp1 = DOT(h,np->u);
158 >                                dtmp1 *= dtmp1 / au2;
159 >                                dtmp2 = DOT(h,np->v);
160 >                                dtmp2 *= dtmp2 / av2;
161 >                                dtmp = (dtmp1 + dtmp2) / dtmp;
162 >                        }
163                  } else
164                          dtmp = 0.0;
165                                                  /* gaussian */
166 <                dtmp = exp(-dtmp) * 1.0/(4.0*PI)
166 >                dtmp = exp(-dtmp) * (1.0/PI)
167                                  * sqrt(-ldot/(np->pdot*au2*av2));
168                                                  /* worth using? */
169                  if (dtmp > FTINY) {
# Line 179 | Line 181 | register OBJREC  *m;
181   register RAY  *r;
182   {
183          ANISODAT  nd;
182        double  dtmp;
184          COLOR  ctmp;
185          register int  i;
186                                                  /* easy shadow test */
# Line 218 | Line 219 | register RAY  *r;
219                  else
220                          setcolor(nd.scolor, 1.0, 1.0, 1.0);
221                  scalecolor(nd.scolor, nd.rspec);
221                                                /* improved model */
222                dtmp = exp(-BSPEC(m)*nd.pdot);
223                for (i = 0; i < 3; i++)
224                        colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
225                nd.rspec += (1.0-nd.rspec)*dtmp;
222                                                  /* check threshold */
223 <                if (specthresh > FTINY &&
228 <                                (specthresh >= 1.-FTINY ||
229 <                                specthresh + .05 - .1*frandom() > nd.rspec))
223 >                if (specthresh >= nd.rspec-FTINY)
224                          nd.specfl |= SP_RBLT;
225                                                  /* compute refl. direction */
226                  for (i = 0; i < 3; i++)
# Line 243 | Line 237 | register RAY  *r;
237                  if (nd.tspec > FTINY) {
238                          nd.specfl |= SP_TRAN;
239                                                          /* check threshold */
240 <                        if (specthresh > FTINY &&
247 <                                        (specthresh >= 1.-FTINY ||
248 <                                specthresh + .05 - .1*frandom() > nd.tspec))
240 >                        if (specthresh >= nd.tspec-FTINY)
241                                  nd.specfl |= SP_TBLT;
242                          if (DOT(r->pert,r->pert) <= FTINY*FTINY) {
243                                  VCOPY(nd.prdir, r->rdir);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines