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.3 by rschregle, Fri May 8 13:20:23 2015 UTC vs.
Revision 2.6 by greg, Fri May 22 10:27:40 2015 UTC

# Line 199 | Line 199 | static int isoSpecPhotonScatter (NORMDAT *nd, RAY *ray
199     int      niter, i = 0;
200    
201     /* Set up sample coordinates */  
202 <   do {
203 <      v [0] = v [1] = v [2] = 0;
204 <      v [i++] = 1;
205 <      fcross(u, v, nd -> pnorm);
206 <   } while (normalize(u) < FTINY);
207 <  
202 >   getperpendicular(u, nd -> pnorm, 1);  
203     fcross(v, nd -> pnorm, u);
204    
205     if (nd -> specfl & SP_REFL) {
# Line 268 | Line 263 | static void diffPhotonScatter (FVECT normal, RAY* rayO
263     int         i = 0;
264  
265     /* Set up sample coordinates */
266 <   do {
272 <      v [0] = v [1] = v [2] = 0;
273 <      v [i++] = 1;
274 <      fcross(u, v, normal);
275 <   } while (normalize(u) < FTINY);
276 <  
266 >   getperpendicular(u, normal, 1);
267     fcross(v, normal, u);
268    
269     /* Convert theta & phi to cartesian */
# Line 324 | Line 314 | static int normalPhotonScatter (OBJREC *mat, RAY *rayI
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);
# Line 753 | Line 743 | static int dielectricPhotonScatter (OBJREC *mat, RAY *
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 {
# Line 900 | Line 890 | static int glassPhotonScatter (OBJREC *mat, RAY *rayIn
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);
# Line 1677 | 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 1696 | 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 1704 | 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 1817 | 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 1832 | 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 1851 | 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 1860 | 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 1875 | 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 1883 | 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 1895 | 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