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.15 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.27 by greg, Mon Oct 25 22:57:45 2010 UTC

# Line 5 | Line 5 | static const char      RCSid[] = "$Id$";
5   *  Shading for materials with arbitrary BRDF's
6   */
7  
8 < /* ====================================================================
9 < * The Radiance Software License, Version 1.0
10 < *
11 < * Copyright (c) 1990 - 2002 The Regents of the University of California,
12 < * through Lawrence Berkeley National Laboratory.   All rights reserved.
13 < *
14 < * Redistribution and use in source and binary forms, with or without
15 < * modification, are permitted provided that the following conditions
16 < * are met:
17 < *
18 < * 1. Redistributions of source code must retain the above copyright
19 < *         notice, this list of conditions and the following disclaimer.
20 < *
21 < * 2. Redistributions in binary form must reproduce the above copyright
22 < *       notice, this list of conditions and the following disclaimer in
23 < *       the documentation and/or other materials provided with the
24 < *       distribution.
25 < *
26 < * 3. The end-user documentation included with the redistribution,
27 < *           if any, must include the following acknowledgment:
28 < *             "This product includes Radiance software
29 < *                 (http://radsite.lbl.gov/)
30 < *                 developed by the Lawrence Berkeley National Laboratory
31 < *               (http://www.lbl.gov/)."
32 < *       Alternately, this acknowledgment may appear in the software itself,
33 < *       if and wherever such third-party acknowledgments normally appear.
34 < *
35 < * 4. The names "Radiance," "Lawrence Berkeley National Laboratory"
36 < *       and "The Regents of the University of California" must
37 < *       not be used to endorse or promote products derived from this
38 < *       software without prior written permission. For written
39 < *       permission, please contact [email protected].
40 < *
41 < * 5. Products derived from this software may not be called "Radiance",
42 < *       nor may "Radiance" appear in their name, without prior written
43 < *       permission of Lawrence Berkeley National Laboratory.
44 < *
45 < * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46 < * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 < * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 < * DISCLAIMED.   IN NO EVENT SHALL Lawrence Berkeley National Laboratory OR
49 < * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50 < * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51 < * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52 < * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 < * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54 < * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 < * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 < * SUCH DAMAGE.
57 < * ====================================================================
58 < *
59 < * This software consists of voluntary contributions made by many
60 < * individuals on behalf of Lawrence Berkeley National Laboratory.   For more
61 < * information on Lawrence Berkeley National Laboratory, please see
62 < * <http://www.lbl.gov/>.
63 < */
8 > #include "copyright.h"
9  
10   #include  "ray.h"
11 <
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  
18   /*
# Line 132 | Line 77 | typedef struct {
77   }  BRDFDAT;             /* BRDF material data */
78  
79  
80 + static srcdirf_t dirbrdf;
81 + static int setbrdfunc(BRDFDAT  *np);
82 +
83 +
84   static void
85 < dirbrdf(cval, np, ldir, omega)          /* compute source contribution */
86 < COLOR  cval;                    /* returned coefficient */
87 < register BRDFDAT  *np;          /* material data */
88 < FVECT  ldir;                    /* light source direction */
89 < double  omega;                  /* light source size */
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;
# Line 178 | Line 129 | double  omega;                 /* light source size */
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 194 | Line 145 | double  omega;                 /* light source size */
145                          colval(ctmp,RED) = 0.0;
146                  else
147                          colval(ctmp,RED) = funvalue(sa[6], 4, lddx);
148 <                if (!strcmp(sa[7],sa[6]))
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], 4, lddx);
# Line 215 | Line 168 | double  omega;                 /* light source size */
168                  dtmp = funvalue(sa[0], 5, vldx);
169                  setcolor(ctmp, dtmp, dtmp, dtmp);
170          }
171 <        if (errno) {
171 >        if ((errno == EDOM) | (errno == ERANGE)) {
172                  objerror(np->mp, WARNING, "compute error");
173                  return;
174          }
# Line 225 | Line 178 | double  omega;                 /* light source size */
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 234 | 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);
# Line 244 | Line 197 | double  omega;                 /* light source size */
197   }
198  
199  
200 < int
201 < m_brdf(m, r)                    /* color a ray that hit a BRDTfunc material */
202 < register OBJREC  *m;
203 < 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  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          FVECT  vtmp;
215 +        double  d;
216          register MFUNC  *mf;
217          register int  i;
218                                                  /* check arguments */
219 <        if (m->oargs.nsargs < 10 | m->oargs.nfargs < 9)
219 >        if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9))
220                  objerror(m, USER, "bad # arguments");
221          nd.mp = m;
222          nd.pr = r;
# Line 279 | Line 236 | register RAY  *r;
236          setcolor(nd.tdiff, m->oargs.farg[6],
237                          m->oargs.farg[7],
238                          m->oargs.farg[8]);
239 <                                        /* get modifiers */
239 >                                                /* get modifiers */
240          raytexture(r, m->omod);
241 <        nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
241 >        hastexture = DOT(r->pert,r->pert) > FTINY*FTINY;
242 >        if (hastexture) {                       /* perturb normal */
243 >                nd.pdot = raynormal(nd.pnorm, r);
244 >        } else {
245 >                VCOPY(nd.pnorm, r->ron);
246 >                nd.pdot = r->rod;
247 >        }
248          if (r->rod < 0.0) {                     /* orient perturbed values */
249                  nd.pdot = -nd.pdot;
250                  for (i = 0; i < 3; i++) {
# Line 300 | Line 263 | register RAY  *r;
263          mf = getfunc(m, 9, 0x3f, 0);
264                                                  /* compute transmitted ray */
265          setbrdfunc(&nd);
303        transtest = 0;
304        transdist = r->rot;
266          errno = 0;
267          setcolor(ctmp, evalue(mf->ep[3]),
268                          evalue(mf->ep[4]),
269                          evalue(mf->ep[5]));
270 <        if (errno)
270 >        if ((errno == EDOM) | (errno == ERANGE))
271                  objerror(m, WARNING, "compute error");
272 <        else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) {
273 <                if (!(r->crtype & SHADOW) &&
274 <                                DOT(r->pert,r->pert) > FTINY*FTINY) {
275 <                        for (i = 0; i < 3; i++) /* perturb direction */
315 <                                sr.rdir[i] = r->rdir[i] - .75*r->pert[i];
272 >        else if (rayorigin(&sr, TRANS, r, ctmp) == 0) {
273 >                if (!(r->crtype & SHADOW) && hastexture) {
274 >                                                /* perturb direction */
275 >                        VSUM(sr.rdir, r->rdir, r->pert, -.75);
276                          if (normalize(sr.rdir) == 0.0) {
277                                  objerror(m, WARNING, "illegal perturbation");
278                                  VCOPY(sr.rdir, r->rdir);
279                          }
280                  } else {
281                          VCOPY(sr.rdir, r->rdir);
322                        transtest = 2;
282                  }
283                  rayvalue(&sr);
284 <                multcolor(sr.rcol, ctmp);
284 >                multcolor(sr.rcol, sr.rcoef);
285                  addcolor(r->rcol, sr.rcol);
286 <                transtest *= bright(sr.rcol);
287 <                transdist = r->rot + sr.rt;
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(1);
# Line 335 | Line 296 | register RAY  *r;
296          setcolor(ctmp, evalue(mf->ep[0]),
297                          evalue(mf->ep[1]),
298                          evalue(mf->ep[2]));
299 <        if (errno)
299 >        if ((errno == EDOM) | (errno == ERANGE))
300                  objerror(m, WARNING, "compute error");
301 <        else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) {
302 <                for (i = 0; i < 3; i++)
303 <                        sr.rdir[i] = r->rdir[i] + 2.0*nd.pdot*nd.pnorm[i];
301 >        else if (rayorigin(&sr, REFLECTED, r, ctmp) == 0) {
302 >                VSUM(sr.rdir, r->rdir, nd.pnorm, 2.*nd.pdot);
303 >                checknorm(sr.rdir);
304                  rayvalue(&sr);
305 <                multcolor(sr.rcol, ctmp);
305 >                multcolor(sr.rcol, sr.rcoef);
306                  addcolor(r->rcol, sr.rcol);
307 +                if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) {
308 +                        mirtest = 2.0*bright(sr.rcol);
309 +                        mirdist = r->rot + sr.rt;
310 +                }
311          }
312                                                  /* compute ambient */
313          if (hasrefl) {
314                  if (!hitfront)
315                          flipsurface(r);
316 <                ambient(ctmp, r, nd.pnorm);
317 <                multcolor(ctmp, nd.rdiff);
316 >                copycolor(ctmp, nd.rdiff);
317 >                multambient(ctmp, r, nd.pnorm);
318                  addcolor(r->rcol, ctmp);        /* add to returned color */
319                  if (!hitfront)
320                          flipsurface(r);
# Line 360 | Line 325 | register RAY  *r;
325                  vtmp[0] = -nd.pnorm[0];
326                  vtmp[1] = -nd.pnorm[1];
327                  vtmp[2] = -nd.pnorm[2];
328 <                ambient(ctmp, r, vtmp);
329 <                multcolor(ctmp, nd.tdiff);
328 >                copycolor(ctmp, nd.tdiff);
329 >                multambient(ctmp, r, vtmp);
330                  addcolor(r->rcol, ctmp);
331                  if (hitfront)
332                          flipsurface(r);
333          }
334          if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0')
335                  direct(r, dirbrdf, &nd);        /* add direct component */
336 <                                                /* check distance */
337 <        if (transtest > bright(r->rcol))
336 >
337 >        d = bright(r->rcol);                    /* set effective distance */
338 >        if (transtest > d)
339                  r->rt = transdist;
340 +        else if (mirtest > d)
341 +                r->rt = mirdist;
342  
343          return(1);
344   }
345  
346  
347  
348 < int
349 < m_brdf2(m, r)                   /* color a ray that hit a BRDF material */
350 < register OBJREC  *m;
351 < register RAY  *r;
348 > extern int
349 > m_brdf2(                        /* color a ray that hit a BRDF material */
350 >        register OBJREC  *m,
351 >        register RAY  *r
352 > )
353   {
354          BRDFDAT  nd;
355          COLOR  ctmp;
# Line 390 | Line 359 | register RAY  *r;
359          if (r->crtype & SHADOW)
360                  return(1);
361                                                  /* check arguments */
362 <        if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs <
363 <                        (m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4))
362 >        if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs <
363 >                        ((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4)))
364                  objerror(m, USER, "bad # arguments");
365 +                                                /* check for back side */
366 +        if (r->rod < 0.0) {
367 +                if (!backvis && m->otype != MAT_TFUNC
368 +                                && m->otype != MAT_TDATA) {
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 */
# Line 402 | Line 383 | register RAY  *r;
383                                                  /* get specular component */
384          nd.rspec = m->oargs.farg[3];
385                                                  /* compute transmittance */
386 <        if (m->otype == MAT_TFUNC | m->otype == MAT_TDATA) {
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;
# Line 414 | Line 395 | register RAY  *r;
395                                                  /* compute reflectance */
396          dtmp = 1.0 - nd.trans - nd.rspec;
397          setcolor(nd.rdiff, dtmp, dtmp, dtmp);
417                                                /* check for back side */
418        if (r->rod < 0.0) {
419                if (!backvis && m->otype != MAT_TFUNC
420                                && m->otype != MAT_TDATA) {
421                        raytrans(r);
422                        return(1);
423                }
424                flipsurface(r);                 /* reorient if backvis */
425        }
426                                                /* get modifiers */
427        raytexture(r, m->omod);
398          nd.pdot = raynormal(nd.pnorm, r);       /* perturb normal */
399          multcolor(nd.mcolor, r->pcol);          /* modify material color */
400          multcolor(nd.rdiff, nd.mcolor);
# Line 439 | Line 409 | register RAY  *r;
409          }
410                                                  /* compute ambient */
411          if (nd.trans < 1.0-FTINY) {
412 <                ambient(ctmp, r, nd.pnorm);
412 >                copycolor(ctmp, nd.mcolor);     /* modified by material color */
413                  scalecolor(ctmp, 1.0-nd.trans);
414 <                multcolor(ctmp, nd.mcolor);     /* modified by material color */
414 >                multambient(ctmp, r, nd.pnorm);
415                  addcolor(r->rcol, ctmp);        /* add to returned color */
416          }
417          if (nd.trans > FTINY) {         /* from other side */
# Line 449 | Line 419 | register RAY  *r;
419                  vtmp[0] = -nd.pnorm[0];
420                  vtmp[1] = -nd.pnorm[1];
421                  vtmp[2] = -nd.pnorm[2];
422 <                ambient(ctmp, r, vtmp);
422 >                copycolor(ctmp, nd.mcolor);
423                  scalecolor(ctmp, nd.trans);
424 <                multcolor(ctmp, nd.mcolor);
424 >                multambient(ctmp, r, vtmp);
425                  addcolor(r->rcol, ctmp);
426                  flipsurface(r);
427          }
# Line 462 | Line 432 | register RAY  *r;
432   }
433  
434  
435 < int
436 < setbrdfunc(np)                  /* set up brdf function and variables */
437 < register BRDFDAT  *np;
435 > static int
436 > setbrdfunc(                     /* set up brdf function and variables */
437 >        register BRDFDAT  *np
438 > )
439   {
440          FVECT  vec;
441  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines