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 |
|
|
200 |
|
double transtest, transdist; |
201 |
|
int hasrefl, hastrans; |
202 |
|
COLOR ctmp; |
197 |
– |
double dtmp; |
203 |
|
register MFUNC *mf; |
204 |
|
register int i; |
205 |
|
/* check arguments */ |
244 |
|
/* compute transmitted ray */ |
245 |
|
setbrdfunc(&nd); |
246 |
|
transtest = 0; |
247 |
+ |
transdist = r->rot; |
248 |
|
errno = 0; |
249 |
|
setcolor(ctmp, evalue(mf->ep[3]), |
250 |
|
evalue(mf->ep[4]), |
271 |
|
transdist = r->rot + sr.rt; |
272 |
|
} |
273 |
|
if (r->crtype & SHADOW) /* the rest is shadow */ |
274 |
< |
return; |
274 |
> |
return(1); |
275 |
|
/* compute reflected ray */ |
276 |
|
setbrdfunc(&nd); |
277 |
|
errno = 0; |
311 |
|
/* check distance */ |
312 |
|
if (transtest > bright(r->rcol)) |
313 |
|
r->rt = transdist; |
314 |
+ |
|
315 |
+ |
return(1); |
316 |
|
} |
317 |
|
|
318 |
|
|
326 |
|
double dtmp; |
327 |
|
/* always a shadow */ |
328 |
|
if (r->crtype & SHADOW) |
329 |
< |
return; |
329 |
> |
return(1); |
330 |
|
/* check arguments */ |
331 |
|
if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs < |
332 |
|
(m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4)) |
352 |
|
/* compute reflectance */ |
353 |
|
dtmp = 1.0 - nd.trans - nd.rspec; |
354 |
|
setcolor(nd.rdiff, dtmp, dtmp, dtmp); |
355 |
< |
/* fix orientation */ |
356 |
< |
if (r->rod < 0.0) |
357 |
< |
flipsurface(r); |
355 |
> |
/* check for back side */ |
356 |
> |
if (r->rod < 0.0) { |
357 |
> |
if (!backvis && m->otype != MAT_TFUNC |
358 |
> |
&& m->otype != MAT_TDATA) { |
359 |
> |
raytrans(r); |
360 |
> |
return(1); |
361 |
> |
} |
362 |
> |
flipsurface(r); /* reorient if backvis */ |
363 |
> |
} |
364 |
|
/* get modifiers */ |
365 |
|
raytexture(r, m->omod); |
366 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
392 |
|
} |
393 |
|
/* add direct component */ |
394 |
|
direct(r, dirbrdf, &nd); |
395 |
+ |
|
396 |
+ |
return(1); |
397 |
|
} |
398 |
|
|
399 |
|
|