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.13 by rschregle, Tue May 17 17:39:47 2016 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5     ==================================================================
6     Photon map support routines for scattering by materials.
# Line 8 | Line 11
11     supported by the Swiss National Science Foundation (SNSF, #147053)
12     ==================================================================
13    
11   $Id$
14   */
15  
16  
# Line 104 | Line 106 | void photonRay (const RAY *rayIn, RAY *rayOut,
106   {
107     rayorigin(rayOut, rayOutType, rayIn, NULL);
108    
109 <   /* Transfer flux */
110 <   copycolor(rayOut -> rcol, rayIn -> rcol);
111 <  
112 <   /* Copy caustic flag & direction for transferred rays */
113 <   if (rayOutType == PMAP_XFER) {
114 <      /* rayOut -> rtype |= rayIn -> rtype & SPECULAR; */
115 <      rayOut -> rtype |= rayIn -> rtype;
116 <      VCOPY(rayOut -> rdir, rayIn -> rdir);
117 <   }
118 <   else if (fluxAtten) {
119 <      /* Attenuate and normalise flux for scattered rays */
120 <      multcolor(rayOut -> rcol, fluxAtten);
121 <      colorNorm(rayOut -> rcol);
122 <   }
109 >   if (rayIn) {
110 >      /* Transfer flux */
111 >      copycolor(rayOut -> rcol, rayIn -> rcol);
112 >      
113 >      /* Copy caustic flag & direction for transferred rays */
114 >      if (rayOutType == PMAP_XFER) {
115 >         /* rayOut -> rtype |= rayIn -> rtype & SPECULAR; */
116 >         rayOut -> rtype |= rayIn -> rtype;
117 >         VCOPY(rayOut -> rdir, rayIn -> rdir);
118 >      }
119 >      else if (fluxAtten) {
120 >         /* Attenuate and normalise flux for scattered rays */
121 >         multcolor(rayOut -> rcol, fluxAtten);
122 >         colorNorm(rayOut -> rcol);
123 >      }
124  
125 <   /* Propagate index of emitting light source */
126 <   rayOut -> rsrc = rayIn -> rsrc;
125 >      /* Propagate index of emitting light source */
126 >      rayOut -> rsrc = rayIn -> rsrc;
127 >   }
128   }
129  
130  
# Line 130 | Line 134 | static void addPhotons (const RAY *r)
134   {
135     if (!r -> rlvl)
136        /* Add direct photon map at primary hitpoint */
137 <      addPhoton(directPmap, r);
137 >      newPhoton(directPmap, r);
138     else {
139        /* Add global or precomputed photon map at indirect hitpoint */
140 <      addPhoton(preCompPmap ? preCompPmap : globalPmap, r);
140 >      newPhoton(preCompPmap ? preCompPmap : globalPmap, r);
141  
142        /* Store caustic photon if specular flag set */
143        if (PMAP_CAUSTICRAY(r))
144 <         addPhoton(causticPmap, r);
144 >         newPhoton(causticPmap, r);
145          
146        /* Store in contribution photon map */
147 <      addPhoton(contribPmap, r);
147 >      newPhoton(contribPmap, r);
148     }
149   }
150  
# Line 199 | Line 203 | static int isoSpecPhotonScatter (NORMDAT *nd, RAY *ray
203     int      niter, i = 0;
204    
205     /* Set up sample coordinates */  
206 <   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 <  
206 >   getperpendicular(u, nd -> pnorm, 1);  
207     fcross(v, nd -> pnorm, u);
208    
209     if (nd -> specfl & SP_REFL) {
# Line 268 | Line 267 | static void diffPhotonScatter (FVECT normal, RAY* rayO
267     int         i = 0;
268  
269     /* Set up sample coordinates */
270 <   do {
272 <      v [0] = v [1] = v [2] = 0;
273 <      v [i++] = 1;
274 <      fcross(u, v, normal);
275 <   } while (normalize(u) < FTINY);
276 <  
270 >   getperpendicular(u, normal, 1);
271     fcross(v, normal, u);
272    
273     /* Convert theta & phi to cartesian */
# Line 324 | Line 318 | static int normalPhotonScatter (OBJREC *mat, RAY *rayI
318        nd.specfl |= SP_FLAT;  
319        
320     /* Perturb normal */
321 <   if ((hastexture = DOT(rayIn -> pert, rayIn -> pert)) > sqr(FTINY))
321 >   if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > sqr(FTINY)) ))
322        nd.pdot = raynormal(nd.pnorm, rayIn);
323     else {
324        VCOPY(nd.pnorm, rayIn -> ron);
# Line 753 | Line 747 | static int dielectricPhotonScatter (OBJREC *mat, RAY *
747     /* get modifiers */
748     raytexture(rayIn, mat -> omod);                      
749    
750 <   if ((hastexture = DOT(rayIn -> pert, rayIn -> pert)) > FTINY * FTINY)
750 >   if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY)))
751        /* Perturb normal */
752        cos1 = raynormal(dnorm, rayIn);
753     else {
# Line 900 | Line 894 | static int glassPhotonScatter (OBJREC *mat, RAY *rayIn
894     /* reorient if necessary */
895     if (rayIn -> rod < 0)
896        flipsurface(rayIn);
897 <   if ((hastexture = DOT(rayIn -> pert, rayIn -> pert)) > FTINY * FTINY)
897 >   if ((hastexture = (DOT(rayIn -> pert, rayIn -> pert) > FTINY * FTINY) ))
898        pdot = raynormal(pnorm, rayIn);
899     else {
900        VCOPY(pnorm, rayIn -> ron);
# Line 986 | Line 980 | static int aliasPhotonScatter (OBJREC *mat, RAY *rayIn
980    
981     /* Straight replacement? */
982     if (!mat -> oargs.nsargs) {
983 <      mat = objptr(mat -> omod);
984 <      photonScatter [mat -> otype] (mat, rayIn);
983 >      /* Skip void modifier! */
984 >      if (mat -> omod != OVOID) {  
985 >         mat = objptr(mat -> omod);
986 >         photonScatter [mat -> otype] (mat, rayIn);
987 >      }
988        
989        return 0;
990     }
# Line 1258 | Line 1255 | static int mx_dataPhotonScatter (OBJREC *mat, RAY *ray
1255     if (errno)
1256        objerror(mat, WARNING, "compute error");
1257     else {
1258 <      mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]);
1259 <      photonScatter [mat -> otype] (mat, rayIn);
1258 >      OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1];
1259 >      
1260 >      if (mxMod != OVOID) {
1261 >         mat = objptr(mxMod);
1262 >         photonScatter [mat -> otype] (mat, rayIn);
1263 >      }
1264 >      else {
1265 >         /* Transfer ray if no modifier */
1266 >         RAY rayOut;
1267 >        
1268 >         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1269 >         tracePhoton(&rayOut);      
1270 >      }            
1271     }
1272    
1273     return 0;
# Line 1311 | Line 1319 | static int mx_pdataPhotonScatter (OBJREC *mat, RAY *ra
1319     if (errno)
1320        objerror(mat, WARNING, "compute error");
1321     else {
1322 <      mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]);
1323 <      photonScatter [mat -> otype] (mat, rayIn);
1322 >      OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1];
1323 >      
1324 >      if (mxMod != OVOID) {
1325 >         mat = objptr(mxMod);
1326 >         photonScatter [mat -> otype] (mat, rayIn);
1327 >      }
1328 >      else {
1329 >         /* Transfer ray if no modifier */
1330 >         RAY rayOut;
1331 >        
1332 >         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1333 >         tracePhoton(&rayOut);      
1334 >      }      
1335     }  
1336    
1337     return 0;
# Line 1351 | Line 1370 | static int mx_funcPhotonScatter (OBJREC *mat, RAY *ray
1370     if (errno)
1371        objerror(mat, WARNING, "compute error");
1372     else {        
1373 <      mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]);
1374 <      photonScatter [mat -> otype] (mat, rayIn);
1373 >      OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1];
1374 >      
1375 >      if (mxMod != OVOID) {
1376 >         mat = objptr(mxMod);
1377 >         photonScatter [mat -> otype] (mat, rayIn);
1378 >      }
1379 >      else {
1380 >         /* Transfer ray if no modifier */
1381 >         RAY rayOut;
1382 >        
1383 >         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1384 >         tracePhoton(&rayOut);      
1385 >      }
1386     }
1387    
1388     return 0;
# Line 1384 | Line 1414 | static int pattexPhotonScatter (OBJREC *mat, RAY *rayI
1414  
1415  
1416  
1387 #if 0
1388   static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1389   /* Generate new photon ray for BSDF modifier and recurse. */
1390   {
1391      int      hitFront;
1392      SDError  err;
1393      FVECT        upvec;
1394      MFUNC        *mf;
1395      BSDFDAT   nd;
1396      RAY      rayOut;
1397
1398      /* Following code adapted from m_bsdf() */
1399      /* Check arguments */
1400      if (mat -> oargs.nsargs < 6 || mat -> oargs.nfargs > 9 ||
1401          mat -> oargs.nfargs % 3)
1402         objerror(mat, USER, "bad # arguments");
1403        
1404      hitFront = (rayIn -> rod > 0);
1405
1406      /* Load cal file */
1407      mf = getfunc(mat, 5, 0x1d, 1);
1408      
1409      /* Get thickness */
1410      nd.thick = evalue(mf -> ep [0]);
1411      if ((-FTINY <= nd.thick) & (nd.thick <= FTINY))
1412         nd.thick = .0;
1413        
1414      if (nd.thick != .0 || (!hitFront && !backvis)) {
1415         /* Proxy geometry present, so use it instead and transfer ray */
1416         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1417         tracePhoton(&rayOut);
1418        
1419         return 0;
1420      }
1421
1422      /* Get BSDF data */
1423      nd.sd = loadBSDF(mat -> oargs.sarg [1]);
1424      
1425      /* Diffuse reflectance */
1426      if (hitFront) {
1427         if (mat -> oargs.nfargs < 3)
1428            setcolor(nd.rdiff, .0, .0, .0);
1429         else setcolor(nd.rdiff, mat -> oargs.farg [0], mat -> oargs.farg [1],
1430                       mat -> oargs.farg [2]);
1431      }    
1432      else if (mat -> oargs.nfargs < 6) {
1433         /* Check for absorbing backside */
1434         if (!backvis && !nd.sd -> rb && !nd.sd -> tf) {
1435            SDfreeCache(nd.sd);                    
1436            return 0;
1437         }
1438        
1439         setcolor(nd.rdiff, .0, .0, .0);
1440      }
1441      else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4],
1442                    mat -> oargs.farg [5]);
1443
1444      /* Diffuse transmittance */
1445      if (mat -> oargs.nfargs < 9)
1446         setcolor(nd.tdiff, .0, .0, .0);
1447      else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7],
1448                    mat -> oargs.farg [8]);
1449                  
1450      nd.mp = mat;
1451      nd.pr = rayIn;
1452      
1453      /* Get modifiers */
1454      raytexture(rayIn, mat -> omod);
1455      
1456      /* Modify diffuse values */
1457      multcolor(nd.rdiff, rayIn -> pcol);
1458      multcolor(nd.tdiff, rayIn -> pcol);
1459        
1460      /* Get up vector & xform to world coords */
1461      upvec [0] = evalue(mf -> ep [1]);
1462      upvec [1] = evalue(mf -> ep [2]);
1463      upvec [2] = evalue(mf -> ep [3]);
1464      
1465      if (mf -> fxp != &unitxf) {
1466         multv3(upvec, upvec, mf -> fxp -> xfm);
1467         nd.thick *= mf -> fxp -> sca;
1468      }
1469      
1470      if (rayIn -> rox) {
1471         multv3(upvec, upvec, rayIn -> rox -> f.xfm);
1472         nd.thick *= rayIn -> rox -> f.sca;
1473      }
1474      
1475      /* Perturb normal */
1476      raynormal(nd.pnorm, rayIn);
1477      
1478      /* Xform incident dir to local BSDF coords */
1479      err = SDcompXform(nd.toloc, nd.pnorm, upvec);
1480      
1481      if (!err) {
1482         nd.vray [0] = -rayIn -> rdir [0];
1483         nd.vray [1] = -rayIn -> rdir [1];
1484         nd.vray [2] = -rayIn -> rdir [2];
1485         err = SDmapDir(nd.vray, nd.toloc, nd.vray);
1486      }
1487      
1488      if (!err)
1489         err = SDinvXform(nd.fromloc, nd.toloc);
1490        
1491      if (err) {
1492         objerror(mat, WARNING, "Illegal orientation vector");
1493         return 0;
1494      }
1495      
1496      /* Determine BSDF resolution */
1497      err = SDsizeBSDF(nd.sr_vpsa, nd.vray, NULL, SDqueryMin + SDqueryMax, nd.sd);
1498      
1499      if (err)
1500         objerror(mat, USER, transSDError(err));
1501        
1502      nd.sr_vpsa [0] = sqrt(nd.sr_vpsa [0]);
1503      nd.sr_vpsa [1] = sqrt(nd.sr_vpsa [1]);
1504
1505      /* Orient perturbed normal towards incident side */
1506      if (!hitFront) {                  
1507         nd.pnorm [0] = -nd.pnorm [0];
1508         nd.pnorm [1] = -nd.pnorm [1];
1509         nd.pnorm [2] = -nd.pnorm [2];
1510      }
1511      
1512      /* Following code adapted from SDsampBSDF() */
1513      {
1514         SDSpectralDF   *rdf, *tdf;
1515         SDValue        bsdfVal;
1516         double         xi, rhoDiff = 0;
1517         float          coef [SDmaxCh];
1518         int            i, j, n, nr;
1519         SDComponent       *sdc;
1520         const SDCDst   **cdarr = NULL;
1521        
1522         /* Get diffuse albedo (?) */
1523         if (hitFront) {
1524            bsdfVal = nd.sd -> rLambFront;
1525            rdf = nd.sd -> rf;
1526            tdf = nd.sd -> tf ? nd.sd -> tf : nd.sd -> tb;
1527         }
1528         else {
1529            bsdfVal = nd.sd -> rLambBack;
1530            rdf = nd.sd -> rb;
1531            tdf = nd.sd -> tb ? nd.sd -> tb : nd.sd -> tf;
1532         }
1533        
1534         rhoDiff = bsdfVal.cieY;
1535         bsdfVal.cieY += nd.sd -> tLamb.cieY;
1536        
1537         /* Allocate non-diffuse sampling */
1538         i = nr = rdf ? rdf -> ncomp : 0;
1539         j = tdf ? tdf -> ncomp : 0;
1540         n = i + j;
1541        
1542         if (n > 0 && !(cdarr = (const SDCDst**)malloc(n * sizeof(SDCDst*))))
1543            objerror(mat, USER, transSDError(SDEmemory));
1544            
1545         while (j-- > 0) {
1546            /* Sum up non-diffuse transmittance */
1547            cdarr [i + j] = (*tdf -> comp [j].func -> getCDist)(nd.vray, &tdf -> comp [j]);
1548            
1549            if (!cdarr [i + j])
1550               cdarr [i + j] = &SDemptyCD;
1551            else bsdfVal.cieY += cdarr [i + j] -> cTotal;
1552         }
1553        
1554         while (i-- > 0) {
1555            /* Sum up non-diffuse reflectance */
1556            cdarr [i] = (*rdf -> comp [i].func -> getCDist)(nd.vray, &rdf -> comp [i]);
1557            
1558            if (!cdarr [i])
1559               cdarr [i] = &SDemptyCD;
1560            else bsdfVal.cieY += cdarr [i] -> cTotal;
1561         }
1562        
1563         if (bsdfVal.cieY <= FTINY) {
1564            /* Don't bother sampling, just absorb photon */
1565            if (cdarr)
1566               free(cdarr);
1567            return 0;
1568         }      
1569        
1570         /* Insert direct and indirect photon hits if diffuse component */
1571         if (rhoDiff > FTINY || nd.sd -> tLamb.cieY > FTINY)
1572            addPhotons(rayIn);  
1573            
1574         xi = pmapRandom(rouletteState);
1575        
1576         if ((xi -= rhoDiff) <= 0) {
1577            /* Diffuse reflection */
1578            photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff);
1579            diffPhotonScatter(nd.pnorm, &rayOut);
1580         }
1581         else if ((xi -= nd.sd -> tLamb.cieY) <= 0) {
1582            /* Diffuse transmission */
1583            flipsurface(rayIn);
1584            photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff);
1585            bsdfVal.spec = nd.sd -> tLamb.spec;
1586            diffPhotonScatter(nd.pnorm, &rayOut);
1587         }
1588         else {
1589            int rayOutType;
1590            COLOR bsdfRGB;
1591              
1592            /* Non-diffuse CDF inversion (?) */
1593            for (i = 0; i < n && (xi -= cdarr [i] -> cTotal) > 0; i++);
1594            
1595            if (i >= n) {
1596               /* Absorbed -- photon went Deer Hunter */
1597               if (cdarr)
1598                  free(cdarr);
1599               return 0;
1600            }
1601
1602            if (i < nr) {
1603               /* Non-diffuse reflection */
1604               sdc = &rdf -> comp [i];
1605               rayOutType = PMAP_SPECREFL;
1606            }
1607            else {
1608               /* Non-diffuse transmission */
1609               sdc = &tdf -> comp [i - nr];
1610               rayOutType = PMAP_SPECTRANS;
1611            }
1612            
1613            /* Generate non-diff sample dir */
1614            VCOPY(rayOut.rdir, nd.vray);
1615            err = (*sdc -> func -> sampCDist)
1616                  (rayOut.rdir, pmapRandom(scatterState), cdarr [i]);              
1617            if (err)
1618               objerror(mat, USER, transSDError(SDEinternal));
1619
1620            /* Get colour */
1621            j = (*sdc -> func -> getBSDFs)(coef, rayOut.rdir, nd.vray, sdc);
1622            
1623            if (j <= 0) {
1624               sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
1625                       nd.sd -> name);
1626               objerror(mat, USER, transSDError(SDEinternal));
1627            }
1628            
1629            bsdfVal.spec = sdc -> cspec [0];
1630            rhoDiff = coef [0];
1631            
1632            while (--j) {
1633               c_cmix(&bsdfVal.spec, rhoDiff, &bsdfVal.spec, coef [j],
1634                      &sdc -> cspec [j]);
1635               rhoDiff += coef [j];
1636            }
1637            
1638            /* ? */
1639            c_ccvt(&bsdfVal.spec, C_CSXY + C_CSSPEC);
1640            ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1641            
1642            /* Xform outgoing dir to world coords */
1643            if ((err = SDmapDir(rayOut.rdir, nd.fromloc, rayOut.rdir))) {
1644               objerror(mat, USER, transSDError(err));
1645               return 0;
1646            }
1647            
1648            photonRay(rayIn, &rayOut, rayOutType, bsdfRGB);
1649         }
1650        
1651         if (cdarr)
1652            free(cdarr);
1653      }
1654                          
1655      /* Clean up BSDF */
1656      SDfreeCache(nd.sd);
1657
1658      tracePhoton(&rayOut);
1659      return 0;
1660   }
1661 #else
1662
1417   /*
1418 +   ==================================================================
1419     The following code is
1420     (c) Lucerne University of Applied Sciences and Arts,
1421     supported by the Swiss National Science Foundation (SNSF, #147053)
1422 +   ==================================================================
1423   */  
1424  
1425   static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
# Line 1677 | Line 1433 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1433     BSDFDAT      nd;
1434     RAY      rayOut;
1435     COLOR    bsdfRGB;
1436 +   int      transmitted;
1437     double   prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD,
1438 <            albedo, xi, xi2;
1439 <   const double patAlb = colorAvg(rayIn -> pcol);
1438 >            albedo, xi;
1439 >   const double patAlb = bright(rayIn -> pcol);
1440    
1441     /* Following code adapted from m_bsdf() */
1442     /* Check arguments */
# Line 1696 | Line 1453 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1453          nd.thick = evalue(mf -> ep [0]);
1454          if ((-FTINY <= nd.thick) & (nd.thick <= FTINY))
1455                  nd.thick = .0;
1699                
1700   if (nd.thick != .0 || (!hitFront && !backvis)) {
1701      /* Proxy geometry present, so use it instead and transfer ray */
1702      photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1703      tracePhoton(&rayOut);
1704      
1705      return 0;
1706   }
1456  
1457     /* Get BSDF data */
1458     nd.sd = loadBSDF(mat -> oargs.sarg [1]);
# Line 1817 | Line 1566 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1566     if (prDiff + ptDiff + prDiffSD + ptDiffSD > FTINY)
1567        addPhotons(rayIn);        
1568  
1569 <   xi = xi2 = pmapRandom(rouletteState);
1569 >   xi = pmapRandom(rouletteState);
1570        
1571     if (xi > albedo)
1572        /* Absorbtion */
1573        return 0;
1574    
1575 +   transmitted = 0;
1576 +
1577     if ((xi -= prDiff) <= 0) {
1578        /* Diffuse reflection (extra component in material def) */
1579        photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff);
# Line 1832 | Line 1583 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1583     else if ((xi -= ptDiff) <= 0) {
1584        /* Diffuse transmission (extra component in material def) */
1585        flipsurface(rayIn);
1586 +      nd.thick = -nd.thick;
1587        photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff);
1588 <      diffPhotonScatter(nd.pnorm, &rayOut);      
1588 >      diffPhotonScatter(nd.pnorm, &rayOut);
1589 >      transmitted = 1;
1590     }
1591 <  
1591 >  
1592     else {   /* Sample SDF */
1593        if ((xi -= prDiffSD) <= 0) {
1594           /* Diffuse SDF reflection (constant component) */
1595 <         if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2,
1595 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1596                                 SDsampDf | SDsampR, nd.sd)))
1597              objerror(mat, USER, transSDError(err));
1598          
# Line 1851 | Line 1604 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1604  
1605        else if ((xi -= ptDiffSD) <= 0) {
1606           /* Diffuse SDF transmission (constant component) */
1607 <         if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2,
1607 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1608                                 SDsampDf | SDsampT, nd.sd)))
1609              objerror(mat, USER, transSDError(err));
1610          
# Line 1860 | Line 1613 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1613           multcolor(bsdfRGB, rayIn -> pcol);
1614           addcolor(bsdfRGB, nd.tdiff);      
1615           flipsurface(rayIn);  /* Necessary? */
1616 +         nd.thick = -nd.thick;
1617           photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB);
1618 +         transmitted = 1;
1619        }
1620  
1621        else if ((xi -= prSpecSD) <= 0) {
1622           /* Non-diffuse ("specular") SDF reflection */
1623 <         if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2,
1623 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1624                                 SDsampSp | SDsampR, nd.sd)))
1625              objerror(mat, USER, transSDError(err));
1626          
# Line 1875 | Line 1630 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1630        
1631        else {
1632           /* Non-diffuse ("specular") SDF transmission */
1633 <         if ((err = SDsampBSDF(&bsdfVal, nd.vray, xi2,
1633 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1634                                 SDsampSp | SDsampT, nd.sd)))
1635              objerror(mat, USER, transSDError(err));
1636  
# Line 1883 | Line 1638 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1638           ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1639           multcolor(bsdfRGB, rayIn -> pcol);
1640           flipsurface(rayIn);  /* Necessary? */
1641 +         nd.thick = -nd.thick;
1642           photonRay(rayIn, &rayOut, PMAP_SPECTRANS, bsdfRGB);
1643 +         transmitted = 1;
1644        }      
1645        
1646        /* Xform outgoing dir to world coords */
# Line 1896 | Line 1653 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1653     /* Clean up */
1654     SDfreeCache(nd.sd);
1655  
1656 +   /* Need to offset ray origin to get past detail geometry? */
1657 +   if (transmitted && nd.thick != 0)
1658 +      VSUM(rayOut.rorg, rayOut.rorg, rayIn -> ron, -nd.thick);
1659 +
1660     tracePhoton(&rayOut);
1661     return 0;
1662   }
1902 #endif
1663  
1664  
1665  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines