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 1.11 by greg, Tue Jun 18 08:59:55 1991 UTC vs.
Revision 2.32 by greg, Thu Aug 6 16:06:06 2015 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 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 for materials with arbitrary BRDF's
6   */
7  
8 < #include  "ray.h"
8 > #include "copyright.h"
9  
10 + #include  "ray.h"
11 + #include  "ambient.h"
12   #include  "data.h"
13 <
13 > #include  "source.h"
14   #include  "otypes.h"
15 + #include  "rtotypes.h"
16 + #include  "func.h"
17  
18   /*
19   *      Arguments to this material include the color and specularity.
20   *  String arguments include the reflection function and files.
21   *  The BRDF is currently used just for the specular component to light
22   *  sources.  Reflectance values or data coordinates are functions
23 < *  of the direction to the light source.
23 > *  of the direction to the light source.  (Data modification functions
24 > *  are passed the source direction as args 2-4.)
25   *      We orient the surface towards the incoming ray, so a single
26   *  surface can be used to represent an infinitely thin object.
27   *
# Line 36 | Line 38 | static char SCCSid[] = "$SunId$ LBL";
38   *  Arguments for MAT_TFUNC are:
39   *      2+      func    funcfile        transform
40   *      0
41 < *      4+      red     grn     blu     rspec   trans   tspec   A7 ..
41 > *      6+      red     grn     blu     rspec   trans   tspec   A7 ..
42   *
43   *  Arguments for MAT_TDATA are:
44   *      4+      func    datafile        funcfile        v0 ..   transform
45   *      0
46 < *      4+      red     grn     blu     rspec   trans   tspec   A7 ..
46 > *      6+      red     grn     blu     rspec   trans   tspec   A7 ..
47   *
48   *  Arguments for the more general MAT_BRTDF are:
49   *      10+     rrefl   grefl   brefl
# Line 49 | Line 51 | static char SCCSid[] = "$SunId$ LBL";
51   *              rbrtd   gbrtd   bbrtd
52   *              funcfile        transform
53   *      0
54 < *      6+      red     grn     blu     rspec   trans   tspec   A7 ..
54 > *      9+      rdf     gdf     bdf
55 > *              rdb     gdb     bdb
56 > *              rdt     gdt     bdt     A10 ..
57   *
58   *      In addition to the normal variables available to functions,
59   *  we define the following:
60   *              NxP, NyP, NzP -         perturbed surface normal
61   *              RdotP -                 perturbed ray dot product
62 < *              CrP, CgP, CbP -         perturbed material color
62 > *              CrP, CgP, CbP -         perturbed material color (or pattern)
63   */
64  
61 extern double   funvalue(), varvalue();
62 extern XF  funcxf;
63
65   typedef struct {
66          OBJREC  *mp;            /* material pointer */
67          RAY  *pr;               /* intersected ray */
68          DATARRAY  *dp;          /* data array for PDATA, MDATA or TDATA */
69 <        COLOR  mcolor;          /* color of this material */
70 <        double  rspec;          /* specular reflection */
71 <        double  rdiff;          /* diffuse reflection */
72 <        double  trans;          /* transmissivity */
73 <        double  tspec;          /* specular transmission */
74 <        double  tdiff;          /* diffuse transmission */
69 >        COLOR  mcolor;          /* material (or pattern) color */
70 >        COLOR  rdiff;           /* diffuse reflection */
71 >        COLOR  tdiff;           /* diffuse transmission */
72 >        double  rspec;          /* specular reflectance (1 for BRDTF) */
73 >        double  trans;          /* transmissivity (.5 for BRDTF) */
74 >        double  tspec;          /* specular transmittance (1 for BRDTF) */
75          FVECT  pnorm;           /* perturbed surface normal */
76          double  pdot;           /* perturbed dot product */
77   }  BRDFDAT;             /* BRDF material data */
78  
79  
80 < dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
81 < COLOR  cval;                    /* returned coefficient */
82 < register BRDFDAT  *np;          /* material data */
83 < FVECT  ldir;                    /* light source direction */
84 < double  omega;                  /* light source size */
80 > static int setbrdfunc(BRDFDAT *np);
81 >
82 >
83 > static void
84 > dirbrdf(                /* compute source contribution */
85 >        COLOR  cval,                    /* returned coefficient */
86 >        void  *nnp,             /* material data */
87 >        FVECT  ldir,                    /* light source direction */
88 >        double  omega                   /* light source size */
89 > )
90   {
91 +        BRDFDAT *np = nnp;
92          double  ldot;
93          double  dtmp;
94          COLOR  ctmp;
95          FVECT  ldx;
96 <        double  pt[MAXDIM];
97 <        register char   **sa;
98 <        register int    i;
96 >        static double  vldx[5], pt[MAXDIM];
97 >        char    **sa;
98 >        int     i;
99 > #define lddx (vldx+1)
100  
101          setcolor(cval, 0.0, 0.0, 0.0);
102          
# Line 96 | Line 104 | double  omega;                 /* light source size */
104  
105          if (ldot <= FTINY && ldot >= -FTINY)
106                  return;         /* too close to grazing */
107 +
108          if (ldot < 0.0 ? np->trans <= FTINY : np->trans >= 1.0-FTINY)
109                  return;         /* wrong side */
110  
111 <        if (ldot > 0.0 && np->rdiff > FTINY) {
111 >        if (ldot > 0.0) {
112                  /*
113                   *  Compute and add diffuse reflected component to returned
114                   *  color.  The diffuse reflected component will always be
115                   *  modified by the color of the material.
116                   */
117 <                copycolor(ctmp, np->mcolor);
118 <                dtmp = ldot * omega * np->rdiff / PI;
117 >                copycolor(ctmp, np->rdiff);
118 >                dtmp = ldot * omega / PI;
119                  scalecolor(ctmp, dtmp);
120                  addcolor(cval, ctmp);
121 <        }
113 <        if (ldot < 0.0 && np->tdiff > FTINY) {
121 >        } else {
122                  /*
123                   *  Diffuse transmitted component.
124                   */
125 <                copycolor(ctmp, np->mcolor);
126 <                dtmp = -ldot * omega * np->tdiff / PI;
125 >                copycolor(ctmp, np->tdiff);
126 >                dtmp = -ldot * omega / PI;
127                  scalecolor(ctmp, dtmp);
128                  addcolor(cval, ctmp);
129          }
130          if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
131 <                return;         /* no specular component */
131 >                return;         /* diffuse only */
132                                          /* set up function */
133          setbrdfunc(np);
134          sa = np->mp->oargs.sarg;
# Line 128 | Line 136 | double  omega;                 /* light source size */
136                                          /* transform light vector */
137          multv3(ldx, ldir, funcxf.xfm);
138          for (i = 0; i < 3; i++)
139 <                ldx[i] /= funcxf.sca;
139 >                lddx[i] = ldx[i]/funcxf.sca;
140 >        lddx[3] = omega;
141                                          /* compute BRTDF */
142          if (np->mp->otype == MAT_BRTDF) {
143 <                colval(ctmp,RED) = funvalue(sa[6], 3, ldx);
144 <                if (!strcmp(sa[7],sa[6]))
143 >                if (sa[6][0] == '0' && !sa[6][1])       /* special case */
144 >                        colval(ctmp,RED) = 0.0;
145 >                else
146 >                        colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
147 >                if (sa[7][0] == '0' && !sa[7][1])
148 >                        colval(ctmp,GRN) = 0.0;
149 >                else if (!strcmp(sa[7],sa[6]))
150                          colval(ctmp,GRN) = colval(ctmp,RED);
151                  else
152 <                        colval(ctmp,GRN) = funvalue(sa[7], 3, ldx);
153 <                if (!strcmp(sa[8],sa[6]))
152 >                        colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
153 >                if (sa[8][0] == '0' && !sa[8][1])
154 >                        colval(ctmp,BLU) = 0.0;
155 >                else if (!strcmp(sa[8],sa[6]))
156                          colval(ctmp,BLU) = colval(ctmp,RED);
157                  else if (!strcmp(sa[8],sa[7]))
158                          colval(ctmp,BLU) = colval(ctmp,GRN);
159                  else
160 <                        colval(ctmp,BLU) = funvalue(sa[8], 3, ldx);
160 >                        colval(ctmp,BLU) = funvalue(sa[8], 4, lddx);
161                  dtmp = bright(ctmp);
162          } else if (np->dp == NULL) {
163 <                dtmp = funvalue(sa[0], 3, ldx);
163 >                dtmp = funvalue(sa[0], 4, lddx);
164                  setcolor(ctmp, dtmp, dtmp, dtmp);
165          } else {
166                  for (i = 0; i < np->dp->nd; i++)
167 <                        pt[i] = funvalue(sa[3+i], 3, ldx);
168 <                dtmp = datavalue(np->dp, pt);
169 <                dtmp = funvalue(sa[0], 1, &dtmp);
167 >                        pt[i] = funvalue(sa[3+i], 4, lddx);
168 >                vldx[0] = datavalue(np->dp, pt);
169 >                dtmp = funvalue(sa[0], 5, vldx);
170                  setcolor(ctmp, dtmp, dtmp, dtmp);
171          }
172 <        if (errno)
173 <                goto computerr;
172 >        if ((errno == EDOM) | (errno == ERANGE)) {
173 >                objerror(np->mp, WARNING, "compute error");
174 >                return;
175 >        }
176          if (dtmp <= FTINY)
177                  return;
178          if (ldot > 0.0) {
179                  /*
180                   *  Compute reflected non-diffuse component.
181                   */
182 <                if (np->mp->otype == MAT_MFUNC || np->mp->otype == MAT_MDATA)
182 >                if ((np->mp->otype == MAT_MFUNC) | (np->mp->otype == MAT_MDATA))
183                          multcolor(ctmp, np->mcolor);
184                  dtmp = ldot * omega * np->rspec;
185                  scalecolor(ctmp, dtmp);
# Line 170 | Line 188 | double  omega;                 /* light source size */
188                  /*
189                   *  Compute transmitted non-diffuse component.
190                   */
191 <                if (np->mp->otype == MAT_TFUNC || np->mp->otype == MAT_TDATA)
191 >                if ((np->mp->otype == MAT_TFUNC) | (np->mp->otype == MAT_TDATA))
192                          multcolor(ctmp, np->mcolor);
193                  dtmp = -ldot * omega * np->tspec;
194                  scalecolor(ctmp, dtmp);
195                  addcolor(cval, ctmp);
196          }
197 <        return;
180 < computerr:
181 <        objerror(np->mp, WARNING, "compute error");
182 <        return;
197 > #undef lddx
198   }
199  
200  
201 < m_brdf(m, r)                    /* color a ray which hit a BRDF material */
202 < register OBJREC  *m;
203 < register RAY  *r;
201 > int
202 > m_brdf(                 /* color a ray that hit a BRDTfunc material */
203 >        OBJREC  *m,
204 >        RAY  *r
205 > )
206   {
207 <        int  minsa, minfa;
207 >        int  hitfront = 1;
208          BRDFDAT  nd;
209 <        double  transtest, transdist;
209 >        RAY  sr;
210 >        double  mirtest=0, mirdist=0;
211 >        double  transtest=0, transdist=0;
212 >        int  hasrefl, hastrans;
213 >        int  hastexture;
214          COLOR  ctmp;
215 <        double  dtmp;
216 <        register int  i;
215 >        FVECT  vtmp;
216 >        double  d;
217 >        MFUNC  *mf;
218 >        int  i;
219                                                  /* check arguments */
220 <        switch (m->otype) {
198 <        case MAT_PFUNC: case MAT_MFUNC:
199 <                minsa = 2; minfa = 4; break;
200 <        case MAT_PDATA: case MAT_MDATA:
201 <                minsa = 4; minfa = 4; break;
202 <        case MAT_TFUNC:
203 <                minsa = 2; minfa = 6; break;
204 <        case MAT_TDATA:
205 <                minsa = 4; minfa = 6; break;
206 <        case MAT_BRTDF:
207 <                minsa = 10; minfa = 6; break;
208 <        }
209 <        if (m->oargs.nsargs < minsa || m->oargs.nfargs < minfa)
220 >        if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
221                  objerror(m, USER, "bad # arguments");
222          nd.mp = m;
223          nd.pr = r;
224 <                                                /* get specular component */
225 <        nd.rspec = m->oargs.farg[3];
226 <                                                /* compute transmission */
227 <        if (m->otype == MAT_TFUNC || m->otype == MAT_TDATA
228 <                        || m->otype == MAT_BRTDF) {
229 <                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
230 <                nd.tspec = nd.trans * m->oargs.farg[5];
231 <                nd.tdiff = nd.trans - nd.tspec;
232 <        } else
233 <                nd.tdiff = nd.tspec = nd.trans = 0.0;
234 <                                                /* early shadow check */
235 <        if (r->crtype & SHADOW && (m->otype != MAT_BRTDF || nd.tspec <= FTINY))
236 <                return;
237 <                                                /* diffuse reflection */
238 <        nd.rdiff = 1.0 - nd.trans - nd.rspec;
239 <                                                /* get material color */
229 <        setcolor(nd.mcolor, m->oargs.farg[0],
230 <                           m->oargs.farg[1],
231 <                           m->oargs.farg[2]);
232 <                                                /* fix orientation */
233 <        if (r->rod < 0.0)
234 <                flipsurface(r);
224 >                                                /* dummy values */
225 >        nd.rspec = nd.tspec = 1.0;
226 >        nd.trans = 0.5;
227 >                                                /* diffuse reflectance */
228 >        if (r->rod > 0.0)
229 >                setcolor(nd.rdiff, m->oargs.farg[0],
230 >                                m->oargs.farg[1],
231 >                                m->oargs.farg[2]);
232 >        else
233 >                setcolor(nd.rdiff, m->oargs.farg[3],
234 >                                m->oargs.farg[4],
235 >                                m->oargs.farg[5]);
236 >                                                /* diffuse transmittance */
237 >        setcolor(nd.tdiff, m->oargs.farg[6],
238 >                        m->oargs.farg[7],
239 >                        m->oargs.farg[8]);
240                                                  /* get modifiers */
241          raytexture(r, m->omod);
242 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
243 <        multcolor(nd.mcolor, r->pcol);          /* modify material color */
244 <        transtest = 0;
240 <                                                /* load auxiliary files */
241 <        if (m->otype == MAT_PDATA || m->otype == MAT_MDATA
242 <                        || m->otype == MAT_TDATA) {
243 <                nd.dp = getdata(m->oargs.sarg[1]);
244 <                for (i = 3; i < m->oargs.nsargs; i++)
245 <                        if (m->oargs.sarg[i][0] == '-')
246 <                                break;
247 <                if (i-3 != nd.dp->nd)
248 <                        objerror(m, USER, "dimension error");
249 <                if (!fundefined(m->oargs.sarg[3]))
250 <                        loadfunc(m->oargs.sarg[2]);
251 <        } else if (m->otype == MAT_BRTDF) {
252 <                nd.dp = NULL;
253 <                if (!fundefined(m->oargs.sarg[7]))
254 <                        loadfunc(m->oargs.sarg[9]);
242 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
243 >        if (hastexture) {                       /* perturb normal */
244 >                nd.pdot = raynormal(nd.pnorm, r);
245          } else {
246 <                nd.dp = NULL;
247 <                if (!fundefined(m->oargs.sarg[0]))
258 <                        loadfunc(m->oargs.sarg[1]);
246 >                VCOPY(nd.pnorm, r->ron);
247 >                nd.pdot = r->rod;
248          }
249 <                                                /* set special variables */
250 <        setbrdfunc(&nd);
249 >        if (r->rod < 0.0) {                     /* orient perturbed values */
250 >                nd.pdot = -nd.pdot;
251 >                for (i = 0; i < 3; i++) {
252 >                        nd.pnorm[i] = -nd.pnorm[i];
253 >                        r->pert[i] = -r->pert[i];
254 >                }
255 >                hitfront = 0;
256 >        }
257 >        copycolor(nd.mcolor, r->pcol);          /* get pattern color */
258 >        multcolor(nd.rdiff, nd.mcolor);         /* modify diffuse values */
259 >        multcolor(nd.tdiff, nd.mcolor);
260 >        hasrefl = bright(nd.rdiff) > FTINY;
261 >        hastrans = bright(nd.tdiff) > FTINY;
262 >                                                /* load cal file */
263 >        nd.dp = NULL;
264 >        mf = getfunc(m, 9, 0x3f, 0);
265                                                  /* compute transmitted ray */
266 <        if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
267 <                RAY  sr;
268 <                errno = 0;
269 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
270 <                                varvalue(m->oargs.sarg[1]),
271 <                                varvalue(m->oargs.sarg[2]));
272 <                scalecolor(ctmp, nd.tspec);
273 <                if (errno)
274 <                        objerror(m, WARNING, "compute error");
275 <                else if ((dtmp = bright(ctmp)) > FTINY &&
276 <                                rayorigin(&sr, r, TRANS, dtmp) == 0) {
277 <                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
278 <                                for (i = 0; i < 3; i++) /* perturb direction */
276 <                                        sr.rdir[i] = r->rdir[i] -
277 <                                                        .75*r->pert[i];
278 <                                normalize(sr.rdir);
279 <                        } else {
266 >        setbrdfunc(&nd);
267 >        errno = 0;
268 >        setcolor(ctmp, evalue(mf->ep[3]),
269 >                        evalue(mf->ep[4]),
270 >                        evalue(mf->ep[5]));
271 >        if ((errno == EDOM) | (errno == ERANGE))
272 >                objerror(m, WARNING, "compute error");
273 >        else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
274 >                if (!(r->crtype & SHADOW) && hastexture) {
275 >                                                /* perturb direction */
276 >                        VSUM(sr.rdir, r->rdir, r->pert, -.75);
277 >                        if (normalize(sr.rdir) == 0.0) {
278 >                                objerror(m, WARNING, "illegal perturbation");
279                                  VCOPY(sr.rdir, r->rdir);
281                                transtest = 2;
280                          }
281 <                        rayvalue(&sr);
282 <                        multcolor(sr.rcol, ctmp);
283 <                        addcolor(r->rcol, sr.rcol);
284 <                        transtest *= bright(sr.rcol);
281 >                } else {
282 >                        VCOPY(sr.rdir, r->rdir);
283 >                }
284 >                rayvalue(&sr);
285 >                multcolor(sr.rcol, sr.rcoef);
286 >                addcolor(r->rcol, sr.rcol);
287 >                if (!hastexture) {
288 >                        transtest = 2.0*bright(sr.rcol);
289                          transdist = r->rot + sr.rt;
290                  }
291          }
292          if (r->crtype & SHADOW)                 /* the rest is shadow */
293 <                return;
293 >                return(1);
294                                                  /* compute reflected ray */
295 <        if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
296 <                RAY  sr;
297 <                errno = 0;
298 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
299 <                                varvalue(m->oargs.sarg[4]),
300 <                                varvalue(m->oargs.sarg[5]));
301 <                scalecolor(ctmp, nd.rspec);
302 <                if (errno)
303 <                        objerror(m, WARNING, "compute error");
304 <                else if ((dtmp = bright(ctmp)) > FTINY &&
305 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
306 <                        for (i = 0; i < 3; i++)
307 <                                sr.rdir[i] = r->rdir[i] +
308 <                                                2.0*nd.pdot*nd.pnorm[i];
309 <                        rayvalue(&sr);
310 <                        multcolor(sr.rcol, ctmp);
309 <                        addcolor(r->rcol, sr.rcol);
295 >        setbrdfunc(&nd);
296 >        errno = 0;
297 >        setcolor(ctmp, evalue(mf->ep[0]),
298 >                        evalue(mf->ep[1]),
299 >                        evalue(mf->ep[2]));
300 >        if ((errno == EDOM) | (errno == ERANGE))
301 >                objerror(m, WARNING, "compute error");
302 >        else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
303 >                VSUM(sr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot);
304 >                checknorm(sr.rdir);
305 >                rayvalue(&sr);
306 >                multcolor(sr.rcol, sr.rcoef);
307 >                addcolor(r->rcol, sr.rcol);
308 >                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
309 >                        mirtest = 2.0*bright(sr.rcol);
310 >                        mirdist = r->rot + sr.rt;
311                  }
312          }
313                                                  /* compute ambient */
314 <        if (nd.rdiff > FTINY) {
315 <                ambient(ctmp, r);
316 <                if (m->otype == MAT_BRTDF)
317 <                        scalecolor(ctmp, nd.rdiff);
318 <                else
318 <                        scalecolor(ctmp, 1.0-nd.trans);
319 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
314 >        if (hasrefl) {
315 >                if (!hitfront)
316 >                        flipsurface(r);
317 >                copycolor(ctmp, nd.rdiff);
318 >                multambient(ctmp, r, nd.pnorm);
319                  addcolor(r->rcol, ctmp);        /* add to returned color */
320 +                if (!hitfront)
321 +                        flipsurface(r);
322          }
323 <        if (nd.tdiff > FTINY) {                 /* from other side */
323 >        if (hastrans) {                         /* from other side */
324 >                if (hitfront)
325 >                        flipsurface(r);
326 >                vtmp[0] = -nd.pnorm[0];
327 >                vtmp[1] = -nd.pnorm[1];
328 >                vtmp[2] = -nd.pnorm[2];
329 >                copycolor(ctmp, nd.tdiff);
330 >                multambient(ctmp, r, vtmp);
331 >                addcolor(r->rcol, ctmp);
332 >                if (hitfront)
333 >                        flipsurface(r);
334 >        }
335 >        if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
336 >                direct(r, dirbrdf, &nd);        /* add direct component */
337 >
338 >        d = bright(r->rcol);                    /* set effective distance */
339 >        if (transtest > d)
340 >                r->rt = transdist;
341 >        else if (mirtest > d)
342 >                r->rt = mirdist;
343 >
344 >        return(1);
345 > }
346 >
347 >
348 >
349 > int
350 > m_brdf2(                        /* color a ray that hit a BRDF material */
351 >        OBJREC  *m,
352 >        RAY  *r
353 > )
354 > {
355 >        BRDFDAT  nd;
356 >        COLOR  ctmp;
357 >        FVECT  vtmp;
358 >        double  dtmp;
359 >                                                /* always a shadow */
360 >        if (r->crtype & SHADOW)
361 >                return(1);
362 >                                                /* check arguments */
363 >        if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
364 >                        ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
365 >                objerror(m, USER, "bad # arguments");
366 >                                                /* check for back side */
367 >        if (r->rod < 0.0) {
368 >                if (!backvis) {
369 >                        raytrans(r);
370 >                        return(1);
371 >                }
372 >                raytexture(r, m->omod);
373 >                flipsurface(r);                 /* reorient if backvis */
374 >        } else
375 >                raytexture(r, m->omod);
376 >
377 >        nd.mp = m;
378 >        nd.pr = r;
379 >                                                /* get material color */
380 >        setcolor(nd.mcolor, m->oargs.farg[0],
381 >                        m->oargs.farg[1],
382 >                        m->oargs.farg[2]);
383 >                                                /* get specular component */
384 >        nd.rspec = m->oargs.farg[3];
385 >                                                /* compute transmittance */
386 >        if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) {
387 >                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
388 >                nd.tspec = nd.trans * m->oargs.farg[5];
389 >                dtmp = nd.trans - nd.tspec;
390 >                setcolor(nd.tdiff, dtmp, dtmp, dtmp);
391 >        } else {
392 >                nd.tspec = nd.trans = 0.0;
393 >                setcolor(nd.tdiff, 0.0, 0.0, 0.0);
394 >        }
395 >                                                /* compute reflectance */
396 >        dtmp = 1.0 - nd.trans - nd.rspec;
397 >        setcolor(nd.rdiff, dtmp, dtmp, dtmp);
398 >        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
399 >        multcolor(nd.mcolor, r->pcol);          /* modify material color */
400 >        multcolor(nd.rdiff, nd.mcolor);
401 >        multcolor(nd.tdiff, nd.mcolor);
402 >                                                /* load auxiliary files */
403 >        if (hasdata(m->otype)) {
404 >                nd.dp = getdata(m->oargs.sarg[1]);
405 >                getfunc(m, 2, 0, 0);
406 >        } else {
407 >                nd.dp = NULL;
408 >                getfunc(m, 1, 0, 0);
409 >        }
410 >                                                /* compute ambient */
411 >        if (nd.trans < 1.0-FTINY) {
412 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
413 >                scalecolor(ctmp, 1.0-nd.trans);
414 >                multambient(ctmp, r, nd.pnorm);
415 >                addcolor(r->rcol, ctmp);        /* add to returned color */
416 >        }
417 >        if (nd.trans > FTINY) {         /* from other side */
418                  flipsurface(r);
419 <                ambient(ctmp, r);
420 <                if (m->otype == MAT_BRTDF)
421 <                        scalecolor(ctmp, nd.tdiff);
422 <                else
423 <                        scalecolor(ctmp, nd.trans);
424 <                multcolor(ctmp, nd.mcolor);
419 >                vtmp[0] = -nd.pnorm[0];
420 >                vtmp[1] = -nd.pnorm[1];
421 >                vtmp[2] = -nd.pnorm[2];
422 >                copycolor(ctmp, nd.mcolor);
423 >                scalecolor(ctmp, nd.trans);
424 >                multambient(ctmp, r, vtmp);
425                  addcolor(r->rcol, ctmp);
426                  flipsurface(r);
427          }
428                                                  /* add direct component */
429          direct(r, dirbrdf, &nd);
430 <                                                /* check distance */
431 <        if (transtest > bright(r->rcol))
337 <                r->rt = transdist;
430 >
431 >        return(1);
432   }
433  
434  
435 < setbrdfunc(np)                  /* set up brdf function and variables */
436 < register BRDFDAT  *np;
435 > static int
436 > setbrdfunc(                     /* set up brdf function and variables */
437 >        BRDFDAT  *np
438 > )
439   {
440          FVECT  vec;
441  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines