ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapmat.c
(Generate patch)

Comparing ray/src/rt/pmapmat.c (file contents):
Revision 2.5 by greg, Thu May 21 05:54:54 2015 UTC vs.
Revision 2.6 by greg, Fri May 22 10:27:40 2015 UTC

# Line 1667 | Line 1667 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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 */
# Line 1686 | Line 1687 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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);
# Line 1694 | Line 1695 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1695        
1696        return 0;
1697     }
1698 <
1698 > #endif
1699     /* Get BSDF data */
1700     nd.sd = loadBSDF(mat -> oargs.sarg [1]);
1701    
# Line 1807 | Line 1808 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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);
# Line 1822 | Line 1825 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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          
# Line 1841 | Line 1846 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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          
# Line 1850 | Line 1855 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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          
# Line 1865 | Line 1872 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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  
# Line 1873 | Line 1880 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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 */
# Line 1885 | Line 1894 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines