2 |
|
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
4 |
|
/* |
5 |
< |
================================================================== |
5 |
> |
|
6 |
> |
====================================================================== |
7 |
|
Photon map support routines for scattering by materials. |
8 |
|
|
9 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
10 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
11 |
+ |
supported by the German Research Foundation |
12 |
+ |
(DFG LU-204/10-2, "Fassadenintegrierte Regelsysteme FARESYS") |
13 |
|
(c) Lucerne University of Applied Sciences and Arts, |
14 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
15 |
< |
================================================================== |
14 |
> |
supported by the Swiss National Science Foundation |
15 |
> |
(SNSF #147053, "Daylight Redirecting Components") |
16 |
> |
====================================================================== |
17 |
|
|
18 |
|
*/ |
19 |
|
|
1582 |
|
objerror(mat, WARNING, "illegal perturbation"); |
1583 |
|
VCOPY(rayOut.rdir, rayIn -> rdir); |
1584 |
|
} |
1581 |
– |
else VCOPY(rayOut.rdir, rayIn -> rdir); |
1585 |
|
} |
1586 |
+ |
else VCOPY(rayOut.rdir, rayIn -> rdir); |
1587 |
|
} |
1588 |
|
else if (xi > (albedo -= prDiff)) { |
1589 |
|
/* Diffuz reflekzion */ |
1715 |
|
|
1716 |
|
|
1717 |
|
/* |
1718 |
< |
================================================================== |
1718 |
> |
====================================================================== |
1719 |
|
The following code is |
1720 |
|
(c) Lucerne University of Applied Sciences and Arts, |
1721 |
< |
supported by the Swiss National Science Foundation (SNSF, #147053) |
1722 |
< |
================================================================== |
1721 |
> |
supported by the Swiss National Science Foundation |
1722 |
> |
(SNSF #147053, "Daylight Redirecting Components") |
1723 |
> |
====================================================================== |
1724 |
|
*/ |
1725 |
|
|
1726 |
|
static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) |
1727 |
|
/* Generate new photon ray for BSDF modifier and recurse. */ |
1728 |
|
{ |
1729 |
< |
int hasthick = (mat->otype == MAT_BSDF); |
1730 |
< |
int hitFront; |
1731 |
< |
SDError err; |
1732 |
< |
SDValue bsdfVal; |
1733 |
< |
FVECT upvec; |
1734 |
< |
MFUNC *mf; |
1735 |
< |
BSDFDAT nd; |
1736 |
< |
RAY rayOut; |
1737 |
< |
COLOR bsdfRGB; |
1738 |
< |
int transmitted; |
1739 |
< |
double prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD, |
1740 |
< |
albedo, xi; |
1741 |
< |
const double patAlb = bright(rayIn -> pcol); |
1729 |
> |
int hasthick = (mat->otype == MAT_BSDF); |
1730 |
> |
int hitFront; |
1731 |
> |
SDError err; |
1732 |
> |
SDValue bsdfVal; |
1733 |
> |
FVECT upvec; |
1734 |
> |
MFUNC *mf; |
1735 |
> |
BSDFDAT nd; |
1736 |
> |
RAY rayOut; |
1737 |
> |
COLOR bsdfRGB; |
1738 |
> |
int transmitted; |
1739 |
> |
double prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD, |
1740 |
> |
albedo, xi; |
1741 |
> |
const double patAlb = bright(rayIn -> pcol); |
1742 |
|
|
1743 |
|
/* Following code adapted from m_bsdf() */ |
1744 |
|
/* Check arguments */ |
1745 |
< |
if (mat -> oargs.nsargs < hasthick+5 || mat -> oargs.nfargs > 9 || |
1746 |
< |
mat -> oargs.nfargs % 3) |
1745 |
> |
if ( |
1746 |
> |
mat -> oargs.nsargs < hasthick+5 || |
1747 |
> |
mat -> oargs.nfargs > 9 || mat -> oargs.nfargs % 3 |
1748 |
> |
) |
1749 |
|
objerror(mat, USER, "bad # arguments"); |
1750 |
|
|
1751 |
|
hitFront = (rayIn -> rod > 0); |
1756 |
|
/* Get thickness */ |
1757 |
|
nd.thick = 0; |
1758 |
|
if (hasthick) { |
1759 |
< |
nd.thick = evalue(mf -> ep [0]); |
1760 |
< |
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
1761 |
< |
nd.thick = .0; |
1759 |
> |
nd.thick = evalue(mf -> ep [0]); |
1760 |
> |
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
1761 |
> |
nd.thick = .0; |
1762 |
|
} |
1763 |
|
|
1764 |
|
/* Get BSDF data */ |
1768 |
|
if (hitFront) { |
1769 |
|
if (mat -> oargs.nfargs < 3) |
1770 |
|
setcolor(nd.rdiff, .0, .0, .0); |
1771 |
< |
else setcolor(nd.rdiff, mat -> oargs.farg [0], mat -> oargs.farg [1], |
1772 |
< |
mat -> oargs.farg [2]); |
1771 |
> |
else setcolor( |
1772 |
> |
nd.rdiff, |
1773 |
> |
mat -> oargs.farg [0], mat -> oargs.farg [1], mat -> oargs.farg [2] |
1774 |
> |
); |
1775 |
|
} |
1776 |
|
else if (mat -> oargs.nfargs < 6) { |
1777 |
|
/* Check for absorbing backside */ |
1782 |
|
|
1783 |
|
setcolor(nd.rdiff, .0, .0, .0); |
1784 |
|
} |
1785 |
< |
else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4], |
1786 |
< |
mat -> oargs.farg [5]); |
1785 |
> |
else setcolor( |
1786 |
> |
nd.rdiff, |
1787 |
> |
mat -> oargs.farg [3], mat -> oargs.farg [4], mat -> oargs.farg [5] |
1788 |
> |
); |
1789 |
|
|
1790 |
|
/* Extra diffuse transmittance from material def */ |
1791 |
|
if (mat -> oargs.nfargs < 9) |
1792 |
|
setcolor(nd.tdiff, .0, .0, .0); |
1793 |
< |
else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7], |
1794 |
< |
mat -> oargs.farg [8]); |
1793 |
> |
else setcolor( |
1794 |
> |
nd.tdiff, |
1795 |
> |
mat -> oargs.farg [6], mat -> oargs.farg [7], mat -> oargs.farg [8] |
1796 |
> |
); |
1797 |
|
|
1798 |
|
nd.mp = mat; |
1799 |
|
nd.pr = rayIn; |
1842 |
|
} |
1843 |
|
|
1844 |
|
/* Determine BSDF resolution */ |
1845 |
< |
err = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, |
1846 |
< |
SDqueryMin + SDqueryMax, nd.sd); |
1845 |
> |
err = SDsizeBSDF( |
1846 |
> |
nd.sr_vpsa, nd.vray, NULL, SDqueryMin + SDqueryMax, nd.sd |
1847 |
> |
); |
1848 |
|
|
1849 |
|
if (err) |
1850 |
|
objerror(mat, USER, transSDError(err)); |
1905 |
|
else { /* Sample SDF */ |
1906 |
|
if ((xi -= prDiffSD) <= 0) { |
1907 |
|
/* Diffuse SDF reflection (constant component) */ |
1908 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1909 |
< |
SDsampDf | SDsampR, nd.sd))) |
1908 |
> |
if ((err = SDsampBSDF( |
1909 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
1910 |
> |
SDsampDf | SDsampR, nd.sd |
1911 |
> |
))) |
1912 |
|
objerror(mat, USER, transSDError(err)); |
1913 |
|
|
1914 |
|
/* Apply pattern to spectral component */ |
1919 |
|
|
1920 |
|
else if ((xi -= ptDiffSD) <= 0) { |
1921 |
|
/* Diffuse SDF transmission (constant component) */ |
1922 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1923 |
< |
SDsampDf | SDsampT, nd.sd))) |
1922 |
> |
if ((err = SDsampBSDF( |
1923 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
1924 |
> |
SDsampDf | SDsampT, nd.sd |
1925 |
> |
))) |
1926 |
|
objerror(mat, USER, transSDError(err)); |
1927 |
|
|
1928 |
|
/* Apply pattern to spectral component */ |
1935 |
|
|
1936 |
|
else if ((xi -= prSpecSD) <= 0) { |
1937 |
|
/* Non-diffuse ("specular") SDF reflection */ |
1938 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1939 |
< |
SDsampSp | SDsampR, nd.sd))) |
1938 |
> |
if ((err = SDsampBSDF( |
1939 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
1940 |
> |
SDsampSp | SDsampR, nd.sd |
1941 |
> |
))) |
1942 |
|
objerror(mat, USER, transSDError(err)); |
1943 |
|
|
1944 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
1947 |
|
|
1948 |
|
else { |
1949 |
|
/* Non-diffuse ("specular") SDF transmission */ |
1950 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1951 |
< |
SDsampSp | SDsampT, nd.sd))) |
1950 |
> |
if ((err = SDsampBSDF( |
1951 |
> |
&bsdfVal, nd.vray, pmapRandom(scatterState), |
1952 |
> |
SDsampSp | SDsampT, nd.sd |
1953 |
> |
))) |
1954 |
|
objerror(mat, USER, transSDError(err)); |
1955 |
|
|
1956 |
|
/* Apply pattern to spectral component */ |