16 |
|
|
17 |
|
#include "func.h" |
18 |
|
|
19 |
+ |
extern int backvis; /* back faces visible? */ |
20 |
+ |
|
21 |
|
/* |
22 |
|
* Arguments to this material include the color and specularity. |
23 |
|
* String arguments include the reflection function and files. |
24 |
|
* The BRDF is currently used just for the specular component to light |
25 |
|
* sources. Reflectance values or data coordinates are functions |
26 |
< |
* of the direction to the light source. |
26 |
> |
* of the direction to the light source. (Data modification functions |
27 |
> |
* are passed the source direction as args 2-4.) |
28 |
|
* We orient the surface towards the incoming ray, so a single |
29 |
|
* surface can be used to represent an infinitely thin object. |
30 |
|
* |
90 |
|
double dtmp; |
91 |
|
COLOR ctmp; |
92 |
|
FVECT ldx; |
93 |
< |
double lddx[3], pt[MAXDIM]; |
93 |
> |
static double vldx[5], pt[MAXDIM]; |
94 |
|
register char **sa; |
95 |
|
register int i; |
96 |
+ |
#define lddx (vldx+1) |
97 |
|
|
98 |
|
setcolor(cval, 0.0, 0.0, 0.0); |
99 |
|
|
134 |
|
multv3(ldx, ldir, funcxf.xfm); |
135 |
|
for (i = 0; i < 3; i++) |
136 |
|
lddx[i] = ldx[i]/funcxf.sca; |
137 |
+ |
lddx[3] = omega; |
138 |
|
/* compute BRTDF */ |
139 |
|
if (np->mp->otype == MAT_BRTDF) { |
140 |
|
if (sa[6][0] == '0') /* special case */ |
141 |
|
colval(ctmp,RED) = 0.0; |
142 |
|
else |
143 |
< |
colval(ctmp,RED) = funvalue(sa[6], 3, lddx); |
143 |
> |
colval(ctmp,RED) = funvalue(sa[6], 4, lddx); |
144 |
|
if (!strcmp(sa[7],sa[6])) |
145 |
|
colval(ctmp,GRN) = colval(ctmp,RED); |
146 |
|
else |
147 |
< |
colval(ctmp,GRN) = funvalue(sa[7], 3, lddx); |
147 |
> |
colval(ctmp,GRN) = funvalue(sa[7], 4, lddx); |
148 |
|
if (!strcmp(sa[8],sa[6])) |
149 |
|
colval(ctmp,BLU) = colval(ctmp,RED); |
150 |
|
else if (!strcmp(sa[8],sa[7])) |
151 |
|
colval(ctmp,BLU) = colval(ctmp,GRN); |
152 |
|
else |
153 |
< |
colval(ctmp,BLU) = funvalue(sa[8], 3, lddx); |
153 |
> |
colval(ctmp,BLU) = funvalue(sa[8], 4, lddx); |
154 |
|
dtmp = bright(ctmp); |
155 |
|
} else if (np->dp == NULL) { |
156 |
< |
dtmp = funvalue(sa[0], 3, lddx); |
156 |
> |
dtmp = funvalue(sa[0], 4, lddx); |
157 |
|
setcolor(ctmp, dtmp, dtmp, dtmp); |
158 |
|
} else { |
159 |
|
for (i = 0; i < np->dp->nd; i++) |
160 |
< |
pt[i] = funvalue(sa[3+i], 3, lddx); |
161 |
< |
dtmp = datavalue(np->dp, pt); |
162 |
< |
dtmp = funvalue(sa[0], 1, &dtmp); |
160 |
> |
pt[i] = funvalue(sa[3+i], 4, lddx); |
161 |
> |
vldx[0] = datavalue(np->dp, pt); |
162 |
> |
dtmp = funvalue(sa[0], 5, vldx); |
163 |
|
setcolor(ctmp, dtmp, dtmp, dtmp); |
164 |
|
} |
165 |
|
if (errno) { |
187 |
|
scalecolor(ctmp, dtmp); |
188 |
|
addcolor(cval, ctmp); |
189 |
|
} |
190 |
+ |
#undef lddx |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
< |
m_brdf(m, r) /* color a ray which hit a BRDTF material */ |
194 |
> |
m_brdf(m, r) /* color a ray which hit a BRDTfunc material */ |
195 |
|
register OBJREC *m; |
196 |
|
register RAY *r; |
197 |
|
{ |
200 |
|
double transtest, transdist; |
201 |
|
int hasrefl, hastrans; |
202 |
|
COLOR ctmp; |
203 |
< |
double dtmp; |
203 |
> |
FVECT vtmp; |
204 |
|
register MFUNC *mf; |
205 |
|
register int i; |
206 |
|
/* check arguments */ |
245 |
|
/* compute transmitted ray */ |
246 |
|
setbrdfunc(&nd); |
247 |
|
transtest = 0; |
248 |
+ |
transdist = r->rot; |
249 |
|
errno = 0; |
250 |
|
setcolor(ctmp, evalue(mf->ep[3]), |
251 |
|
evalue(mf->ep[4]), |
272 |
|
transdist = r->rot + sr.rt; |
273 |
|
} |
274 |
|
if (r->crtype & SHADOW) /* the rest is shadow */ |
275 |
< |
return; |
275 |
> |
return(1); |
276 |
|
/* compute reflected ray */ |
277 |
|
setbrdfunc(&nd); |
278 |
|
errno = 0; |
290 |
|
} |
291 |
|
/* compute ambient */ |
292 |
|
if (hasrefl) { |
293 |
< |
if (nd.pdot < 0.0) |
293 |
> |
if (nd.pdot < 0.0) { |
294 |
|
flipsurface(r); |
295 |
< |
ambient(ctmp, r); |
295 |
> |
vtmp[0] = -nd.pnorm[0]; |
296 |
> |
vtmp[1] = -nd.pnorm[1]; |
297 |
> |
vtmp[2] = -nd.pnorm[2]; |
298 |
> |
} else |
299 |
> |
VCOPY(vtmp, nd.pnorm); |
300 |
> |
ambient(ctmp, r, vtmp); |
301 |
|
multcolor(ctmp, nd.rdiff); |
302 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
303 |
|
if (nd.pdot < 0.0) |
304 |
|
flipsurface(r); |
305 |
|
} |
306 |
|
if (hastrans) { /* from other side */ |
307 |
< |
if (nd.pdot > 0.0) |
307 |
> |
if (nd.pdot > 0.0) { |
308 |
|
flipsurface(r); |
309 |
< |
ambient(ctmp, r); |
309 |
> |
vtmp[0] = -nd.pnorm[0]; |
310 |
> |
vtmp[1] = -nd.pnorm[1]; |
311 |
> |
vtmp[2] = -nd.pnorm[2]; |
312 |
> |
} else |
313 |
> |
VCOPY(vtmp, nd.pnorm); |
314 |
> |
ambient(ctmp, r, vtmp); |
315 |
|
multcolor(ctmp, nd.tdiff); |
316 |
|
addcolor(r->rcol, ctmp); |
317 |
|
if (nd.pdot > 0.0) |
322 |
|
/* check distance */ |
323 |
|
if (transtest > bright(r->rcol)) |
324 |
|
r->rt = transdist; |
325 |
+ |
|
326 |
+ |
return(1); |
327 |
|
} |
328 |
|
|
329 |
|
|
334 |
|
{ |
335 |
|
BRDFDAT nd; |
336 |
|
COLOR ctmp; |
337 |
+ |
FVECT vtmp; |
338 |
|
double dtmp; |
339 |
|
/* always a shadow */ |
340 |
|
if (r->crtype & SHADOW) |
341 |
< |
return; |
341 |
> |
return(1); |
342 |
|
/* check arguments */ |
343 |
|
if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs < |
344 |
|
(m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4)) |
364 |
|
/* compute reflectance */ |
365 |
|
dtmp = 1.0 - nd.trans - nd.rspec; |
366 |
|
setcolor(nd.rdiff, dtmp, dtmp, dtmp); |
367 |
< |
/* fix orientation */ |
368 |
< |
if (r->rod < 0.0) |
369 |
< |
flipsurface(r); |
367 |
> |
/* check for back side */ |
368 |
> |
if (r->rod < 0.0) { |
369 |
> |
if (!backvis && m->otype != MAT_TFUNC |
370 |
> |
&& m->otype != MAT_TDATA) { |
371 |
> |
raytrans(r); |
372 |
> |
return(1); |
373 |
> |
} |
374 |
> |
flipsurface(r); /* reorient if backvis */ |
375 |
> |
} |
376 |
|
/* get modifiers */ |
377 |
|
raytexture(r, m->omod); |
378 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
389 |
|
} |
390 |
|
/* compute ambient */ |
391 |
|
if (nd.trans < 1.0-FTINY) { |
392 |
< |
ambient(ctmp, r); |
392 |
> |
ambient(ctmp, r, nd.pnorm); |
393 |
|
scalecolor(ctmp, 1.0-nd.trans); |
394 |
|
multcolor(ctmp, nd.mcolor); /* modified by material color */ |
395 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
396 |
|
} |
397 |
|
if (nd.trans > FTINY) { /* from other side */ |
398 |
|
flipsurface(r); |
399 |
< |
ambient(ctmp, r); |
399 |
> |
vtmp[0] = -nd.pnorm[0]; |
400 |
> |
vtmp[1] = -nd.pnorm[1]; |
401 |
> |
vtmp[2] = -nd.pnorm[2]; |
402 |
> |
ambient(ctmp, r, vtmp); |
403 |
|
scalecolor(ctmp, nd.trans); |
404 |
|
multcolor(ctmp, nd.mcolor); |
405 |
|
addcolor(r->rcol, ctmp); |
407 |
|
} |
408 |
|
/* add direct component */ |
409 |
|
direct(r, dirbrdf, &nd); |
410 |
+ |
|
411 |
+ |
return(1); |
412 |
|
} |
413 |
|
|
414 |
|
|