1 |
– |
/* Copyright (c) 1991 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Shading for materials with arbitrary BRDF's |
6 |
|
*/ |
7 |
|
|
8 |
+ |
#include "copyright.h" |
9 |
+ |
|
10 |
|
#include "ray.h" |
11 |
|
|
12 |
|
#include "data.h" |
15 |
|
|
16 |
|
#include "func.h" |
17 |
|
|
19 |
– |
extern int backvis; /* back faces visible? */ |
20 |
– |
|
18 |
|
/* |
19 |
|
* Arguments to this material include the color and specularity. |
20 |
|
* String arguments include the reflection function and files. |
77 |
|
} BRDFDAT; /* BRDF material data */ |
78 |
|
|
79 |
|
|
80 |
+ |
static void |
81 |
|
dirbrdf(cval, np, ldir, omega) /* compute source contribution */ |
82 |
|
COLOR cval; /* returned coefficient */ |
83 |
|
register BRDFDAT *np; /* material data */ |
189 |
|
} |
190 |
|
|
191 |
|
|
192 |
< |
m_brdf(m, r) /* color a ray which hit a BRDTfunc material */ |
192 |
> |
int |
193 |
> |
m_brdf(m, r) /* color a ray that hit a BRDTfunc material */ |
194 |
|
register OBJREC *m; |
195 |
|
register RAY *r; |
196 |
|
{ |
197 |
+ |
int hitfront = 1; |
198 |
|
BRDFDAT nd; |
199 |
|
RAY sr; |
200 |
|
double transtest, transdist; |
224 |
|
setcolor(nd.tdiff, m->oargs.farg[6], |
225 |
|
m->oargs.farg[7], |
226 |
|
m->oargs.farg[8]); |
227 |
< |
/* get modifiers */ |
227 |
> |
/* get modifiers */ |
228 |
|
raytexture(r, m->omod); |
229 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
230 |
|
if (r->rod < 0.0) { /* orient perturbed values */ |
233 |
|
nd.pnorm[i] = -nd.pnorm[i]; |
234 |
|
r->pert[i] = -r->pert[i]; |
235 |
|
} |
236 |
+ |
hitfront = 0; |
237 |
|
} |
238 |
|
copycolor(nd.mcolor, r->pcol); /* get pattern color */ |
239 |
|
multcolor(nd.rdiff, nd.mcolor); /* modify diffuse values */ |
291 |
|
} |
292 |
|
/* compute ambient */ |
293 |
|
if (hasrefl) { |
294 |
< |
if (nd.pdot < 0.0) { |
294 |
> |
if (!hitfront) |
295 |
|
flipsurface(r); |
296 |
< |
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); |
296 |
> |
ambient(ctmp, r, nd.pnorm); |
297 |
|
multcolor(ctmp, nd.rdiff); |
298 |
|
addcolor(r->rcol, ctmp); /* add to returned color */ |
299 |
< |
if (nd.pdot < 0.0) |
299 |
> |
if (!hitfront) |
300 |
|
flipsurface(r); |
301 |
|
} |
302 |
|
if (hastrans) { /* from other side */ |
303 |
< |
if (nd.pdot > 0.0) { |
303 |
> |
if (hitfront) |
304 |
|
flipsurface(r); |
305 |
< |
vtmp[0] = -nd.pnorm[0]; |
306 |
< |
vtmp[1] = -nd.pnorm[1]; |
307 |
< |
vtmp[2] = -nd.pnorm[2]; |
312 |
< |
} else |
313 |
< |
VCOPY(vtmp, nd.pnorm); |
305 |
> |
vtmp[0] = -nd.pnorm[0]; |
306 |
> |
vtmp[1] = -nd.pnorm[1]; |
307 |
> |
vtmp[2] = -nd.pnorm[2]; |
308 |
|
ambient(ctmp, r, vtmp); |
309 |
|
multcolor(ctmp, nd.tdiff); |
310 |
|
addcolor(r->rcol, ctmp); |
311 |
< |
if (nd.pdot > 0.0) |
311 |
> |
if (hitfront) |
312 |
|
flipsurface(r); |
313 |
|
} |
314 |
|
if (hasrefl | hastrans || m->oargs.sarg[6][0] != '0') |
322 |
|
|
323 |
|
|
324 |
|
|
325 |
< |
m_brdf2(m, r) /* color a ray which hit a BRDF material */ |
325 |
> |
int |
326 |
> |
m_brdf2(m, r) /* color a ray that hit a BRDF material */ |
327 |
|
register OBJREC *m; |
328 |
|
register RAY *r; |
329 |
|
{ |
338 |
|
if (m->oargs.nsargs < (hasdata(m->otype)?4:2) | m->oargs.nfargs < |
339 |
|
(m->otype==MAT_TFUNC|m->otype==MAT_TDATA?6:4)) |
340 |
|
objerror(m, USER, "bad # arguments"); |
341 |
+ |
/* check for back side */ |
342 |
+ |
if (r->rod < 0.0) { |
343 |
+ |
if (!backvis && m->otype != MAT_TFUNC |
344 |
+ |
&& m->otype != MAT_TDATA) { |
345 |
+ |
raytrans(r); |
346 |
+ |
return(1); |
347 |
+ |
} |
348 |
+ |
raytexture(r, m->omod); |
349 |
+ |
flipsurface(r); /* reorient if backvis */ |
350 |
+ |
} else |
351 |
+ |
raytexture(r, m->omod); |
352 |
+ |
|
353 |
|
nd.mp = m; |
354 |
|
nd.pr = r; |
355 |
|
/* get material color */ |
371 |
|
/* compute reflectance */ |
372 |
|
dtmp = 1.0 - nd.trans - nd.rspec; |
373 |
|
setcolor(nd.rdiff, dtmp, dtmp, dtmp); |
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); |
374 |
|
nd.pdot = raynormal(nd.pnorm, r); /* perturb normal */ |
375 |
|
multcolor(nd.mcolor, r->pcol); /* modify material color */ |
376 |
|
multcolor(nd.rdiff, nd.mcolor); |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
+ |
int |
412 |
|
setbrdfunc(np) /* set up brdf function and variables */ |
413 |
|
register BRDFDAT *np; |
414 |
|
{ |