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.19 by greg, Wed May 20 11:01:40 1992 UTC vs.
Revision 2.28 by greg, Wed Dec 21 09:51:44 1994 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 + extern int  backvis;                    /* back faces visible? */
23 +
24 + static  agaussamp(), getacoords();
25 +
26   /*
27 < *      This anisotropic reflection model uses a variant on the
28 < *  exponential Gaussian used in normal.c.
27 > *      This routine implements the anisotropic Gaussian
28 > *  model described by Ward in Siggraph `92 article.
29   *      We orient the surface towards the incoming ray, so a single
30   *  surface can be used to represent an infinitely thin object.
31   *
# Line 34 | Line 38 | extern double  specjitter;             /* specular sampling jitte
38   *  8  red      grn     blu     rspec   u-rough v-rough trans   tspec
39   */
40  
37 #define  BSPEC(m)       (6.0)           /* specularity parameter b */
38
41                                  /* specularity flags */
42   #define  SP_REFL        01              /* has reflected specular component */
43   #define  SP_TRAN        02              /* has transmitted specular */
# Line 109 | Line 111 | double  omega;                 /* light source size */
111                  h[0] = ldir[0] - np->rp->rdir[0];
112                  h[1] = ldir[1] - np->rp->rdir[1];
113                  h[2] = ldir[2] - np->rp->rdir[2];
112                normalize(h);
114                                                  /* ellipse */
115                  dtmp1 = DOT(np->u, h);
116                  dtmp1 *= dtmp1 / au2;
117                  dtmp2 = DOT(np->v, h);
118                  dtmp2 *= dtmp2 / av2;
119                                                  /* gaussian */
120 <                dtmp = (dtmp1 + dtmp2) / (1.0 + DOT(np->pnorm, h));
121 <                dtmp = exp(-2.0*dtmp) * 1.0/(4.0*PI)
120 >                dtmp = DOT(np->pnorm, h);
121 >                dtmp = (dtmp1 + dtmp2) / (dtmp*dtmp);
122 >                dtmp = exp(-dtmp) * (0.25/PI)
123                                  * sqrt(ldot/(np->pdot*au2*av2));
124                                                  /* worth using? */
125                  if (dtmp > FTINY) {
# Line 155 | Line 157 | double  omega;                 /* light source size */
157                          dtmp = 1.0 - dtmp1*dtmp1/dtmp;
158                          if (dtmp > FTINY*FTINY) {
159                                  dtmp1 = DOT(h,np->u);
160 <                                dtmp1 = dtmp1*dtmp1 / au2;
160 >                                dtmp1 *= dtmp1 / au2;
161                                  dtmp2 = DOT(h,np->v);
162 <                                dtmp2 = dtmp2*dtmp2 / av2;
162 >                                dtmp2 *= dtmp2 / av2;
163                                  dtmp = (dtmp1 + dtmp2) / dtmp;
164                          }
165                  } else
166                          dtmp = 0.0;
167                                                  /* gaussian */
168 <                dtmp = exp(-dtmp) * 1.0/(4.0*PI)
168 >                dtmp = exp(-dtmp) * (1.0/PI)
169                                  * sqrt(-ldot/(np->pdot*au2*av2));
170                                                  /* worth using? */
171                  if (dtmp > FTINY) {
# Line 181 | Line 183 | register OBJREC  *m;
183   register RAY  *r;
184   {
185          ANISODAT  nd;
184        double  dtmp;
186          COLOR  ctmp;
187          register int  i;
188                                                  /* easy shadow test */
189          if (r->crtype & SHADOW)
190 <                return;
190 >                return(1);
191  
192          if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6))
193                  objerror(m, USER, "bad number of real arguments");
# Line 202 | Line 203 | register RAY  *r;
203          nd.v_alpha = m->oargs.farg[5];
204          if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY)
205                  objerror(m, USER, "roughness too small");
206 <                                                /* reorient if necessary */
207 <        if (r->rod < 0.0)
208 <                flipsurface(r);
206 >                                                /* check for back side */
207 >        if (r->rod < 0.0) {
208 >                if (!backvis && m->otype != MAT_TRANS2) {
209 >                        raytrans(r);
210 >                        return(1);
211 >                }
212 >                flipsurface(r);                 /* reorient if backvis */
213 >        }
214                                                  /* get modifiers */
215          raytexture(r, m->omod);
216          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
# Line 220 | Line 226 | register RAY  *r;
226                  else
227                          setcolor(nd.scolor, 1.0, 1.0, 1.0);
228                  scalecolor(nd.scolor, nd.rspec);
223                                                /* improved model */
224                dtmp = exp(-BSPEC(m)*nd.pdot);
225                for (i = 0; i < 3; i++)
226                        colval(nd.scolor,i) += (1.0-colval(nd.scolor,i))*dtmp;
227                nd.rspec += (1.0-nd.rspec)*dtmp;
229                                                  /* check threshold */
230 <                if (specthresh > FTINY &&
230 <                                (specthresh >= 1.-FTINY ||
231 <                                specthresh + .05 - .1*frandom() > nd.rspec))
230 >                if (specthresh >= nd.rspec-FTINY)
231                          nd.specfl |= SP_RBLT;
232                                                  /* compute refl. direction */
233                  for (i = 0; i < 3; i++)
# Line 245 | Line 244 | register RAY  *r;
244                  if (nd.tspec > FTINY) {
245                          nd.specfl |= SP_TRAN;
246                                                          /* check threshold */
247 <                        if (specthresh > FTINY &&
249 <                                        (specthresh >= 1.-FTINY ||
250 <                                specthresh + .05 - .1*frandom() > nd.tspec))
247 >                        if (specthresh >= nd.tspec-FTINY)
248                                  nd.specfl |= SP_TBLT;
249                          if (DOT(r->pert,r->pert) <= FTINY*FTINY) {
250                                  VCOPY(nd.prdir, r->rdir);
# Line 297 | Line 294 | register RAY  *r;
294          }
295                                          /* add direct component */
296          direct(r, diraniso, &nd);
297 +
298 +        return(1);
299   }
300  
301  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines