1 |
< |
/* Copyright (c) 1990 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
66 |
|
RAY *pr; /* intersected ray */ |
67 |
|
DATARRAY *dp; /* data array for PDATA, MDATA or TDATA */ |
68 |
|
COLOR mcolor; /* color of this material */ |
69 |
– |
COLOR scolor; /* color of specular reflection */ |
69 |
|
double rspec; /* specular reflection */ |
70 |
|
double rdiff; /* diffuse reflection */ |
71 |
|
double trans; /* transmissivity */ |
132 |
|
/* compute BRTDF */ |
133 |
|
if (np->mp->otype == MAT_BRTDF) { |
134 |
|
colval(ctmp,RED) = funvalue(sa[6], 3, ldx); |
135 |
< |
if (sa[7] == sa[6]) |
135 |
> |
if (!strcmp(sa[7],sa[6])) |
136 |
|
colval(ctmp,GRN) = colval(ctmp,RED); |
137 |
|
else |
138 |
|
colval(ctmp,GRN) = funvalue(sa[7], 3, ldx); |
139 |
< |
if (sa[8] == sa[6]) |
139 |
> |
if (!strcmp(sa[8],sa[6])) |
140 |
|
colval(ctmp,BLU) = colval(ctmp,RED); |
141 |
< |
else if (sa[8] == sa[7]) |
141 |
> |
else if (!strcmp(sa[8],sa[7])) |
142 |
|
colval(ctmp,BLU) = colval(ctmp,GRN); |
143 |
|
else |
144 |
|
colval(ctmp,BLU) = funvalue(sa[8], 3, ldx); |
161 |
|
/* |
162 |
|
* Compute reflected non-diffuse component. |
163 |
|
*/ |
164 |
< |
multcolor(ctmp, np->scolor); |
165 |
< |
dtmp = ldot * omega; |
164 |
> |
if (np->mp->otype == MAT_MFUNC || np->mp->otype == MAT_MDATA) |
165 |
> |
multcolor(ctmp, np->mcolor); |
166 |
> |
dtmp = ldot * omega * np->rspec; |
167 |
|
scalecolor(ctmp, dtmp); |
168 |
|
addcolor(cval, ctmp); |
169 |
|
} else { |
170 |
|
/* |
171 |
|
* Compute transmitted non-diffuse component. |
172 |
|
*/ |
173 |
+ |
if (np->mp->otype == MAT_TFUNC || np->mp->otype == MAT_TDATA) |
174 |
+ |
multcolor(ctmp, np->mcolor); |
175 |
|
dtmp = -ldot * omega * np->tspec; |
176 |
|
scalecolor(ctmp, dtmp); |
177 |
|
addcolor(cval, ctmp); |
189 |
|
{ |
190 |
|
int minsa, minfa; |
191 |
|
BRDFDAT nd; |
192 |
+ |
double transtest, transdist; |
193 |
|
COLOR ctmp; |
194 |
|
double dtmp; |
195 |
|
FVECT vec; |
238 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
239 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
240 |
|
r->rt = r->rot; /* default ray length */ |
241 |
+ |
transtest = 0; |
242 |
|
/* load auxiliary files */ |
243 |
|
if (m->otype == MAT_PDATA || m->otype == MAT_MDATA |
244 |
|
|| m->otype == MAT_TDATA) { |
281 |
|
objerror(m, WARNING, "compute error"); |
282 |
|
else if ((dtmp = bright(ctmp)) > FTINY && |
283 |
|
rayorigin(&sr, r, TRANS, dtmp) == 0) { |
284 |
< |
VCOPY(sr.rdir, r->rdir); |
284 |
> |
if (DOT(r->pert,r->pert) > FTINY*FTINY) { |
285 |
> |
for (i = 0; i < 3; i++) /* perturb direction */ |
286 |
> |
sr.rdir[i] = r->rdir[i] - |
287 |
> |
.75*r->pert[i]; |
288 |
> |
normalize(sr.rdir); |
289 |
> |
} else |
290 |
> |
transtest = 2; |
291 |
|
rayvalue(&sr); |
292 |
|
multcolor(sr.rcol, ctmp); |
293 |
|
addcolor(r->rcol, sr.rcol); |
294 |
< |
if (dtmp > .5) |
295 |
< |
r->rt = r->rot + sr.rt; |
294 |
> |
transtest *= bright(sr.rcol); |
295 |
> |
transdist = r->rot + sr.rt; |
296 |
|
} |
297 |
|
} |
298 |
|
if (r->crtype & SHADOW) /* the rest is shadow */ |
299 |
|
return; |
290 |
– |
if (nd.rspec > FTINY) { /* has specular component */ |
291 |
– |
/* compute specular color */ |
292 |
– |
if (m->otype == MAT_MFUNC || m->otype == MAT_MDATA) |
293 |
– |
copycolor(nd.scolor, nd.mcolor); |
294 |
– |
else |
295 |
– |
setcolor(nd.scolor, 1.0, 1.0, 1.0); |
296 |
– |
scalecolor(nd.scolor, nd.rspec); |
300 |
|
/* compute reflected ray */ |
301 |
< |
if (m->otype == MAT_BRTDF) { |
302 |
< |
RAY sr; |
303 |
< |
errno = 0; |
304 |
< |
setcolor(ctmp, varvalue(m->oargs.sarg[3]), |
305 |
< |
varvalue(m->oargs.sarg[4]), |
306 |
< |
varvalue(m->oargs.sarg[5])); |
307 |
< |
scalecolor(ctmp, nd.rspec); |
308 |
< |
if (errno) |
309 |
< |
objerror(m, WARNING, "compute error"); |
310 |
< |
else if ((dtmp = bright(ctmp)) > FTINY && |
301 |
> |
if (m->otype == MAT_BRTDF && nd.rspec > FTINY) { |
302 |
> |
RAY sr; |
303 |
> |
errno = 0; |
304 |
> |
setcolor(ctmp, varvalue(m->oargs.sarg[3]), |
305 |
> |
varvalue(m->oargs.sarg[4]), |
306 |
> |
varvalue(m->oargs.sarg[5])); |
307 |
> |
scalecolor(ctmp, nd.rspec); |
308 |
> |
if (errno) |
309 |
> |
objerror(m, WARNING, "compute error"); |
310 |
> |
else if ((dtmp = bright(ctmp)) > FTINY && |
311 |
|
rayorigin(&sr, r, REFLECTED, dtmp) == 0) { |
312 |
< |
for (i = 0; i < 3; i++) |
313 |
< |
sr.rdir[i] = r->rdir[i] + |
312 |
> |
for (i = 0; i < 3; i++) |
313 |
> |
sr.rdir[i] = r->rdir[i] + |
314 |
|
2.0*nd.pdot*nd.pnorm[i]; |
315 |
< |
rayvalue(&sr); |
316 |
< |
multcolor(sr.rcol, ctmp); |
317 |
< |
addcolor(r->rcol, sr.rcol); |
315 |
< |
} |
315 |
> |
rayvalue(&sr); |
316 |
> |
multcolor(sr.rcol, ctmp); |
317 |
> |
addcolor(r->rcol, sr.rcol); |
318 |
|
} |
319 |
|
} |
320 |
|
/* compute ambient */ |
340 |
|
} |
341 |
|
/* add direct component */ |
342 |
|
direct(r, dirbrdf, &nd); |
343 |
+ |
/* check distance */ |
344 |
+ |
if (transtest > bright(r->rcol)) |
345 |
+ |
r->rt = transdist; |
346 |
|
} |