8 |
|
#include "copyright.h" |
9 |
|
|
10 |
|
#include "ray.h" |
11 |
+ |
#include "otypes.h" |
12 |
|
#include "ambient.h" |
13 |
|
#include "source.h" |
14 |
|
#include "func.h" |
17 |
|
#include "pmapmat.h" |
18 |
|
|
19 |
|
/* |
20 |
< |
* Arguments to this material include optional diffuse colors. |
20 |
> |
* Arguments to this material include optional diffuse colors. |
21 |
|
* String arguments include the BSDF and function files. |
22 |
< |
* A non-zero thickness causes the strange but useful behavior |
22 |
> |
* For the MAT_BSDF type, a non-zero thickness causes the useful behavior |
23 |
|
* of translating transmitted rays this distance beneath the surface |
24 |
|
* (opposite the surface normal) to bypass any intervening geometry. |
25 |
|
* Translation only affects scattered, non-source-directed samples. |
36 |
|
* hides geometry in front of the surface when rays hit from behind, |
37 |
|
* and applies only the transmission and backside reflectance properties. |
38 |
|
* Reflection is ignored on the hidden side, as those rays pass through. |
39 |
< |
* When thickness is set to zero, shadow rays will be blocked unless |
40 |
< |
* a BTDF has a strong "through" component in the source direction. |
39 |
> |
* For the MAT_SBSDF type, we check for a strong "through" component. |
40 |
> |
* Such a component will cause direct rays to pass through unscattered. |
41 |
|
* A separate test prevents over-counting by dropping samples that are |
42 |
|
* too close to this "through" direction. BSDFs with such a through direction |
43 |
|
* will also have a view component, meaning they are somewhat see-through. |
44 |
+ |
* A MAT_BSDF type with zero thickness behaves the same as a MAT_SBSDF |
45 |
+ |
* type with no strong through component. |
46 |
|
* The "up" vector for the BSDF is given by three variables, defined |
47 |
|
* (along with the thickness) by the named function file, or '.' if none. |
48 |
|
* Together with the surface normal, this defines the local coordinate |
55 |
|
* not multiplied. However, patterns affect this material as a multiplier |
56 |
|
* on everything except non-diffuse reflection. |
57 |
|
* |
58 |
+ |
* Arguments for MAT_SBSDF are: |
59 |
+ |
* 5+ BSDFfile ux uy uz funcfile transform |
60 |
+ |
* 0 |
61 |
+ |
* 0|3|6|9 rdf gdf bdf |
62 |
+ |
* rdb gdb bdb |
63 |
+ |
* rdt gdt bdt |
64 |
+ |
* |
65 |
|
* Arguments for MAT_BSDF are: |
66 |
|
* 6+ thick BSDFfile ux uy uz funcfile transform |
67 |
|
* 0 |
86 |
|
RREAL toloc[3][3]; /* world to local BSDF coords */ |
87 |
|
RREAL fromloc[3][3]; /* local BSDF coords to world */ |
88 |
|
double thick; /* surface thickness */ |
89 |
< |
COLOR cthru; /* "through" component multiplier */ |
89 |
> |
COLOR cthru; /* "through" component for MAT_SBSDF */ |
90 |
|
SDData *sd; /* loaded BSDF data */ |
91 |
|
COLOR rdiff; /* diffuse reflection */ |
92 |
|
COLOR runsamp; /* BSDF hemispherical reflection */ |
96 |
|
|
97 |
|
#define cvt_sdcolor(cv, svp) ccy2rgb(&(svp)->spec, (svp)->cieY, cv) |
98 |
|
|
99 |
< |
/* Compute "through" component color */ |
99 |
> |
/* Compute "through" component color for MAT_SBSDF */ |
100 |
|
static void |
101 |
|
compute_through(BSDFDAT *ndp) |
102 |
|
{ |
124 |
|
int i; |
125 |
|
SDError ec; |
126 |
|
|
117 |
– |
setcolor(ndp->cthru, 0, 0, 0); /* starting assumption */ |
118 |
– |
|
127 |
|
if (ndp->pr->rod > 0) |
128 |
|
dfp = (ndp->sd->tf != NULL) ? ndp->sd->tf : ndp->sd->tb; |
129 |
|
else |
245 |
|
if ((vsrc[2] > 0) ^ (ndp->vray[2] > 0) && bright(ndp->cthru) > FTINY) { |
246 |
|
double dx = vsrc[0] + ndp->vray[0]; |
247 |
|
double dy = vsrc[1] + ndp->vray[1]; |
248 |
< |
if (dx*dx + dy*dy <= (1.5*4./PI)*(omega + tomega + |
248 |
> |
if (dx*dx + dy*dy <= (2.5*4./PI)*(omega + tomega + |
249 |
|
2.*sqrt(omega*tomega))) |
250 |
|
return(0); |
251 |
|
} |
589 |
|
int |
590 |
|
m_bsdf(OBJREC *m, RAY *r) |
591 |
|
{ |
592 |
+ |
int hasthick = (m->otype == MAT_BSDF); |
593 |
|
int hitfront; |
594 |
|
COLOR ctmp; |
595 |
|
SDError ec; |
597 |
|
MFUNC *mf; |
598 |
|
BSDFDAT nd; |
599 |
|
/* check arguments */ |
600 |
< |
if ((m->oargs.nsargs < 6) | (m->oargs.nfargs > 9) | |
600 |
> |
if ((m->oargs.nsargs < hasthick+5) | (m->oargs.nfargs > 9) | |
601 |
|
(m->oargs.nfargs % 3)) |
602 |
|
objerror(m, USER, "bad # arguments"); |
603 |
|
/* record surface struck */ |
604 |
|
hitfront = (r->rod > 0); |
605 |
|
/* load cal file */ |
606 |
< |
mf = getfunc(m, 5, 0x1d, 1); |
606 |
> |
mf = hasthick ? getfunc(m, 5, 0x1d, 1) |
607 |
> |
: getfunc(m, 4, 0xe, 1) ; |
608 |
|
setfunc(m, r); |
609 |
< |
/* get thickness */ |
610 |
< |
nd.thick = evalue(mf->ep[0]); |
611 |
< |
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
612 |
< |
nd.thick = 0; |
609 |
> |
nd.thick = 0; /* set thickness */ |
610 |
> |
if (hasthick) { |
611 |
> |
nd.thick = evalue(mf->ep[0]); |
612 |
> |
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
613 |
> |
nd.thick = 0; |
614 |
> |
} |
615 |
|
/* check backface visibility */ |
616 |
|
if (!hitfront & !backvis) { |
617 |
|
raytrans(r); |
627 |
|
nd.mp = m; |
628 |
|
nd.pr = r; |
629 |
|
/* get BSDF data */ |
630 |
< |
nd.sd = loadBSDF(m->oargs.sarg[1]); |
630 |
> |
nd.sd = loadBSDF(m->oargs.sarg[hasthick]); |
631 |
|
/* early shadow check */ |
632 |
|
if (r->crtype & SHADOW && (nd.sd->tf == NULL) & (nd.sd->tb == NULL)) |
633 |
|
return(1); |
663 |
|
multcolor(nd.rdiff, r->pcol); |
664 |
|
multcolor(nd.tdiff, r->pcol); |
665 |
|
/* get up vector */ |
666 |
< |
upvec[0] = evalue(mf->ep[1]); |
667 |
< |
upvec[1] = evalue(mf->ep[2]); |
668 |
< |
upvec[2] = evalue(mf->ep[3]); |
666 |
> |
upvec[0] = evalue(mf->ep[hasthick+0]); |
667 |
> |
upvec[1] = evalue(mf->ep[hasthick+1]); |
668 |
> |
upvec[2] = evalue(mf->ep[hasthick+2]); |
669 |
|
/* return to world coords */ |
670 |
|
if (mf->fxp != &unitxf) { |
671 |
|
multv3(upvec, upvec, mf->fxp->xfm); |
688 |
|
objerror(m, WARNING, "Illegal orientation vector"); |
689 |
|
return(1); |
690 |
|
} |
691 |
< |
compute_through(&nd); /* compute through component */ |
692 |
< |
if (r->crtype & SHADOW) { |
693 |
< |
RAY tr; /* attempt to pass shadow ray */ |
694 |
< |
if (rayorigin(&tr, TRANS, r, nd.cthru) < 0) |
695 |
< |
return(1); /* no through component */ |
696 |
< |
VCOPY(tr.rdir, r->rdir); |
697 |
< |
rayvalue(&tr); /* transmit with scaling */ |
698 |
< |
multcolor(tr.rcol, tr.rcoef); |
699 |
< |
copycolor(r->rcol, tr.rcol); |
700 |
< |
return(1); /* we're done */ |
691 |
> |
setcolor(nd.cthru, 0, 0, 0); /* consider through component */ |
692 |
> |
if (m->otype == MAT_SBSDF) { |
693 |
> |
compute_through(&nd); |
694 |
> |
if (r->crtype & SHADOW) { |
695 |
> |
RAY tr; /* attempt to pass shadow ray */ |
696 |
> |
if (rayorigin(&tr, TRANS, r, nd.cthru) < 0) |
697 |
> |
return(1); /* no through component */ |
698 |
> |
VCOPY(tr.rdir, r->rdir); |
699 |
> |
rayvalue(&tr); /* transmit with scaling */ |
700 |
> |
multcolor(tr.rcol, tr.rcoef); |
701 |
> |
copycolor(r->rcol, tr.rcol); |
702 |
> |
return(1); /* we're done */ |
703 |
> |
} |
704 |
|
} |
705 |
|
ec = SDinvXform(nd.fromloc, nd.toloc); |
706 |
|
if (!ec) /* determine BSDF resolution */ |