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 |
|
/* |
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; |
166 |
|
dtmp = funvalue(sa[0], 5, vldx); |
167 |
|
setcolor(ctmp, dtmp, dtmp, dtmp); |
168 |
|
} |
169 |
< |
if (errno) { |
169 |
> |
if (errno == EDOM || errno == ERANGE) { |
170 |
|
objerror(np->mp, WARNING, "compute error"); |
171 |
|
return; |
172 |
|
} |
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); |
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); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
< |
int |
199 |
< |
m_brdf(m, r) /* color a ray that hit a BRDTfunc material */ |
200 |
< |
register OBJREC *m; |
201 |
< |
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 hitfront = 1; |
205 |
|
BRDFDAT nd; |
211 |
|
register MFUNC *mf; |
212 |
|
register int i; |
213 |
|
/* check arguments */ |
214 |
< |
if (m->oargs.nsargs < 10 | m->oargs.nfargs < 9) |
214 |
> |
if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9)) |
215 |
|
objerror(m, USER, "bad # arguments"); |
216 |
|
nd.mp = m; |
217 |
|
nd.pr = r; |
231 |
|
setcolor(nd.tdiff, m->oargs.farg[6], |
232 |
|
m->oargs.farg[7], |
233 |
|
m->oargs.farg[8]); |
234 |
< |
/* get modifiers */ |
234 |
> |
/* get modifiers */ |
235 |
|
raytexture(r, m->omod); |
236 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
237 |
|
if (r->rod < 0.0) { /* orient perturbed values */ |
258 |
|
setcolor(ctmp, evalue(mf->ep[3]), |
259 |
|
evalue(mf->ep[4]), |
260 |
|
evalue(mf->ep[5])); |
261 |
< |
if (errno) |
261 |
> |
if (errno == EDOM || errno == ERANGE) |
262 |
|
objerror(m, WARNING, "compute error"); |
263 |
|
else if (rayorigin(&sr, r, TRANS, bright(ctmp)) == 0) { |
264 |
|
if (!(r->crtype & SHADOW) && |
287 |
|
setcolor(ctmp, evalue(mf->ep[0]), |
288 |
|
evalue(mf->ep[1]), |
289 |
|
evalue(mf->ep[2])); |
290 |
< |
if (errno) |
290 |
> |
if (errno == EDOM || errno == ERANGE) |
291 |
|
objerror(m, WARNING, "compute error"); |
292 |
|
else if (rayorigin(&sr, r, REFLECTED, bright(ctmp)) == 0) { |
293 |
|
for (i = 0; i < 3; i++) |
329 |
|
|
330 |
|
|
331 |
|
|
332 |
< |
int |
333 |
< |
m_brdf2(m, r) /* color a ray that hit a BRDF material */ |
334 |
< |
register OBJREC *m; |
335 |
< |
register RAY *r; |
332 |
> |
extern int |
333 |
> |
m_brdf2( /* color a ray that hit a BRDF material */ |
334 |
> |
register OBJREC *m, |
335 |
> |
register RAY *r |
336 |
> |
) |
337 |
|
{ |
338 |
|
BRDFDAT nd; |
339 |
|
COLOR ctmp; |
343 |
|
if (r->crtype & SHADOW) |
344 |
|
return(1); |
345 |
|
/* check arguments */ |
346 |
< |
if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs < |
347 |
< |
(m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4)) |
346 |
> |
if ((m->oargs.nsargs < (hasdata(m->otype)?4:2)) | (m->oargs.nfargs < |
347 |
> |
((m->otype==MAT_TFUNC)|(m->otype==MAT_TDATA)?6:4))) |
348 |
|
objerror(m, USER, "bad # arguments"); |
349 |
+ |
/* check for back side */ |
350 |
+ |
if (r->rod < 0.0) { |
351 |
+ |
if (!backvis && m->otype != MAT_TFUNC |
352 |
+ |
&& m->otype != MAT_TDATA) { |
353 |
+ |
raytrans(r); |
354 |
+ |
return(1); |
355 |
+ |
} |
356 |
+ |
raytexture(r, m->omod); |
357 |
+ |
flipsurface(r); /* reorient if backvis */ |
358 |
+ |
} else |
359 |
+ |
raytexture(r, m->omod); |
360 |
+ |
|
361 |
|
nd.mp = m; |
362 |
|
nd.pr = r; |
363 |
|
/* get material color */ |
367 |
|
/* get specular component */ |
368 |
|
nd.rspec = m->oargs.farg[3]; |
369 |
|
/* compute transmittance */ |
370 |
< |
if (m->otype == MAT_TFUNC | m->otype == MAT_TDATA) { |
370 |
> |
if ((m->otype == MAT_TFUNC) | (m->otype == MAT_TDATA)) { |
371 |
|
nd.trans = m->oargs.farg[4]*(1.0 - nd.rspec); |
372 |
|
nd.tspec = nd.trans * m->oargs.farg[5]; |
373 |
|
dtmp = nd.trans - nd.tspec; |
379 |
|
/* compute reflectance */ |
380 |
|
dtmp = 1.0 - nd.trans - nd.rspec; |
381 |
|
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); |
382 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
383 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
384 |
|
multcolor(nd.rdiff, nd.mcolor); |
416 |
|
} |
417 |
|
|
418 |
|
|
419 |
< |
int |
420 |
< |
setbrdfunc(np) /* set up brdf function and variables */ |
421 |
< |
register BRDFDAT *np; |
419 |
> |
static int |
420 |
> |
setbrdfunc( /* set up brdf function and variables */ |
421 |
> |
register BRDFDAT *np |
422 |
> |
) |
423 |
|
{ |
424 |
|
FVECT vec; |
425 |
|
|