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.12 by greg, Fri Jun 28 10:04:02 1991 UTC vs.
Revision 2.26 by greg, Sun Sep 26 15:51:15 2010 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 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 srcdirf_t dirbrdf;
81 > static int setbrdfunc(BRDFDAT  *np);
82 >
83 >
84 > static void
85 > dirbrdf(                /* compute source contribution */
86 >        COLOR  cval,                    /* returned coefficient */
87 >        void  *nnp,             /* material data */
88 >        FVECT  ldir,                    /* light source direction */
89 >        double  omega                   /* light source size */
90 > )
91   {
92 +        register BRDFDAT *np = nnp;
93          double  ldot;
94          double  dtmp;
95          COLOR  ctmp;
96          FVECT  ldx;
97 <        double  pt[MAXDIM];
97 >        static double  vldx[5], pt[MAXDIM];
98          register char   **sa;
99          register int    i;
100 + #define lddx (vldx+1)
101  
102          setcolor(cval, 0.0, 0.0, 0.0);
103          
# Line 96 | Line 105 | double  omega;                 /* light source size */
105  
106          if (ldot <= FTINY && ldot >= -FTINY)
107                  return;         /* too close to grazing */
108 +
109          if (ldot < 0.0 ? np->trans <= FTINY : np->trans >= 1.0-FTINY)
110                  return;         /* wrong side */
111  
112 <        if (ldot > 0.0 && np->rdiff > FTINY) {
112 >        if (ldot > 0.0) {
113                  /*
114                   *  Compute and add diffuse reflected component to returned
115                   *  color.  The diffuse reflected component will always be
116                   *  modified by the color of the material.
117                   */
118 <                copycolor(ctmp, np->mcolor);
119 <                dtmp = ldot * omega * np->rdiff / PI;
118 >                copycolor(ctmp, np->rdiff);
119 >                dtmp = ldot * omega / PI;
120                  scalecolor(ctmp, dtmp);
121                  addcolor(cval, ctmp);
122 <        }
113 <        if (ldot < 0.0 && np->tdiff > FTINY) {
122 >        } else {
123                  /*
124                   *  Diffuse transmitted component.
125                   */
126 <                copycolor(ctmp, np->mcolor);
127 <                dtmp = -ldot * omega * np->tdiff / PI;
126 >                copycolor(ctmp, np->tdiff);
127 >                dtmp = -ldot * omega / PI;
128                  scalecolor(ctmp, dtmp);
129                  addcolor(cval, ctmp);
130          }
131          if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY)
132 <                return;         /* no specular component */
132 >                return;         /* diffuse only */
133                                          /* set up function */
134          setbrdfunc(np);
135          sa = np->mp->oargs.sarg;
# Line 128 | Line 137 | double  omega;                 /* light source size */
137                                          /* transform light vector */
138          multv3(ldx, ldir, funcxf.xfm);
139          for (i = 0; i < 3; i++)
140 <                ldx[i] /= funcxf.sca;
140 >                lddx[i] = ldx[i]/funcxf.sca;
141 >        lddx[3] = omega;
142                                          /* compute BRTDF */
143          if (np->mp->otype == MAT_BRTDF) {
144 <                colval(ctmp,RED) = funvalue(sa[6], 3, ldx);
145 <                if (!strcmp(sa[7],sa[6]))
144 >                if (sa[6][0] == '0')            /* special case */
145 >                        colval(ctmp,RED) = 0.0;
146 >                else
147 >                        colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
148 >                if (sa[7][0] == '0')
149 >                        colval(ctmp,GRN) = 0.0;
150 >                else if (!strcmp(sa[7],sa[6]))
151                          colval(ctmp,GRN) = colval(ctmp,RED);
152                  else
153 <                        colval(ctmp,GRN) = funvalue(sa[7], 3, ldx);
153 >                        colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
154                  if (!strcmp(sa[8],sa[6]))
155                          colval(ctmp,BLU) = colval(ctmp,RED);
156                  else if (!strcmp(sa[8],sa[7]))
157                          colval(ctmp,BLU) = colval(ctmp,GRN);
158                  else
159 <                        colval(ctmp,BLU) = funvalue(sa[8], 3, ldx);
159 >                        colval(ctmp,BLU) = funvalue(sa[8], 4, lddx);
160                  dtmp = bright(ctmp);
161          } else if (np->dp == NULL) {
162 <                dtmp = funvalue(sa[0], 3, ldx);
162 >                dtmp = funvalue(sa[0], 4, lddx);
163                  setcolor(ctmp, dtmp, dtmp, dtmp);
164          } else {
165                  for (i = 0; i < np->dp->nd; i++)
166 <                        pt[i] = funvalue(sa[3+i], 3, ldx);
167 <                dtmp = datavalue(np->dp, pt);
168 <                dtmp = funvalue(sa[0], 1, &dtmp);
166 >                        pt[i] = funvalue(sa[3+i], 4, lddx);
167 >                vldx[0] = datavalue(np->dp, pt);
168 >                dtmp = funvalue(sa[0], 5, vldx);
169                  setcolor(ctmp, dtmp, dtmp, dtmp);
170          }
171 <        if (errno)
172 <                goto computerr;
171 >        if ((errno == EDOM) | (errno == ERANGE)) {
172 >                objerror(np->mp, WARNING, "compute error");
173 >                return;
174 >        }
175          if (dtmp <= FTINY)
176                  return;
177          if (ldot > 0.0) {
178                  /*
179                   *  Compute reflected non-diffuse component.
180                   */
181 <                if (np->mp->otype == MAT_MFUNC || np->mp->otype == MAT_MDATA)
181 >                if ((np->mp->otype == MAT_MFUNC) | (np->mp->otype == MAT_MDATA))
182                          multcolor(ctmp, np->mcolor);
183                  dtmp = ldot * omega * np->rspec;
184                  scalecolor(ctmp, dtmp);
# Line 170 | Line 187 | double  omega;                 /* light source size */
187                  /*
188                   *  Compute transmitted non-diffuse component.
189                   */
190 <                if (np->mp->otype == MAT_TFUNC || np->mp->otype == MAT_TDATA)
190 >                if ((np->mp->otype == MAT_TFUNC) | (np->mp->otype == MAT_TDATA))
191                          multcolor(ctmp, np->mcolor);
192                  dtmp = -ldot * omega * np->tspec;
193                  scalecolor(ctmp, dtmp);
194                  addcolor(cval, ctmp);
195          }
196 <        return;
180 < computerr:
181 <        objerror(np->mp, WARNING, "compute error");
182 <        return;
196 > #undef lddx
197   }
198  
199  
200 < m_brdf(m, r)                    /* color a ray which hit a BRDF material */
201 < register OBJREC  *m;
202 < register RAY  *r;
200 > extern int
201 > m_brdf(                 /* color a ray that hit a BRDTfunc material */
202 >        register OBJREC  *m,
203 >        register RAY  *r
204 > )
205   {
206 <        int  minsa, minfa;
206 >        int  hitfront = 1;
207          BRDFDAT  nd;
208 +        RAY  sr;
209 +        double  mirtest=0, mirdist=0;
210          double  transtest, transdist;
211 +        int  hasrefl, hastrans;
212 +        int  hastexture;
213          COLOR  ctmp;
214 <        double  dtmp;
214 >        FVECT  vtmp;
215 >        double  d;
216 >        register MFUNC  *mf;
217          register int  i;
218                                                  /* check arguments */
219 <        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)
219 >        if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
220                  objerror(m, USER, "bad # arguments");
221          nd.mp = m;
222          nd.pr = r;
223 <                                                /* get specular component */
224 <        nd.rspec = m->oargs.farg[3];
225 <                                                /* compute transmission */
226 <        if (m->otype == MAT_TFUNC || m->otype == MAT_TDATA
227 <                        || m->otype == MAT_BRTDF) {
228 <                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
229 <                nd.tspec = nd.trans * m->oargs.farg[5];
230 <                nd.tdiff = nd.trans - nd.tspec;
231 <        } else
232 <                nd.tdiff = nd.tspec = nd.trans = 0.0;
233 <                                                /* early shadow check */
234 <        if (r->crtype & SHADOW && (m->otype != MAT_BRTDF || nd.tspec <= FTINY))
235 <                return;
236 <                                                /* diffuse reflection */
237 <        nd.rdiff = 1.0 - nd.trans - nd.rspec;
238 <                                                /* 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);
223 >                                                /* dummy values */
224 >        nd.rspec = nd.tspec = 1.0;
225 >        nd.trans = 0.5;
226 >                                                /* diffuse reflectance */
227 >        if (r->rod > 0.0)
228 >                setcolor(nd.rdiff, m->oargs.farg[0],
229 >                                m->oargs.farg[1],
230 >                                m->oargs.farg[2]);
231 >        else
232 >                setcolor(nd.rdiff, m->oargs.farg[3],
233 >                                m->oargs.farg[4],
234 >                                m->oargs.farg[5]);
235 >                                                /* diffuse transmittance */
236 >        setcolor(nd.tdiff, m->oargs.farg[6],
237 >                        m->oargs.farg[7],
238 >                        m->oargs.farg[8]);
239                                                  /* get modifiers */
240          raytexture(r, m->omod);
241 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
242 <        multcolor(nd.mcolor, r->pcol);          /* modify material color */
243 <        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]);
241 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
242 >        if (hastexture) {                       /* perturb normal */
243 >                nd.pdot = raynormal(nd.pnorm, r);
244          } else {
245 <                nd.dp = NULL;
246 <                if (!fundefined(m->oargs.sarg[0]))
258 <                        loadfunc(m->oargs.sarg[1]);
245 >                VCOPY(nd.pnorm, r->ron);
246 >                nd.pdot = r->rod;
247          }
248 <                                                /* set special variables */
249 <        setbrdfunc(&nd);
248 >        if (r->rod < 0.0) {                     /* orient perturbed values */
249 >                nd.pdot = -nd.pdot;
250 >                for (i = 0; i < 3; i++) {
251 >                        nd.pnorm[i] = -nd.pnorm[i];
252 >                        r->pert[i] = -r->pert[i];
253 >                }
254 >                hitfront = 0;
255 >        }
256 >        copycolor(nd.mcolor, r->pcol);          /* get pattern color */
257 >        multcolor(nd.rdiff, nd.mcolor);         /* modify diffuse values */
258 >        multcolor(nd.tdiff, nd.mcolor);
259 >        hasrefl = bright(nd.rdiff) > FTINY;
260 >        hastrans = bright(nd.tdiff) > FTINY;
261 >                                                /* load cal file */
262 >        nd.dp = NULL;
263 >        mf = getfunc(m, 9, 0x3f, 0);
264                                                  /* compute transmitted ray */
265 <        if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
266 <                RAY  sr;
267 <                errno = 0;
268 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
269 <                                varvalue(m->oargs.sarg[4]),
270 <                                varvalue(m->oargs.sarg[5]));
271 <                scalecolor(ctmp, nd.tspec);
272 <                if (errno)
273 <                        objerror(m, WARNING, "compute error");
274 <                else if ((dtmp = bright(ctmp)) > FTINY &&
275 <                                rayorigin(&sr, r, TRANS, dtmp) == 0) {
276 <                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
277 <                                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 {
265 >        setbrdfunc(&nd);
266 >        errno = 0;
267 >        setcolor(ctmp, evalue(mf->ep[3]),
268 >                        evalue(mf->ep[4]),
269 >                        evalue(mf->ep[5]));
270 >        if ((errno == EDOM) | (errno == ERANGE))
271 >                objerror(m, WARNING, "compute error");
272 >        else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
273 >                if (!(r->crtype & SHADOW) && hastexture) {
274 >                        for (i = 0; i < 3; i++) /* perturb direction */
275 >                                sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
276 >                        if (normalize(sr.rdir) == 0.0) {
277 >                                objerror(m, WARNING, "illegal perturbation");
278                                  VCOPY(sr.rdir, r->rdir);
281                                transtest = 2;
279                          }
280 <                        rayvalue(&sr);
281 <                        multcolor(sr.rcol, ctmp);
282 <                        addcolor(r->rcol, sr.rcol);
283 <                        transtest *= bright(sr.rcol);
280 >                } else {
281 >                        VCOPY(sr.rdir, r->rdir);
282 >                }
283 >                rayvalue(&sr);
284 >                multcolor(sr.rcol, sr.rcoef);
285 >                addcolor(r->rcol, sr.rcol);
286 >                if (!hastexture) {
287 >                        transtest = 2.0*bright(sr.rcol);
288                          transdist = r->rot + sr.rt;
289                  }
290          }
291          if (r->crtype & SHADOW)                 /* the rest is shadow */
292 <                return;
292 >                return(1);
293                                                  /* compute reflected ray */
294 <        if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
295 <                RAY  sr;
296 <                errno = 0;
297 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
298 <                                varvalue(m->oargs.sarg[1]),
299 <                                varvalue(m->oargs.sarg[2]));
300 <                scalecolor(ctmp, nd.rspec);
301 <                if (errno)
302 <                        objerror(m, WARNING, "compute error");
303 <                else if ((dtmp = bright(ctmp)) > FTINY &&
304 <                                rayorigin(&sr, r, REFLECTED, dtmp) == 0) {
305 <                        for (i = 0; i < 3; i++)
306 <                                sr.rdir[i] = r->rdir[i] +
307 <                                                2.0*nd.pdot*nd.pnorm[i];
308 <                        rayvalue(&sr);
309 <                        multcolor(sr.rcol, ctmp);
310 <                        addcolor(r->rcol, sr.rcol);
294 >        setbrdfunc(&nd);
295 >        errno = 0;
296 >        setcolor(ctmp, evalue(mf->ep[0]),
297 >                        evalue(mf->ep[1]),
298 >                        evalue(mf->ep[2]));
299 >        if ((errno == EDOM) | (errno == ERANGE))
300 >                objerror(m, WARNING, "compute error");
301 >        else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
302 >                for (i = 0; i < 3; i++)
303 >                        sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
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 > extern int
350 > m_brdf2(                        /* color a ray that hit a BRDF material */
351 >        register OBJREC  *m,
352 >        register 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 && m->otype != MAT_TFUNC
369 >                                && m->otype != MAT_TDATA) {
370 >                        raytrans(r);
371 >                        return(1);
372 >                }
373 >                raytexture(r, m->omod);
374 >                flipsurface(r);                 /* reorient if backvis */
375 >        } else
376 >                raytexture(r, m->omod);
377 >
378 >        nd.mp = m;
379 >        nd.pr = r;
380 >                                                /* get material color */
381 >        setcolor(nd.mcolor, m->oargs.farg[0],
382 >                        m->oargs.farg[1],
383 >                        m->oargs.farg[2]);
384 >                                                /* get specular component */
385 >        nd.rspec = m->oargs.farg[3];
386 >                                                /* compute transmittance */
387 >        if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) {
388 >                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
389 >                nd.tspec = nd.trans * m->oargs.farg[5];
390 >                dtmp = nd.trans - nd.tspec;
391 >                setcolor(nd.tdiff, dtmp, dtmp, dtmp);
392 >        } else {
393 >                nd.tspec = nd.trans = 0.0;
394 >                setcolor(nd.tdiff, 0.0, 0.0, 0.0);
395 >        }
396 >                                                /* compute reflectance */
397 >        dtmp = 1.0 - nd.trans - nd.rspec;
398 >        setcolor(nd.rdiff, dtmp, dtmp, dtmp);
399 >        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
400 >        multcolor(nd.mcolor, r->pcol);          /* modify material color */
401 >        multcolor(nd.rdiff, nd.mcolor);
402 >        multcolor(nd.tdiff, nd.mcolor);
403 >                                                /* load auxiliary files */
404 >        if (hasdata(m->otype)) {
405 >                nd.dp = getdata(m->oargs.sarg[1]);
406 >                getfunc(m, 2, 0, 0);
407 >        } else {
408 >                nd.dp = NULL;
409 >                getfunc(m, 1, 0, 0);
410 >        }
411 >                                                /* compute ambient */
412 >        if (nd.trans < 1.0-FTINY) {
413 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
414 >                scalecolor(ctmp, 1.0-nd.trans);
415 >                multambient(ctmp, r, nd.pnorm);
416 >                addcolor(r->rcol, ctmp);        /* add to returned color */
417 >        }
418 >        if (nd.trans > FTINY) {         /* from other side */
419                  flipsurface(r);
420 <                ambient(ctmp, r);
421 <                if (m->otype == MAT_BRTDF)
422 <                        scalecolor(ctmp, nd.tdiff);
423 <                else
424 <                        scalecolor(ctmp, nd.trans);
425 <                multcolor(ctmp, nd.mcolor);
420 >                vtmp[0] = -nd.pnorm[0];
421 >                vtmp[1] = -nd.pnorm[1];
422 >                vtmp[2] = -nd.pnorm[2];
423 >                copycolor(ctmp, nd.mcolor);
424 >                scalecolor(ctmp, nd.trans);
425 >                multambient(ctmp, r, vtmp);
426                  addcolor(r->rcol, ctmp);
427                  flipsurface(r);
428          }
429                                                  /* add direct component */
430          direct(r, dirbrdf, &nd);
431 <                                                /* check distance */
432 <        if (transtest > bright(r->rcol))
337 <                r->rt = transdist;
431 >
432 >        return(1);
433   }
434  
435  
436 < setbrdfunc(np)                  /* set up brdf function and variables */
437 < register BRDFDAT  *np;
436 > static int
437 > setbrdfunc(                     /* set up brdf function and variables */
438 >        register BRDFDAT  *np
439 > )
440   {
441          FVECT  vec;
442  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines