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

Comparing ray/src/rt/m_brdf.c (file contents):
Revision 2.25 by greg, Fri Sep 7 15:25:01 2007 UTC vs.
Revision 2.33 by greg, Wed Sep 2 18:59:01 2015 UTC

# Line 14 | Line 14 | static const char      RCSid[] = "$Id$";
14   #include  "otypes.h"
15   #include  "rtotypes.h"
16   #include  "func.h"
17 + #include  "pmapmat.h"
18  
19   /*
20   *      Arguments to this material include the color and specularity.
# Line 38 | Line 39 | static const char      RCSid[] = "$Id$";
39   *  Arguments for MAT_TFUNC are:
40   *      2+      func    funcfile        transform
41   *      0
42 < *      4+      red     grn     blu     rspec   trans   tspec   A7 ..
42 > *      6+      red     grn     blu     rspec   trans   tspec   A7 ..
43   *
44   *  Arguments for MAT_TDATA are:
45   *      4+      func    datafile        funcfile        v0 ..   transform
46   *      0
47 < *      4+      red     grn     blu     rspec   trans   tspec   A7 ..
47 > *      6+      red     grn     blu     rspec   trans   tspec   A7 ..
48   *
49   *  Arguments for the more general MAT_BRTDF are:
50   *      10+     rrefl   grefl   brefl
# Line 77 | Line 78 | typedef struct {
78   }  BRDFDAT;             /* BRDF material data */
79  
80  
81 < static srcdirf_t dirbrdf;
81 < static int setbrdfunc(BRDFDAT  *np);
81 > static int setbrdfunc(BRDFDAT *np);
82  
83  
84   static void
# Line 89 | Line 89 | dirbrdf(               /* compute source contribution */
89          double  omega                   /* light source size */
90   )
91   {
92 <        register BRDFDAT *np = nnp;
92 >        BRDFDAT *np = nnp;
93          double  ldot;
94          double  dtmp;
95          COLOR  ctmp;
96          FVECT  ldx;
97          static double  vldx[5], pt[MAXDIM];
98 <        register char   **sa;
99 <        register int    i;
98 >        char    **sa;
99 >        int     i;
100   #define lddx (vldx+1)
101  
102          setcolor(cval, 0.0, 0.0, 0.0);
# Line 128 | Line 128 | dirbrdf(               /* compute source contribution */
128                  scalecolor(ctmp, dtmp);
129                  addcolor(cval, ctmp);
130          }
131 <        if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
131 >        if ((ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) ||
132 >                        ambRayInPmap(np->pr))
133                  return;         /* diffuse only */
134                                          /* set up function */
135          setbrdfunc(np);
# Line 141 | Line 142 | dirbrdf(               /* compute source contribution */
142          lddx[3] = omega;
143                                          /* compute BRTDF */
144          if (np->mp->otype == MAT_BRTDF) {
145 <                if (sa[6][0] == '0')            /* special case */
145 >                if (sa[6][0] == '0' && !sa[6][1])       /* special case */
146                          colval(ctmp,RED) = 0.0;
147                  else
148                          colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
149 <                if (sa[7][0] == '0')
149 >                if (sa[7][0] == '0' && !sa[7][1])
150                          colval(ctmp,GRN) = 0.0;
151                  else if (!strcmp(sa[7],sa[6]))
152                          colval(ctmp,GRN) = colval(ctmp,RED);
153                  else
154                          colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
155 <                if (!strcmp(sa[8],sa[6]))
155 >                if (sa[8][0] == '0' && !sa[8][1])
156 >                        colval(ctmp,BLU) = 0.0;
157 >                else if (!strcmp(sa[8],sa[6]))
158                          colval(ctmp,BLU) = colval(ctmp,RED);
159                  else if (!strcmp(sa[8],sa[7]))
160                          colval(ctmp,BLU) = colval(ctmp,GRN);
# Line 197 | Line 200 | dirbrdf(               /* compute source contribution */
200   }
201  
202  
203 < extern int
203 > int
204   m_brdf(                 /* color a ray that hit a BRDTfunc material */
205 <        register OBJREC  *m,
206 <        register RAY  *r
205 >        OBJREC  *m,
206 >        RAY  *r
207   )
208   {
209          int  hitfront = 1;
210          BRDFDAT  nd;
211          RAY  sr;
212          double  mirtest=0, mirdist=0;
213 <        double  transtest, transdist;
213 >        double  transtest=0, transdist=0;
214          int  hasrefl, hastrans;
215          int  hastexture;
216          COLOR  ctmp;
217          FVECT  vtmp;
218          double  d;
219 <        register MFUNC  *mf;
220 <        register int  i;
219 >        MFUNC  *mf;
220 >        int  i;
221                                                  /* check arguments */
222          if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
223                  objerror(m, USER, "bad # arguments");
# Line 271 | Line 274 | m_brdf(                        /* color a ray that hit a BRDTfunc material
274                  objerror(m, WARNING, "compute error");
275          else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
276                  if (!(r->crtype & SHADOW) && hastexture) {
277 <                        for (i = 0; i < 3; i++) /* perturb direction */
278 <                                sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
277 >                                                /* perturb direction */
278 >                        VSUM(sr.rdir, r->rdir, r->pert, -.75);
279                          if (normalize(sr.rdir) == 0.0) {
280                                  objerror(m, WARNING, "illegal perturbation");
281                                  VCOPY(sr.rdir, r->rdir);
# Line 299 | Line 302 | m_brdf(                        /* color a ray that hit a BRDTfunc material
302          if ((errno == EDOM) | (errno == ERANGE))
303                  objerror(m, WARNING, "compute error");
304          else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
305 <                for (i = 0; i < 3; i++)
306 <                        sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
305 >                VSUM(sr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot);
306 >                checknorm(sr.rdir);
307                  rayvalue(&sr);
308                  multcolor(sr.rcol, sr.rcoef);
309                  addcolor(r->rcol, sr.rcol);
# Line 345 | Line 348 | m_brdf(                        /* color a ray that hit a BRDTfunc material
348  
349  
350  
351 < extern int
351 > int
352   m_brdf2(                        /* color a ray that hit a BRDF material */
353 <        register OBJREC  *m,
354 <        register RAY  *r
353 >        OBJREC  *m,
354 >        RAY  *r
355   )
356   {
357          BRDFDAT  nd;
# Line 364 | Line 367 | m_brdf2(                       /* color a ray that hit a BRDF material */
367                  objerror(m, USER, "bad # arguments");
368                                                  /* check for back side */
369          if (r->rod < 0.0) {
370 <                if (!backvis && m->otype != MAT_TFUNC
368 <                                && m->otype != MAT_TDATA) {
370 >                if (!backvis) {
371                          raytrans(r);
372                          return(1);
373                  }
# Line 434 | Line 436 | m_brdf2(                       /* color a ray that hit a BRDF material */
436  
437   static int
438   setbrdfunc(                     /* set up brdf function and variables */
439 <        register BRDFDAT  *np
439 >        BRDFDAT  *np
440   )
441   {
442          FVECT  vec;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines