14 |
|
#include "otypes.h" |
15 |
|
#include "rtotypes.h" |
16 |
|
#include "func.h" |
17 |
+ |
#include "pmapmat.h" |
18 |
|
|
19 |
|
/* |
20 |
|
* Arguments to this material include the color and specularity. |
39 |
|
* Arguments for MAT_TFUNC are: |
40 |
|
* 2+ func funcfile transform |
41 |
|
* 0 |
42 |
< |
* 4+ red grn blu rspec trans tspec A7 .. |
42 |
> |
* 6+ red grn blu rspec trans tspec A7 .. |
43 |
|
* |
44 |
|
* Arguments for MAT_TDATA are: |
45 |
|
* 4+ func datafile funcfile v0 .. transform |
46 |
|
* 0 |
47 |
< |
* 4+ red grn blu rspec trans tspec A7 .. |
47 |
> |
* 6+ red grn blu rspec trans tspec A7 .. |
48 |
|
* |
49 |
|
* Arguments for the more general MAT_BRTDF are: |
50 |
|
* 10+ rrefl grefl brefl |
78 |
|
} BRDFDAT; /* BRDF material data */ |
79 |
|
|
80 |
|
|
81 |
< |
static srcdirf_t dirbrdf; |
81 |
< |
static int setbrdfunc(BRDFDAT *np); |
81 |
> |
static int setbrdfunc(BRDFDAT *np); |
82 |
|
|
83 |
|
|
84 |
|
static void |
89 |
|
double omega /* light source size */ |
90 |
|
) |
91 |
|
{ |
92 |
< |
register BRDFDAT *np = nnp; |
92 |
> |
BRDFDAT *np = nnp; |
93 |
|
double ldot; |
94 |
|
double dtmp; |
95 |
|
COLOR ctmp; |
96 |
|
FVECT ldx; |
97 |
|
static double vldx[5], pt[MAXDIM]; |
98 |
< |
register char **sa; |
99 |
< |
register int i; |
98 |
> |
char **sa; |
99 |
> |
int i; |
100 |
|
#define lddx (vldx+1) |
101 |
|
|
102 |
|
setcolor(cval, 0.0, 0.0, 0.0); |
128 |
|
scalecolor(ctmp, dtmp); |
129 |
|
addcolor(cval, ctmp); |
130 |
|
} |
131 |
< |
if (ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) |
131 |
> |
if ((ldot > 0.0 ? np->rspec <= FTINY : np->tspec <= FTINY) || |
132 |
> |
ambRayInPmap(np->pr)) |
133 |
|
return; /* diffuse only */ |
134 |
|
/* set up function */ |
135 |
|
setbrdfunc(np); |
142 |
|
lddx[3] = omega; |
143 |
|
/* compute BRTDF */ |
144 |
|
if (np->mp->otype == MAT_BRTDF) { |
145 |
< |
if (sa[6][0] == '0') /* special case */ |
145 |
> |
if (sa[6][0] == '0' && !sa[6][1]) /* special case */ |
146 |
|
colval(ctmp,RED) = 0.0; |
147 |
|
else |
148 |
|
colval(ctmp,RED) = funvalue(sa[6], 4, lddx); |
149 |
< |
if (sa[7][0] == '0') |
149 |
> |
if (sa[7][0] == '0' && !sa[7][1]) |
150 |
|
colval(ctmp,GRN) = 0.0; |
151 |
|
else if (!strcmp(sa[7],sa[6])) |
152 |
|
colval(ctmp,GRN) = colval(ctmp,RED); |
153 |
|
else |
154 |
|
colval(ctmp,GRN) = funvalue(sa[7], 4, lddx); |
155 |
< |
if (!strcmp(sa[8],sa[6])) |
155 |
> |
if (sa[8][0] == '0' && !sa[8][1]) |
156 |
> |
colval(ctmp,BLU) = 0.0; |
157 |
> |
else if (!strcmp(sa[8],sa[6])) |
158 |
|
colval(ctmp,BLU) = colval(ctmp,RED); |
159 |
|
else if (!strcmp(sa[8],sa[7])) |
160 |
|
colval(ctmp,BLU) = colval(ctmp,GRN); |
200 |
|
} |
201 |
|
|
202 |
|
|
203 |
< |
extern int |
203 |
> |
int |
204 |
|
m_brdf( /* color a ray that hit a BRDTfunc material */ |
205 |
< |
register OBJREC *m, |
206 |
< |
register RAY *r |
205 |
> |
OBJREC *m, |
206 |
> |
RAY *r |
207 |
|
) |
208 |
|
{ |
209 |
|
int hitfront = 1; |
210 |
|
BRDFDAT nd; |
211 |
|
RAY sr; |
209 |
– |
double mirtest=0, mirdist=0; |
210 |
– |
double transtest, transdist; |
212 |
|
int hasrefl, hastrans; |
213 |
|
int hastexture; |
214 |
|
COLOR ctmp; |
215 |
|
FVECT vtmp; |
216 |
|
double d; |
217 |
< |
register MFUNC *mf; |
218 |
< |
register int i; |
217 |
> |
MFUNC *mf; |
218 |
> |
int i; |
219 |
|
/* check arguments */ |
220 |
|
if ((m->oargs.nsargs < 10) | (m->oargs.nfargs < 9)) |
221 |
|
objerror(m, USER, "bad # arguments"); |
239 |
|
m->oargs.farg[8]); |
240 |
|
/* get modifiers */ |
241 |
|
raytexture(r, m->omod); |
242 |
< |
hastexture = DOT(r->pert,r->pert) > FTINY*FTINY; |
242 |
> |
hastexture = (DOT(r->pert,r->pert) > FTINY*FTINY); |
243 |
|
if (hastexture) { /* perturb normal */ |
244 |
|
nd.pdot = raynormal(nd.pnorm, r); |
245 |
|
} else { |
257 |
|
copycolor(nd.mcolor, r->pcol); /* get pattern color */ |
258 |
|
multcolor(nd.rdiff, nd.mcolor); /* modify diffuse values */ |
259 |
|
multcolor(nd.tdiff, nd.mcolor); |
260 |
< |
hasrefl = bright(nd.rdiff) > FTINY; |
261 |
< |
hastrans = bright(nd.tdiff) > FTINY; |
260 |
> |
hasrefl = (bright(nd.rdiff) > FTINY); |
261 |
> |
hastrans = (bright(nd.tdiff) > FTINY); |
262 |
|
/* load cal file */ |
263 |
|
nd.dp = NULL; |
264 |
|
mf = getfunc(m, 9, 0x3f, 0); |
271 |
|
if ((errno == EDOM) | (errno == ERANGE)) |
272 |
|
objerror(m, WARNING, "compute error"); |
273 |
|
else if (rayorigin(&sr, TRANS, r, ctmp) == 0) { |
274 |
< |
if (!(r->crtype & SHADOW) && hastexture) { |
274 |
> |
if (hastexture && !(r->crtype & (SHADOW|AMBIENT))) { |
275 |
|
/* perturb direction */ |
276 |
< |
VSUM(sr.rdir, r->rdir, r->pert, -.75); |
276 |
> |
VSUB(sr.rdir, r->rdir, r->pert); |
277 |
|
if (normalize(sr.rdir) == 0.0) { |
278 |
|
objerror(m, WARNING, "illegal perturbation"); |
279 |
|
VCOPY(sr.rdir, r->rdir); |
284 |
|
rayvalue(&sr); |
285 |
|
multcolor(sr.rcol, sr.rcoef); |
286 |
|
addcolor(r->rcol, sr.rcol); |
287 |
< |
if (!hastexture) { |
288 |
< |
transtest = 2.0*bright(sr.rcol); |
288 |
< |
transdist = r->rot + sr.rt; |
289 |
< |
} |
287 |
> |
if (!hastexture || r->crtype & (SHADOW|AMBIENT)) |
288 |
> |
r->rxt = r->rot + raydistance(&sr); |
289 |
|
} |
290 |
|
if (r->crtype & SHADOW) /* the rest is shadow */ |
291 |
|
return(1); |
292 |
+ |
|
293 |
|
/* compute reflected ray */ |
294 |
|
setbrdfunc(&nd); |
295 |
|
errno = 0; |
303 |
|
checknorm(sr.rdir); |
304 |
|
rayvalue(&sr); |
305 |
|
multcolor(sr.rcol, sr.rcoef); |
306 |
+ |
copycolor(r->mcol, sr.rcol); |
307 |
|
addcolor(r->rcol, sr.rcol); |
308 |
< |
if (!hastexture && r->ro != NULL && isflat(r->ro->otype)) { |
309 |
< |
mirtest = 2.0*bright(sr.rcol); |
310 |
< |
mirdist = r->rot + sr.rt; |
310 |
< |
} |
308 |
> |
if (r->ro != NULL && isflat(r->ro->otype) && |
309 |
> |
!hastexture | (r->crtype & AMBIENT)) |
310 |
> |
r->rmt = r->rot + raydistance(&sr); |
311 |
|
} |
312 |
|
/* compute ambient */ |
313 |
|
if (hasrefl) { |
334 |
|
if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') |
335 |
|
direct(r, dirbrdf, &nd); /* add direct component */ |
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 |
– |
|
337 |
|
return(1); |
338 |
|
} |
339 |
|
|
340 |
|
|
341 |
|
|
342 |
< |
extern int |
342 |
> |
int |
343 |
|
m_brdf2( /* color a ray that hit a BRDF material */ |
344 |
< |
register OBJREC *m, |
345 |
< |
register RAY *r |
344 |
> |
OBJREC *m, |
345 |
> |
RAY *r |
346 |
|
) |
347 |
|
{ |
348 |
|
BRDFDAT nd; |
358 |
|
objerror(m, USER, "bad # arguments"); |
359 |
|
/* check for back side */ |
360 |
|
if (r->rod < 0.0) { |
361 |
< |
if (!backvis && m->otype != MAT_TFUNC |
368 |
< |
&& m->otype != MAT_TDATA) { |
361 |
> |
if (!backvis) { |
362 |
|
raytrans(r); |
363 |
|
return(1); |
364 |
|
} |
407 |
|
multambient(ctmp, r, nd.pnorm); |
408 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
409 |
|
} |
410 |
< |
if (nd.trans > FTINY) { /* from other side */ |
410 |
> |
if (nd.trans > FTINY) { /* from other side */ |
411 |
|
flipsurface(r); |
412 |
|
vtmp[0] = -nd.pnorm[0]; |
413 |
|
vtmp[1] = -nd.pnorm[1]; |
427 |
|
|
428 |
|
static int |
429 |
|
setbrdfunc( /* set up brdf function and variables */ |
430 |
< |
register BRDFDAT *np |
430 |
> |
BRDFDAT *np |
431 |
|
) |
432 |
|
{ |
433 |
|
FVECT vec; |
436 |
|
return(0); /* it's OK, setfunc says we're done */ |
437 |
|
/* else (re)assign special variables */ |
438 |
|
multv3(vec, np->pnorm, funcxf.xfm); |
439 |
< |
varset("NxP", '=', vec[0]/funcxf.sca); |
440 |
< |
varset("NyP", '=', vec[1]/funcxf.sca); |
441 |
< |
varset("NzP", '=', vec[2]/funcxf.sca); |
442 |
< |
varset("RdotP", '=', np->pdot <= -1.0 ? -1.0 : |
439 |
> |
varset("NxP`", '=', vec[0]/funcxf.sca); |
440 |
> |
varset("NyP`", '=', vec[1]/funcxf.sca); |
441 |
> |
varset("NzP`", '=', vec[2]/funcxf.sca); |
442 |
> |
varset("RdotP`", '=', np->pdot <= -1.0 ? -1.0 : |
443 |
|
np->pdot >= 1.0 ? 1.0 : np->pdot); |
444 |
|
varset("CrP", '=', colval(np->mcolor,RED)); |
445 |
|
varset("CgP", '=', colval(np->mcolor,GRN)); |