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.4 by greg, Wed Oct 14 12:30:54 1992 UTC vs.
Revision 2.38 by greg, Wed Feb 13 02:38:26 2019 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 <
15 > #include  "rtotypes.h"
16   #include  "func.h"
17 + #include  "pmapmat.h"
18  
19   /*
20   *      Arguments to this material include the color and specularity.
21   *  String arguments include the reflection function and files.
22   *  The BRDF is currently used just for the specular component to light
23   *  sources.  Reflectance values or data coordinates are functions
24 < *  of the direction to the light source.
24 > *  of the direction to the light source.  (Data modification functions
25 > *  are passed the source direction as args 2-4.)
26   *      We orient the surface towards the incoming ray, so a single
27   *  surface can be used to represent an infinitely thin object.
28   *
# Line 38 | Line 39 | static char SCCSid[] = "$SunId$ LBL";
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 51 | Line 52 | static char SCCSid[] = "$SunId$ LBL";
52   *              rbrtd   gbrtd   bbrtd
53   *              funcfile        transform
54   *      0
55 < *      6+      red     grn     blu     rspec   trans   tspec   A7 ..
55 > *      9+      rdf     gdf     bdf
56 > *              rdb     gdb     bdb
57 > *              rdt     gdt     bdt     A10 ..
58   *
59   *      In addition to the normal variables available to functions,
60   *  we define the following:
61   *              NxP, NyP, NzP -         perturbed surface normal
62   *              RdotP -                 perturbed ray dot product
63 < *              CrP, CgP, CbP -         perturbed material color
63 > *              CrP, CgP, CbP -         perturbed material color (or pattern)
64   */
65  
66   typedef struct {
67          OBJREC  *mp;            /* material pointer */
68          RAY  *pr;               /* intersected ray */
69          DATARRAY  *dp;          /* data array for PDATA, MDATA or TDATA */
70 <        COLOR  mcolor;          /* color of this material */
71 <        double  rspec;          /* specular reflection */
72 <        double  rdiff;          /* diffuse reflection */
73 <        double  trans;          /* transmissivity */
74 <        double  tspec;          /* specular transmission */
75 <        double  tdiff;          /* diffuse transmission */
70 >        COLOR  mcolor;          /* material (or pattern) color */
71 >        COLOR  rdiff;           /* diffuse reflection */
72 >        COLOR  tdiff;           /* diffuse transmission */
73 >        double  rspec;          /* specular reflectance (1 for BRDTF) */
74 >        double  trans;          /* transmissivity (.5 for BRDTF) */
75 >        double  tspec;          /* specular transmittance (1 for BRDTF) */
76          FVECT  pnorm;           /* perturbed surface normal */
77          double  pdot;           /* perturbed dot product */
78   }  BRDFDAT;             /* BRDF material data */
79  
80  
81 < dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
82 < COLOR  cval;                    /* returned coefficient */
83 < register BRDFDAT  *np;          /* material data */
84 < FVECT  ldir;                    /* light source direction */
85 < double  omega;                  /* light source size */
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 +        BRDFDAT *np = nnp;
93          double  ldot;
94          double  dtmp;
95          COLOR  ctmp;
96          FVECT  ldx;
97 <        double  lddx[3], pt[MAXDIM];
98 <        register char   **sa;
99 <        register int    i;
97 >        static double  vldx[5], pt[MAXDIM];
98 >        char    **sa;
99 >        int     i;
100 > #define lddx (vldx+1)
101  
102          setcolor(cval, 0.0, 0.0, 0.0);
103          
# Line 95 | 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 <        }
112 <        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 */
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);
136          sa = np->mp->oargs.sarg;
# Line 128 | Line 139 | double  omega;                 /* light source size */
139          multv3(ldx, ldir, funcxf.xfm);
140          for (i = 0; i < 3; i++)
141                  lddx[i] = ldx[i]/funcxf.sca;
142 +        lddx[3] = omega;
143                                          /* compute BRTDF */
144          if (np->mp->otype == MAT_BRTDF) {
145 <                colval(ctmp,RED) = funvalue(sa[6], 3, lddx);
146 <                if (!strcmp(sa[7],sa[6]))
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' && !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], 3, lddx);
155 <                if (!strcmp(sa[8],sa[6]))
154 >                        colval(ctmp,GRN) = funvalue(sa[7], 4, lddx);
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);
161                  else
162 <                        colval(ctmp,BLU) = funvalue(sa[8], 3, lddx);
162 >                        colval(ctmp,BLU) = funvalue(sa[8], 4, lddx);
163                  dtmp = bright(ctmp);
164          } else if (np->dp == NULL) {
165 <                dtmp = funvalue(sa[0], 3, lddx);
165 >                dtmp = funvalue(sa[0], 4, lddx);
166                  setcolor(ctmp, dtmp, dtmp, dtmp);
167          } else {
168                  for (i = 0; i < np->dp->nd; i++)
169 <                        pt[i] = funvalue(sa[3+i], 3, lddx);
170 <                dtmp = datavalue(np->dp, pt);
171 <                dtmp = funvalue(sa[0], 1, &dtmp);
169 >                        pt[i] = funvalue(sa[3+i], 4, lddx);
170 >                vldx[0] = datavalue(np->dp, pt);
171 >                dtmp = funvalue(sa[0], 5, vldx);
172                  setcolor(ctmp, dtmp, dtmp, dtmp);
173          }
174 <        if (errno) {
174 >        if ((errno == EDOM) | (errno == ERANGE)) {
175                  objerror(np->mp, WARNING, "compute error");
176                  return;
177          }
# Line 162 | Line 181 | double  omega;                 /* light source size */
181                  /*
182                   *  Compute reflected non-diffuse component.
183                   */
184 <                if (np->mp->otype == MAT_MFUNC || np->mp->otype == MAT_MDATA)
184 >                if ((np->mp->otype == MAT_MFUNC) | (np->mp->otype == MAT_MDATA))
185                          multcolor(ctmp, np->mcolor);
186                  dtmp = ldot * omega * np->rspec;
187                  scalecolor(ctmp, dtmp);
# Line 171 | Line 190 | double  omega;                 /* light source size */
190                  /*
191                   *  Compute transmitted non-diffuse component.
192                   */
193 <                if (np->mp->otype == MAT_TFUNC || np->mp->otype == MAT_TDATA)
193 >                if ((np->mp->otype == MAT_TFUNC) | (np->mp->otype == MAT_TDATA))
194                          multcolor(ctmp, np->mcolor);
195                  dtmp = -ldot * omega * np->tspec;
196                  scalecolor(ctmp, dtmp);
197                  addcolor(cval, ctmp);
198          }
199 + #undef lddx
200   }
201  
202  
203 < m_brdf(m, r)                    /* color a ray which hit a BRDF material */
204 < register OBJREC  *m;
205 < register RAY  *r;
203 > int
204 > m_brdf(                 /* color a ray that hit a BRDTfunc material */
205 >        OBJREC  *m,
206 >        RAY  *r
207 > )
208   {
209 <        int  minsa, minfa;
209 >        int  hitfront = 1;
210          BRDFDAT  nd;
211 <        double  transtest, transdist;
211 >        RAY  sr;
212 >        int  hasrefl, hastrans;
213 >        int  hastexture;
214          COLOR  ctmp;
215 <        double  dtmp, tspect, rspecr;
215 >        FVECT  vtmp;
216 >        double  d;
217          MFUNC  *mf;
218 <        register int  i;
218 >        int  i;
219                                                  /* check arguments */
220 <        switch (m->otype) {
196 <        case MAT_PFUNC: case MAT_MFUNC:
197 <                minsa = 2; minfa = 4; break;
198 <        case MAT_PDATA: case MAT_MDATA:
199 <                minsa = 4; minfa = 4; break;
200 <        case MAT_TFUNC:
201 <                minsa = 2; minfa = 6; break;
202 <        case MAT_TDATA:
203 <                minsa = 4; minfa = 6; break;
204 <        case MAT_BRTDF:
205 <                minsa = 10; minfa = 6; break;
206 <        }
207 <        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 */
227 <        setcolor(nd.mcolor, m->oargs.farg[0],
228 <                           m->oargs.farg[1],
229 <                           m->oargs.farg[2]);
230 <                                                /* fix orientation */
231 <        if (r->rod < 0.0)
232 <                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;
238 <                                                /* load auxiliary files */
239 <        if (hasdata(m->otype)) {
240 <                nd.dp = getdata(m->oargs.sarg[1]);
241 <                i = (1 << nd.dp->nd) - 1;
242 <                mf = getfunc(m, 2, i<<3, 0);
243 <        } else if (m->otype == MAT_BRTDF) {
244 <                nd.dp = NULL;
245 <                mf = getfunc(m, 9, 0x3f, 0);
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 <                mf = getfunc(m, 1, 0, 0);
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 <        tspect = 0.;
267 <        if (m->otype == MAT_BRTDF && nd.tspec > FTINY) {
268 <                RAY  sr;
269 <                errno = 0;
270 <                setcolor(ctmp, evalue(mf->ep[3]),
271 <                                evalue(mf->ep[4]),
272 <                                evalue(mf->ep[5]));
273 <                scalecolor(ctmp, nd.trans);
274 <                if (errno)
275 <                        objerror(m, WARNING, "compute error");
276 <                else if ((tspect = bright(ctmp)) > FTINY &&
277 <                                rayorigin(&sr, r, TRANS, tspect) == 0) {
278 <                        if (!(r->crtype & SHADOW) &&
266 <                                        DOT(r->pert,r->pert) > FTINY*FTINY) {
267 <                                for (i = 0; i < 3; i++) /* perturb direction */
268 <                                        sr.rdir[i] = r->rdir[i] -
269 <                                                        .75*r->pert[i];
270 <                                if (normalize(sr.rdir) == 0.0) {
271 <                                        objerror(m, WARNING, "illegal perturbation");
272 <                                        VCOPY(sr.rdir, r->rdir);
273 <                                }
274 <                        } 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 (hastexture && !(r->crtype & (SHADOW|AMBIENT))) {
275 >                                                /* perturb direction */
276 >                        VSUB(sr.rdir, r->rdir, r->pert);
277 >                        if (normalize(sr.rdir) == 0.0) {
278 >                                objerror(m, WARNING, "illegal perturbation");
279                                  VCOPY(sr.rdir, r->rdir);
276                                transtest = 2;
280                          }
281 <                        rayvalue(&sr);
282 <                        multcolor(sr.rcol, ctmp);
280 <                        addcolor(r->rcol, sr.rcol);
281 <                        transtest *= bright(sr.rcol);
282 <                        transdist = r->rot + sr.rt;
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 || r->crtype & (SHADOW|AMBIENT)) &&
288 +                                nd.tspec > bright(nd.tdiff) + bright(nd.rdiff))
289 +                        r->rxt = r->rot + raydistance(&sr);
290          }
291          if (r->crtype & SHADOW)                 /* the rest is shadow */
292 <                return;
292 >                return(1);
293 >
294                                                  /* compute reflected ray */
295 <        rspecr = 0.;
296 <        if (m->otype == MAT_BRTDF && nd.rspec > FTINY) {
297 <                RAY  sr;
298 <                errno = 0;
299 <                setcolor(ctmp, evalue(mf->ep[0]),
300 <                                evalue(mf->ep[1]),
301 <                                evalue(mf->ep[2]));
302 <                if (errno)
303 <                        objerror(m, WARNING, "compute error");
304 <                else if ((rspecr = bright(ctmp)) > FTINY &&
305 <                                rayorigin(&sr, r, REFLECTED, rspecr) == 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);
311 <                        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 >                copycolor(r->mcol, sr.rcol);
308 >                addcolor(r->rcol, sr.rcol);
309 >                if (r->ro != NULL && isflat(r->ro->otype) &&
310 >                                !hastexture | (r->crtype & AMBIENT))
311 >                        r->rmt = r->rot + raydistance(&sr);
312 >        }
313 >                                                /* compute ambient */
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 (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 >        return(1);
339 > }
340 >
341 >
342 >
343 > int
344 > m_brdf2(                        /* color a ray that hit a BRDF material */
345 >        OBJREC  *m,
346 >        RAY  *r
347 > )
348 > {
349 >        BRDFDAT  nd;
350 >        COLOR  ctmp;
351 >        FVECT  vtmp;
352 >        double  dtmp;
353 >                                                /* always a shadow */
354 >        if (r->crtype & SHADOW)
355 >                return(1);
356 >                                                /* check arguments */
357 >        if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
358 >                        ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
359 >                objerror(m, USER, "bad # arguments");
360 >                                                /* check for back side */
361 >        if (r->rod < 0.0) {
362 >                if (!backvis) {
363 >                        raytrans(r);
364 >                        return(1);
365                  }
366 +                raytexture(r, m->omod);
367 +                flipsurface(r);                 /* reorient if backvis */
368 +        } else
369 +                raytexture(r, m->omod);
370 +
371 +        nd.mp = m;
372 +        nd.pr = r;
373 +                                                /* get material color */
374 +        setcolor(nd.mcolor, m->oargs.farg[0],
375 +                        m->oargs.farg[1],
376 +                        m->oargs.farg[2]);
377 +                                                /* get specular component */
378 +        nd.rspec = m->oargs.farg[3];
379 +                                                /* compute transmittance */
380 +        if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) {
381 +                nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec);
382 +                nd.tspec = nd.trans * m->oargs.farg[5];
383 +                dtmp = nd.trans - nd.tspec;
384 +                setcolor(nd.tdiff, dtmp, dtmp, dtmp);
385 +        } else {
386 +                nd.tspec = nd.trans = 0.0;
387 +                setcolor(nd.tdiff, 0.0, 0.0, 0.0);
388          }
389 +                                                /* compute reflectance */
390 +        dtmp = 1.0 - nd.trans - nd.rspec;
391 +        setcolor(nd.rdiff, dtmp, dtmp, dtmp);
392 +        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
393 +        multcolor(nd.mcolor, r->pcol);          /* modify material color */
394 +        multcolor(nd.rdiff, nd.mcolor);
395 +        multcolor(nd.tdiff, nd.mcolor);
396 +                                                /* load auxiliary files */
397 +        if (hasdata(m->otype)) {
398 +                nd.dp = getdata(m->oargs.sarg[1]);
399 +                getfunc(m, 2, 0, 0);
400 +        } else {
401 +                nd.dp = NULL;
402 +                getfunc(m, 1, 0, 0);
403 +        }
404                                                  /* compute ambient */
405 <        if ((dtmp = 1.0-nd.trans-rspecr) > FTINY) {
406 <                ambient(ctmp, r);
407 <                scalecolor(ctmp, dtmp);
408 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
405 >        if (nd.trans < 1.0-FTINY) {
406 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
407 >                scalecolor(ctmp, 1.0-nd.trans);
408 >                multambient(ctmp, r, nd.pnorm);
409                  addcolor(r->rcol, ctmp);        /* add to returned color */
410          }
411 <        if ((dtmp = nd.trans-tspect) > FTINY) { /* from other side */
411 >        if (nd.trans > FTINY) {                 /* from other side */
412                  flipsurface(r);
413 <                ambient(ctmp, r);
414 <                scalecolor(ctmp, dtmp);
415 <                multcolor(ctmp, nd.mcolor);
413 >                vtmp[0] = -nd.pnorm[0];
414 >                vtmp[1] = -nd.pnorm[1];
415 >                vtmp[2] = -nd.pnorm[2];
416 >                copycolor(ctmp, nd.mcolor);
417 >                scalecolor(ctmp, nd.trans);
418 >                multambient(ctmp, r, vtmp);
419                  addcolor(r->rcol, ctmp);
420                  flipsurface(r);
421          }
422                                                  /* add direct component */
423          direct(r, dirbrdf, &nd);
424 <                                                /* check distance */
425 <        if (transtest > bright(r->rcol))
326 <                r->rt = transdist;
424 >
425 >        return(1);
426   }
427  
428  
429 < setbrdfunc(np)                  /* set up brdf function and variables */
430 < register BRDFDAT  *np;
429 > static int
430 > setbrdfunc(                     /* set up brdf function and variables */
431 >        BRDFDAT  *np
432 > )
433   {
434          FVECT  vec;
435  
# Line 336 | Line 437 | register BRDFDAT  *np;
437                  return(0);      /* it's OK, setfunc says we're done */
438                                  /* else (re)assign special variables */
439          multv3(vec, np->pnorm, funcxf.xfm);
440 <        varset("NxP", '=', vec[0]/funcxf.sca);
441 <        varset("NyP", '=', vec[1]/funcxf.sca);
442 <        varset("NzP", '=', vec[2]/funcxf.sca);
443 <        varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 :
440 >        varset("NxP`", '=', vec[0]/funcxf.sca);
441 >        varset("NyP`", '=', vec[1]/funcxf.sca);
442 >        varset("NzP`", '=', vec[2]/funcxf.sca);
443 >        varset("RdotP`", '=', np->pdot <= -1.0 ? -1.0 :
444                          np->pdot >= 1.0 ? 1.0 : np->pdot);
445          varset("CrP", '=', colval(np->mcolor,RED));
446          varset("CgP", '=', colval(np->mcolor,GRN));

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines