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.32 by greg, Wed Apr 24 15:47:25 1996 UTC vs.
Revision 2.41 by schorsch, Tue Mar 30 16:13:00 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Shading functions for anisotropic materials.
6   */
7  
8 < #include  "ray.h"
8 > #include "copyright.h"
9  
10 + #include  "ray.h"
11 + #include  "ambient.h"
12   #include  "otypes.h"
13 <
13 > #include  "rtotypes.h"
14 > #include  "source.h"
15   #include  "func.h"
16
16   #include  "random.h"
17  
19 extern double  specthresh;              /* specular sampling threshold */
20 extern double  specjitter;              /* specular sampling jitter */
21
22 extern int  backvis;                    /* back faces visible? */
23
18   #ifndef  MAXITER
19   #define  MAXITER        10              /* maximum # specular ray attempts */
20   #endif
21  
28 static  agaussamp(), getacoords();
29
22   /*
23   *      This routine implements the anisotropic Gaussian
24   *  model described by Ward in Siggraph `92 article.
# Line 68 | Line 60 | typedef struct {
60          double  pdot;           /* perturbed dot product */
61   }  ANISODAT;            /* anisotropic material data */
62  
63 + static srcdirf_t diraniso;
64 + static void getacoords(RAY  *r, ANISODAT  *np);
65 + static void agaussamp(RAY  *r, ANISODAT  *np);
66  
67 < diraniso(cval, np, ldir, omega)         /* compute source contribution */
68 < COLOR  cval;                    /* returned coefficient */
69 < register ANISODAT  *np;         /* material data */
70 < FVECT  ldir;                    /* light source direction */
71 < double  omega;                  /* light source size */
67 >
68 > static void
69 > diraniso(               /* compute source contribution */
70 >        COLOR  cval,                    /* returned coefficient */
71 >        void  *nnp,             /* material data */
72 >        FVECT  ldir,                    /* light source direction */
73 >        double  omega                   /* light source size */
74 > )
75   {
76 +        register ANISODAT *np = nnp;
77          double  ldot;
78          double  dtmp, dtmp1, dtmp2;
79          FVECT  h;
# Line 182 | Line 181 | double  omega;                 /* light source size */
181   }
182  
183  
184 < m_aniso(m, r)                   /* shade ray that hit something anisotropic */
185 < register OBJREC  *m;
186 < register RAY  *r;
184 > extern int
185 > m_aniso(                        /* shade ray that hit something anisotropic */
186 >        register OBJREC  *m,
187 >        register RAY  *r
188 > )
189   {
190          ANISODAT  nd;
191          COLOR  ctmp;
# Line 195 | Line 196 | register RAY  *r;
196  
197          if (m->oargs.nfargs != (m->otype == MAT_TRANS2 ? 8 : 6))
198                  objerror(m, USER, "bad number of real arguments");
199 +                                                /* check for back side */
200 +        if (r->rod < 0.0) {
201 +                if (!backvis && m->otype != MAT_TRANS2) {
202 +                        raytrans(r);
203 +                        return(1);
204 +                }
205 +                raytexture(r, m->omod);
206 +                flipsurface(r);                 /* reorient if backvis */
207 +        } else
208 +                raytexture(r, m->omod);
209 +                                                /* get material color */
210          nd.mp = m;
211          nd.rp = r;
200                                                /* get material color */
212          setcolor(nd.mcolor, m->oargs.farg[0],
213                             m->oargs.farg[1],
214                             m->oargs.farg[2]);
# Line 207 | Line 218 | register RAY  *r;
218          nd.v_alpha = m->oargs.farg[5];
219          if (nd.u_alpha < FTINY || nd.v_alpha <= FTINY)
220                  objerror(m, USER, "roughness too small");
221 <                                                /* check for back side */
211 <        if (r->rod < 0.0) {
212 <                if (!backvis && m->otype != MAT_TRANS2) {
213 <                        raytrans(r);
214 <                        return(1);
215 <                }
216 <                flipsurface(r);                 /* reorient if backvis */
217 <        }
218 <                                                /* get modifiers */
219 <        raytexture(r, m->omod);
221 >
222          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
223          if (nd.pdot < .001)
224                  nd.pdot = .001;                 /* non-zero for diraniso() */
# Line 307 | Line 309 | register RAY  *r;
309   }
310  
311  
312 < static
313 < getacoords(r, np)               /* set up coordinate system */
314 < RAY  *r;
315 < register ANISODAT  *np;
312 > static void
313 > getacoords(             /* set up coordinate system */
314 >        RAY  *r,
315 >        register ANISODAT  *np
316 > )
317   {
318          register MFUNC  *mf;
319          register int  i;
# Line 320 | Line 323 | register ANISODAT  *np;
323          errno = 0;
324          for (i = 0; i < 3; i++)
325                  np->u[i] = evalue(mf->ep[i]);
326 <        if (errno) {
326 >        if (errno == EDOM || errno == ERANGE) {
327                  objerror(np->mp, WARNING, "compute error");
328                  np->specfl |= SP_BADU;
329                  return;
# Line 337 | Line 340 | register ANISODAT  *np;
340   }
341  
342  
343 < static
344 < agaussamp(r, np)                /* sample anisotropic gaussian specular */
345 < RAY  *r;
346 < register ANISODAT  *np;
343 > static void
344 > agaussamp(              /* sample anisotropic gaussian specular */
345 >        RAY  *r,
346 >        register ANISODAT  *np
347 > )
348   {
349          RAY  sr;
350          FVECT  h;
# Line 359 | Line 363 | register ANISODAT  *np;
363                                  d = urand(ilhash(dimlist,ndims)+samplendx);
364                          multisamp(rv, 2, d);
365                          d = 2.0*PI * rv[0];
366 <                        cosp = cos(d) * np->u_alpha;
367 <                        sinp = sin(d) * np->v_alpha;
366 >                        cosp = tcos(d) * np->u_alpha;
367 >                        sinp = tsin(d) * np->v_alpha;
368                          d = sqrt(cosp*cosp + sinp*sinp);
369                          cosp /= d;
370                          sinp /= d;
# Line 397 | Line 401 | register ANISODAT  *np;
401                                  d = urand(ilhash(dimlist,ndims)+1823+samplendx);
402                          multisamp(rv, 2, d);
403                          d = 2.0*PI * rv[0];
404 <                        cosp = cos(d) * np->u_alpha;
405 <                        sinp = sin(d) * np->v_alpha;
404 >                        cosp = tcos(d) * np->u_alpha;
405 >                        sinp = tsin(d) * np->v_alpha;
406                          d = sqrt(cosp*cosp + sinp*sinp);
407                          cosp /= d;
408                          sinp /= d;
# Line 408 | Line 412 | register ANISODAT  *np;
412                          else
413                                  d = sqrt(-log(rv[1]) /
414                                          (cosp*cosp/(np->u_alpha*np->u_alpha) +
415 <                                         sinp*sinp/(np->v_alpha*np->u_alpha)));
415 >                                         sinp*sinp/(np->v_alpha*np->v_alpha)));
416                          for (i = 0; i < 3; i++)
417                                  sr.rdir[i] = np->prdir[i] +
418                                                  d*(cosp*np->u[i] + sinp*np->v[i]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines