4 |
|
|
5 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
6 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
7 |
< |
Lucerne University of Applied Sciences & Arts |
7 |
> |
(c) Lucerne University of Applied Sciences and Arts, |
8 |
> |
supported by the Swiss National Science Foundation (SNSF, #147053) |
9 |
|
================================================================== |
10 |
|
|
11 |
|
$Id$ |
199 |
|
int niter, i = 0; |
200 |
|
|
201 |
|
/* Set up sample coordinates */ |
202 |
< |
do { |
202 |
< |
v [0] = v [1] = v [2] = 0; |
203 |
< |
v [i++] = 1; |
204 |
< |
fcross(u, v, nd -> pnorm); |
205 |
< |
} while (normalize(u) < FTINY); |
206 |
< |
|
202 |
> |
getperpendicular(u, nd -> pnorm, 1); |
203 |
|
fcross(v, nd -> pnorm, u); |
204 |
|
|
205 |
|
if (nd -> specfl & SP_REFL) { |
263 |
|
int i = 0; |
264 |
|
|
265 |
|
/* Set up sample coordinates */ |
266 |
< |
do { |
271 |
< |
v [0] = v [1] = v [2] = 0; |
272 |
< |
v [i++] = 1; |
273 |
< |
fcross(u, v, normal); |
274 |
< |
} while (normalize(u) < FTINY); |
275 |
< |
|
266 |
> |
getperpendicular(u, normal, 1); |
267 |
|
fcross(v, normal, u); |
268 |
|
|
269 |
|
/* Convert theta & phi to cartesian */ |
314 |
|
nd.specfl |= SP_FLAT; |
315 |
|
|
316 |
|
/* Perturb normal */ |
317 |
< |
if ((hastexture = DOT(rayIn -> pert, rayIn -> pert)) > sqr(FTINY)) |
317 |
> |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)) )) |
318 |
|
nd.pdot = raynormal(nd.pnorm, rayIn); |
319 |
|
else { |
320 |
|
VCOPY(nd.pnorm, rayIn -> ron); |
743 |
|
/* get modifiers */ |
744 |
|
raytexture(rayIn, mat -> omod); |
745 |
|
|
746 |
< |
if ((hastexture = DOT(rayIn -> pert, rayIn -> pert)) > FTINY * FTINY) |
746 |
> |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY))) |
747 |
|
/* Perturb normal */ |
748 |
|
cos1 = raynormal(dnorm, rayIn); |
749 |
|
else { |
890 |
|
/* reorient if necessary */ |
891 |
|
if (rayIn -> rod < 0) |
892 |
|
flipsurface(rayIn); |
893 |
< |
if ((hastexture = DOT(rayIn -> pert, rayIn -> pert)) > FTINY * FTINY) |
893 |
> |
if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY) )) |
894 |
|
pdot = raynormal(pnorm, rayIn); |
895 |
|
else { |
896 |
|
VCOPY(pnorm, rayIn -> ron); |
1650 |
|
} |
1651 |
|
#else |
1652 |
|
|
1653 |
+ |
/* |
1654 |
+ |
The following code is |
1655 |
+ |
(c) Lucerne University of Applied Sciences and Arts, |
1656 |
+ |
supported by the Swiss National Science Foundation (SNSF, #147053) |
1657 |
+ |
*/ |
1658 |
+ |
|
1659 |
|
static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn) |
1660 |
|
/* Generate new photon ray for BSDF modifier and recurse. */ |
1661 |
|
{ |
1667 |
|
BSDFDAT nd; |
1668 |
|
RAY rayOut; |
1669 |
|
COLOR bsdfRGB; |
1670 |
+ |
int transmitted; |
1671 |
|
double prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD, |
1672 |
< |
albedo, xi, xi2; |
1673 |
< |
const double patAlb = colorAvg(rayIn -> pcol); |
1672 |
> |
albedo, xi; |
1673 |
> |
const double patAlb = bright(rayIn -> pcol); |
1674 |
|
|
1675 |
|
/* Following code adapted from m_bsdf() */ |
1676 |
|
/* Check arguments */ |
1687 |
|
nd.thick = evalue(mf -> ep [0]); |
1688 |
|
if ((-FTINY <= nd.thick) & (nd.thick <= FTINY)) |
1689 |
|
nd.thick = .0; |
1690 |
< |
|
1690 |
> |
#if 0 |
1691 |
|
if (nd.thick != .0 || (!hitFront && !backvis)) { |
1692 |
|
/* Proxy geometry present, so use it instead and transfer ray */ |
1693 |
|
photonRay(rayIn, &rayOut, PMAP_XFER, NULL); |
1695 |
|
|
1696 |
|
return 0; |
1697 |
|
} |
1698 |
< |
|
1698 |
> |
#endif |
1699 |
|
/* Get BSDF data */ |
1700 |
|
nd.sd = loadBSDF(mat -> oargs.sarg [1]); |
1701 |
|
|
1808 |
|
if (prDiff + ptDiff + prDiffSD + ptDiffSD > FTINY) |
1809 |
|
addPhotons(rayIn); |
1810 |
|
|
1811 |
< |
xi = xi2 = pmapRandom(rouletteState); |
1811 |
> |
xi = pmapRandom(rouletteState); |
1812 |
|
|
1813 |
|
if (xi > albedo) |
1814 |
|
/* Absorbtion */ |
1815 |
|
return 0; |
1816 |
|
|
1817 |
+ |
transmitted = 0; |
1818 |
+ |
|
1819 |
|
if ((xi -= prDiff) <= 0) { |
1820 |
|
/* Diffuse reflection (extra component in material def) */ |
1821 |
|
photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff); |
1825 |
|
else if ((xi -= ptDiff) <= 0) { |
1826 |
|
/* Diffuse transmission (extra component in material def) */ |
1827 |
|
flipsurface(rayIn); |
1828 |
+ |
nd.thick = -nd.thick; |
1829 |
|
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff); |
1830 |
< |
diffPhotonScatter(nd.pnorm, &rayOut); |
1830 |
> |
diffPhotonScatter(nd.pnorm, &rayOut); |
1831 |
> |
transmitted = 1; |
1832 |
|
} |
1833 |
< |
|
1833 |
> |
|
1834 |
|
else { /* Sample SDF */ |
1835 |
|
if ((xi -= prDiffSD) <= 0) { |
1836 |
|
/* Diffuse SDF reflection (constant component) */ |
1837 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, |
1837 |
> |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1838 |
|
SDsampDf | SDsampR, nd.sd))) |
1839 |
|
objerror(mat, USER, transSDError(err)); |
1840 |
|
|
1846 |
|
|
1847 |
|
else if ((xi -= ptDiffSD) <= 0) { |
1848 |
|
/* Diffuse SDF transmission (constant component) */ |
1849 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, |
1849 |
> |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1850 |
|
SDsampDf | SDsampT, nd.sd))) |
1851 |
|
objerror(mat, USER, transSDError(err)); |
1852 |
|
|
1855 |
|
multcolor(bsdfRGB, rayIn -> pcol); |
1856 |
|
addcolor(bsdfRGB, nd.tdiff); |
1857 |
|
flipsurface(rayIn); /* Necessary? */ |
1858 |
< |
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB); |
1858 |
> |
nd.thick = -nd.thick; |
1859 |
> |
photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB); |
1860 |
> |
transmitted = 1; |
1861 |
|
} |
1862 |
|
|
1863 |
|
else if ((xi -= prSpecSD) <= 0) { |
1864 |
|
/* Non-diffuse ("specular") SDF reflection */ |
1865 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, |
1865 |
> |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1866 |
|
SDsampSp | SDsampR, nd.sd))) |
1867 |
|
objerror(mat, USER, transSDError(err)); |
1868 |
|
|
1872 |
|
|
1873 |
|
else { |
1874 |
|
/* Non-diffuse ("specular") SDF transmission */ |
1875 |
< |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2, |
1875 |
> |
if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState), |
1876 |
|
SDsampSp | SDsampT, nd.sd))) |
1877 |
|
objerror(mat, USER, transSDError(err)); |
1878 |
|
|
1880 |
|
ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB); |
1881 |
|
multcolor(bsdfRGB, rayIn -> pcol); |
1882 |
|
flipsurface(rayIn); /* Necessary? */ |
1883 |
+ |
nd.thick = -nd.thick; |
1884 |
|
photonRay(rayIn, &rayOut, PMAP_SPECTRANS, bsdfRGB); |
1885 |
+ |
transmitted = 1; |
1886 |
|
} |
1887 |
|
|
1888 |
|
/* Xform outgoing dir to world coords */ |
1894 |
|
|
1895 |
|
/* Clean up */ |
1896 |
|
SDfreeCache(nd.sd); |
1897 |
+ |
|
1898 |
+ |
/* Need to offset ray origin to get past detail geometry? */ |
1899 |
+ |
if (transmitted && nd.thick != 0) |
1900 |
+ |
VSUM(rayOut.rorg, rayOut.rorg, rayIn -> ron, -nd.thick); |
1901 |
|
|
1902 |
|
tracePhoton(&rayOut); |
1903 |
|
return 0; |