| 199 |
|
int niter, i = 0; |
| 200 |
|
|
| 201 |
|
/* Set up sample coordinates */ |
| 202 |
< |
getperpendicular(u, nd -> pnorm); |
| 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 |
< |
getperpendicular(u, normal); |
| 266 |
> |
getperpendicular(u, normal, 1); |
| 267 |
|
fcross(v, normal, u); |
| 268 |
|
|
| 269 |
|
/* Convert theta & phi to cartesian */ |
| 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; |