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.15 by greg, Thu Aug 8 11:30:01 1991 UTC vs.
Revision 2.22 by greg, Thu Sep 9 15:40:02 2004 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          }
# 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);
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 (!strcmp(sa[7],sa[6]))
149                          colval(ctmp,GRN) = colval(ctmp,RED);
150                  else
151 <                        colval(ctmp,GRN) = funvalue(sa[7], 3, ldx);
151 >                        colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
152                  if (!strcmp(sa[8],sa[6]))
153                          colval(ctmp,BLU) = colval(ctmp,RED);
154                  else if (!strcmp(sa[8],sa[7]))
155                          colval(ctmp,BLU) = colval(ctmp,GRN);
156                  else
157 <                        colval(ctmp,BLU) = funvalue(sa[8], 3, ldx);
157 >                        colval(ctmp,BLU) = funvalue(sa[8], 4, lddx);
158                  dtmp = bright(ctmp);
159          } else if (np->dp == NULL) {
160 <                dtmp = funvalue(sa[0], 3, ldx);
160 >                dtmp = funvalue(sa[0], 4, lddx);
161                  setcolor(ctmp, dtmp, dtmp, dtmp);
162          } else {
163                  for (i = 0; i < np->dp->nd; i++)
164 <                        pt[i] = funvalue(sa[3+i], 3, ldx);
165 <                dtmp = datavalue(np->dp, pt);
166 <                dtmp = funvalue(sa[0], 1, &dtmp);
164 >                        pt[i] = funvalue(sa[3+i], 4, lddx);
165 >                vldx[0] = datavalue(np->dp, pt);
166 >                dtmp = funvalue(sa[0], 5, vldx);
167                  setcolor(ctmp, dtmp, dtmp, dtmp);
168          }
169 <        if (errno)
170 <                goto computerr;
169 >        if (errno == EDOM || errno == ERANGE) {
170 >                objerror(np->mp, WARNING, "compute error");
171 >                return;
172 >        }
173          if (dtmp <= FTINY)
174                  return;
175          if (ldot > 0.0) {
176                  /*
177                   *  Compute reflected non-diffuse component.
178                   */
179 <                if (np->mp->otype == MAT_MFUNC || np->mp->otype == MAT_MDATA)
179 >                if ((np->mp->otype == MAT_MFUNC) | (np->mp->otype == MAT_MDATA))
180                          multcolor(ctmp, np->mcolor);
181                  dtmp = ldot * omega * np->rspec;
182                  scalecolor(ctmp, dtmp);
# Line 170 | Line 185 | double  omega;                 /* light source size */
185                  /*
186                   *  Compute transmitted non-diffuse component.
187                   */
188 <                if (np->mp->otype == MAT_TFUNC || np->mp->otype == MAT_TDATA)
188 >                if ((np->mp->otype == MAT_TFUNC) | (np->mp->otype == MAT_TDATA))
189                          multcolor(ctmp, np->mcolor);
190                  dtmp = -ldot * omega * np->tspec;
191                  scalecolor(ctmp, dtmp);
192                  addcolor(cval, ctmp);
193          }
194 <        return;
180 < computerr:
181 <        objerror(np->mp, WARNING, "compute error");
182 <        return;
194 > #undef lddx
195   }
196  
197  
198 < m_brdf(m, r)                    /* color a ray which hit a BRDF material */
199 < register OBJREC  *m;
200 < register RAY  *r;
198 > extern int
199 > m_brdf(                 /* color a ray that hit a BRDTfunc material */
200 >        register OBJREC  *m,
201 >        register RAY  *r
202 > )
203   {
204 <        int  minsa, minfa;
204 >        int  hitfront = 1;
205          BRDFDAT  nd;
206 +        RAY  sr;
207 +        double  mirtest=0, mirdist=0;
208          double  transtest, transdist;
209 +        int  hasrefl, hastrans;
210 +        int  hastexture;
211          COLOR  ctmp;
212 <        double  dtmp, tspect, rspecr;
212 >        FVECT  vtmp;
213 >        double  d;
214 >        register MFUNC  *mf;
215          register int  i;
216                                                  /* check arguments */
217 <        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)
217 >        if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
218                  objerror(m, USER, "bad # arguments");
219          nd.mp = m;
220          nd.pr = r;
221 <                                                /* get specular component */
222 <        nd.rspec = m->oargs.farg[3];
223 <                                                /* compute transmission */
224 <        if (m->otype == MAT_TFUNC || m->otype == MAT_TDATA
225 <                        || m->otype == MAT_BRTDF) {
226 <                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
227 <                nd.tspec = nd.trans * m->oargs.farg[5];
228 <                nd.tdiff = nd.trans - nd.tspec;
229 <        } else
230 <                nd.tdiff = nd.tspec = nd.trans = 0.0;
231 <                                                /* early shadow check */
232 <        if (r->crtype & SHADOW && (m->otype != MAT_BRTDF || nd.tspec <= FTINY))
233 <                return;
234 <                                                /* diffuse reflection */
235 <        nd.rdiff = 1.0 - nd.trans - nd.rspec;
236 <                                                /* 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);
221 >                                                /* dummy values */
222 >        nd.rspec = nd.tspec = 1.0;
223 >        nd.trans = 0.5;
224 >                                                /* diffuse reflectance */
225 >        if (r->rod > 0.0)
226 >                setcolor(nd.rdiff, m->oargs.farg[0],
227 >                                m->oargs.farg[1],
228 >                                m->oargs.farg[2]);
229 >        else
230 >                setcolor(nd.rdiff, m->oargs.farg[3],
231 >                                m->oargs.farg[4],
232 >                                m->oargs.farg[5]);
233 >                                                /* diffuse transmittance */
234 >        setcolor(nd.tdiff, m->oargs.farg[6],
235 >                        m->oargs.farg[7],
236 >                        m->oargs.farg[8]);
237                                                  /* get modifiers */
238          raytexture(r, m->omod);
239 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
240 <        multcolor(nd.mcolor, r->pcol);          /* modify material color */
241 <        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 <                funcfile(m->oargs.sarg[2]);
250 <        } else if (m->otype == MAT_BRTDF) {
251 <                nd.dp = NULL;
252 <                funcfile(m->oargs.sarg[9]);
239 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
240 >        if (hastexture) {                       /* perturb normal */
241 >                nd.pdot = raynormal(nd.pnorm, r);
242          } else {
243 <                nd.dp = NULL;
244 <                funcfile(m->oargs.sarg[1]);
243 >                VCOPY(nd.pnorm, r->ron);
244 >                nd.pdot = r->rod;
245          }
246 <                                                /* set special variables */
247 <        setbrdfunc(&nd);
246 >        if (r->rod < 0.0) {                     /* orient perturbed values */
247 >                nd.pdot = -nd.pdot;
248 >                for (i = 0; i < 3; i++) {
249 >                        nd.pnorm[i] = -nd.pnorm[i];
250 >                        r->pert[i] = -r->pert[i];
251 >                }
252 >                hitfront = 0;
253 >        }
254 >        copycolor(nd.mcolor, r->pcol);          /* get pattern color */
255 >        multcolor(nd.rdiff, nd.mcolor);         /* modify diffuse values */
256 >        multcolor(nd.tdiff, nd.mcolor);
257 >        hasrefl = bright(nd.rdiff) > FTINY;
258 >        hastrans = bright(nd.tdiff) > FTINY;
259 >                                                /* load cal file */
260 >        nd.dp = NULL;
261 >        mf = getfunc(m, 9, 0x3f, 0);
262                                                  /* compute transmitted ray */
263 <        tspect = 0.;
264 <        if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
265 <                RAY  sr;
266 <                errno = 0;
267 <                setcolor(ctmp, varvalue(m->oargs.sarg[3]),
268 <                                varvalue(m->oargs.sarg[4]),
269 <                                varvalue(m->oargs.sarg[5]));
270 <                scalecolor(ctmp, nd.trans);
271 <                if (errno)
272 <                        objerror(m, WARNING, "compute error");
273 <                else if ((tspect = bright(ctmp)) > FTINY &&
274 <                                rayorigin(&sr, r, TRANS, tspect) == 0) {
275 <                        if (DOT(r->pert,r->pert) > FTINY*FTINY) {
273 <                                for (i = 0; i < 3; i++) /* perturb direction */
274 <                                        sr.rdir[i] = r->rdir[i] -
275 <                                                        .75*r->pert[i];
276 <                                normalize(sr.rdir);
277 <                        } else {
263 >        setbrdfunc(&nd);
264 >        errno = 0;
265 >        setcolor(ctmp, evalue(mf->ep[3]),
266 >                        evalue(mf->ep[4]),
267 >                        evalue(mf->ep[5]));
268 >        if (errno == EDOM || errno == ERANGE)
269 >                objerror(m, WARNING, "compute error");
270 >        else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
271 >                if (!(r->crtype & SHADOW) && hastexture) {
272 >                        for (i = 0; i < 3; i++) /* perturb direction */
273 >                                sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
274 >                        if (normalize(sr.rdir) == 0.0) {
275 >                                objerror(m, WARNING, "illegal perturbation");
276                                  VCOPY(sr.rdir, r->rdir);
279                                transtest = 2;
277                          }
278 <                        rayvalue(&sr);
279 <                        multcolor(sr.rcol, ctmp);
280 <                        addcolor(r->rcol, sr.rcol);
281 <                        transtest *= bright(sr.rcol);
278 >                } else {
279 >                        VCOPY(sr.rdir, r->rdir);
280 >                }
281 >                rayvalue(&sr);
282 >                multcolor(sr.rcol, ctmp);
283 >                addcolor(r->rcol, sr.rcol);
284 >                if (!hastexture) {
285 >                        transtest = 2.0*bright(sr.rcol);
286                          transdist = r->rot + sr.rt;
287                  }
288          }
289          if (r->crtype & SHADOW)                 /* the rest is shadow */
290 <                return;
290 >                return(1);
291                                                  /* compute reflected ray */
292 <        rspecr = 0.;
293 <        if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
294 <                RAY  sr;
295 <                errno = 0;
296 <                setcolor(ctmp, varvalue(m->oargs.sarg[0]),
297 <                                varvalue(m->oargs.sarg[1]),
298 <                                varvalue(m->oargs.sarg[2]));
299 <                if (errno)
300 <                        objerror(m, WARNING, "compute error");
301 <                else if ((rspecr = bright(ctmp)) > FTINY &&
302 <                                rayorigin(&sr, r, REFLECTED, rspecr) == 0) {
303 <                        for (i = 0; i < 3; i++)
304 <                                sr.rdir[i] = r->rdir[i] +
305 <                                                2.0*nd.pdot*nd.pnorm[i];
306 <                        rayvalue(&sr);
307 <                        multcolor(sr.rcol, ctmp);
307 <                        addcolor(r->rcol, sr.rcol);
292 >        setbrdfunc(&nd);
293 >        errno = 0;
294 >        setcolor(ctmp, evalue(mf->ep[0]),
295 >                        evalue(mf->ep[1]),
296 >                        evalue(mf->ep[2]));
297 >        if (errno == EDOM || errno == ERANGE)
298 >                objerror(m, WARNING, "compute error");
299 >        else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
300 >                for (i = 0; i < 3; i++)
301 >                        sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
302 >                rayvalue(&sr);
303 >                multcolor(sr.rcol, ctmp);
304 >                addcolor(r->rcol, sr.rcol);
305 >                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
306 >                        mirtest = 2.0*bright(sr.rcol);
307 >                        mirdist = r->rot + sr.rt;
308                  }
309          }
310                                                  /* compute ambient */
311 <        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
312 <                ambient(ctmp, r);
313 <                scalecolor(ctmp, dtmp);
311 >        if (hasrefl) {
312 >                if (!hitfront)
313 >                        flipsurface(r);
314 >                ambient(ctmp, r, nd.pnorm);
315 >                multcolor(ctmp, nd.rdiff);
316 >                addcolor(r->rcol, ctmp);        /* add to returned color */
317 >                if (!hitfront)
318 >                        flipsurface(r);
319 >        }
320 >        if (hastrans) {                         /* from other side */
321 >                if (hitfront)
322 >                        flipsurface(r);
323 >                vtmp[0] = -nd.pnorm[0];
324 >                vtmp[1] = -nd.pnorm[1];
325 >                vtmp[2] = -nd.pnorm[2];
326 >                ambient(ctmp, r, vtmp);
327 >                multcolor(ctmp, nd.tdiff);
328 >                addcolor(r->rcol, ctmp);
329 >                if (hitfront)
330 >                        flipsurface(r);
331 >        }
332 >        if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
333 >                direct(r, dirbrdf, &nd);        /* add direct component */
334 >
335 >        d = bright(r->rcol);                    /* set effective distance */
336 >        if (transtest > d)
337 >                r->rt = transdist;
338 >        else if (mirtest > d)
339 >                r->rt = mirdist;
340 >
341 >        return(1);
342 > }
343 >
344 >
345 >
346 > extern int
347 > m_brdf2(                        /* color a ray that hit a BRDF material */
348 >        register OBJREC  *m,
349 >        register RAY  *r
350 > )
351 > {
352 >        BRDFDAT  nd;
353 >        COLOR  ctmp;
354 >        FVECT  vtmp;
355 >        double  dtmp;
356 >                                                /* always a shadow */
357 >        if (r->crtype & SHADOW)
358 >                return(1);
359 >                                                /* check arguments */
360 >        if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
361 >                        ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
362 >                objerror(m, USER, "bad # arguments");
363 >                                                /* check for back side */
364 >        if (r->rod < 0.0) {
365 >                if (!backvis && m->otype != MAT_TFUNC
366 >                                && m->otype != MAT_TDATA) {
367 >                        raytrans(r);
368 >                        return(1);
369 >                }
370 >                raytexture(r, m->omod);
371 >                flipsurface(r);                 /* reorient if backvis */
372 >        } else
373 >                raytexture(r, m->omod);
374 >
375 >        nd.mp = m;
376 >        nd.pr = r;
377 >                                                /* get material color */
378 >        setcolor(nd.mcolor, m->oargs.farg[0],
379 >                        m->oargs.farg[1],
380 >                        m->oargs.farg[2]);
381 >                                                /* get specular component */
382 >        nd.rspec = m->oargs.farg[3];
383 >                                                /* compute transmittance */
384 >        if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) {
385 >                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
386 >                nd.tspec = nd.trans * m->oargs.farg[5];
387 >                dtmp = nd.trans - nd.tspec;
388 >                setcolor(nd.tdiff, dtmp, dtmp, dtmp);
389 >        } else {
390 >                nd.tspec = nd.trans = 0.0;
391 >                setcolor(nd.tdiff, 0.0, 0.0, 0.0);
392 >        }
393 >                                                /* compute reflectance */
394 >        dtmp = 1.0 - nd.trans - nd.rspec;
395 >        setcolor(nd.rdiff, dtmp, dtmp, dtmp);
396 >        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
397 >        multcolor(nd.mcolor, r->pcol);          /* modify material color */
398 >        multcolor(nd.rdiff, nd.mcolor);
399 >        multcolor(nd.tdiff, nd.mcolor);
400 >                                                /* load auxiliary files */
401 >        if (hasdata(m->otype)) {
402 >                nd.dp = getdata(m->oargs.sarg[1]);
403 >                getfunc(m, 2, 0, 0);
404 >        } else {
405 >                nd.dp = NULL;
406 >                getfunc(m, 1, 0, 0);
407 >        }
408 >                                                /* compute ambient */
409 >        if (nd.trans < 1.0-FTINY) {
410 >                ambient(ctmp, r, nd.pnorm);
411 >                scalecolor(ctmp, 1.0-nd.trans);
412                  multcolor(ctmp, nd.mcolor);     /* modified by material color */
413                  addcolor(r->rcol, ctmp);        /* add to returned color */
414          }
415 <        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
415 >        if (nd.trans > FTINY) {         /* from other side */
416                  flipsurface(r);
417 <                ambient(ctmp, r);
418 <                scalecolor(ctmp, dtmp);
417 >                vtmp[0] = -nd.pnorm[0];
418 >                vtmp[1] = -nd.pnorm[1];
419 >                vtmp[2] = -nd.pnorm[2];
420 >                ambient(ctmp, r, vtmp);
421 >                scalecolor(ctmp, nd.trans);
422                  multcolor(ctmp, nd.mcolor);
423                  addcolor(r->rcol, ctmp);
424                  flipsurface(r);
425          }
426                                                  /* add direct component */
427          direct(r, dirbrdf, &nd);
428 <                                                /* check distance */
429 <        if (transtest > bright(r->rcol))
329 <                r->rt = transdist;
428 >
429 >        return(1);
430   }
431  
432  
433 < setbrdfunc(np)                  /* set up brdf function and variables */
434 < register BRDFDAT  *np;
433 > static int
434 > setbrdfunc(                     /* set up brdf function and variables */
435 >        register BRDFDAT  *np
436 > )
437   {
438          FVECT  vec;
439  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines