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.1 by greg, Tue Feb 24 19:39:27 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.
7  
8     Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
9     (c) Fraunhofer Institute for Solar Energy Systems,
10 <       Lucerne University of Applied Sciences & Arts
10 >   (c) Lucerne University of Applied Sciences and Arts,
11 >   supported by the Swiss National Science Foundation (SNSF, #147053)
12     ==================================================================
13    
10   $Id$
14   */
15  
16  
# Line 103 | 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 normalised 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 129 | 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 198 | Line 203 | static int isoSpecPhotonScatter (NORMDAT *nd, RAY *ray
203     int      niter, i = 0;
204    
205     /* Set up sample coordinates */  
206 <   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 <  
206 >   getperpendicular(u, nd -> pnorm, 1);  
207     fcross(v, nd -> pnorm, u);
208    
209     if (nd -> specfl & SP_REFL) {
# Line 267 | Line 267 | static void diffPhotonScatter (FVECT normal, RAY* rayO
267     int         i = 0;
268  
269     /* Set up sample coordinates */
270 <   do {
271 <      v [0] = v [1] = v [2] = 0;
272 <      v [i++] = 1;
273 <      fcross(u, v, normal);
274 <   } while (normalize(u) < FTINY);
275 <  
270 >   getperpendicular(u, normal, 1);
271     fcross(v, normal, u);
272    
273     /* Convert theta & phi to cartesian */
# Line 323 | 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 752 | 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 899 | 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 985 | 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 1257 | 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 1310 | 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 1350 | 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 1383 | Line 1414 | static int pattexPhotonScatter (OBJREC *mat, RAY *rayI
1414  
1415  
1416  
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)
1426   /* Generate new photon ray for BSDF modifier and recurse. */
1427   {
1428     int      hitFront;
1429     SDError  err;
1430 +   SDValue  bsdfVal;
1431     FVECT           upvec;
1432     MFUNC           *mf;
1433     BSDFDAT      nd;
1434     RAY      rayOut;
1435 <
1435 >   COLOR    bsdfRGB;
1436 >   int      transmitted;
1437 >   double   prDiff, ptDiff, prDiffSD, ptDiffSD, prSpecSD, ptSpecSD,
1438 >            albedo, xi;
1439 >   const double patAlb = bright(rayIn -> pcol);
1440 >  
1441     /* Following code adapted from m_bsdf() */
1442     /* Check arguments */
1443     if (mat -> oargs.nsargs < 6 || mat -> oargs.nfargs > 9 ||
# Line 1408 | 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;
1411                
1412   if (nd.thick != .0 || (!hitFront && !backvis)) {
1413      /* Proxy geometry present, so use it instead and transfer ray */
1414      photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1415      tracePhoton(&rayOut);
1416      
1417      return 0;
1418   }
1456  
1457     /* Get BSDF data */
1458     nd.sd = loadBSDF(mat -> oargs.sarg [1]);
1459    
1460 <   /* Diffuse reflectance */
1460 >   /* Extra diffuse reflectance from material def */
1461     if (hitFront) {
1462        if (mat -> oargs.nfargs < 3)
1463           setcolor(nd.rdiff, .0, .0, .0);
# Line 1439 | Line 1476 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1476     else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4],
1477                   mat -> oargs.farg [5]);
1478  
1479 <        /* Diffuse transmittance */
1479 >        /* Extra diffuse transmittance from material def */
1480          if (mat -> oargs.nfargs < 9)
1481             setcolor(nd.tdiff, .0, .0, .0);
1482     else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7],
# Line 1506 | Line 1543 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1543        nd.pnorm [1] = -nd.pnorm [1];
1544        nd.pnorm [2] = -nd.pnorm [2];
1545     }
1546 <  
1547 <   /* Following code adapted from SDsampBSDF() */
1548 <   {
1549 <      SDSpectralDF   *rdf, *tdf;
1550 <      SDValue        bsdfVal;
1551 <      double         xi, rhoDiff = 0;
1552 <      float          coef [SDmaxCh];
1553 <      int            i, j, n, nr;
1554 <      SDComponent          *sdc;
1555 <      const SDCDst   **cdarr = NULL;
1556 <      
1557 <      /* Get diffuse albedo (?) */
1558 <      if (hitFront) {
1559 <         bsdfVal = nd.sd -> rLambFront;
1560 <         rdf = nd.sd -> rf;
1561 <         tdf = nd.sd -> tf ? nd.sd -> tf : nd.sd -> tb;
1562 <      }
1563 <      else {
1527 <         bsdfVal = nd.sd -> rLambBack;
1528 <         rdf = nd.sd -> rb;
1529 <         tdf = nd.sd -> tb ? nd.sd -> tb : nd.sd -> tf;
1530 <      }
1531 <      
1532 <      rhoDiff = bsdfVal.cieY;
1533 <      bsdfVal.cieY += nd.sd -> tLamb.cieY;
1534 <      
1535 <      /* Allocate non-diffuse sampling */
1536 <      i = nr = rdf ? rdf -> ncomp : 0;
1537 <      j = tdf ? tdf -> ncomp : 0;
1538 <      n = i + j;
1539 <      
1540 <      if (n > 0 && !(cdarr = (const SDCDst**)malloc(n * sizeof(SDCDst*))))
1541 <         objerror(mat, USER, transSDError(SDEmemory));
1546 >
1547 >   /* Get scatter probabilities (weighted by pattern except for spec refl)
1548 >    * prDiff, ptDiff:      extra diffuse component in material def
1549 >    * prDiffSD, ptDiffSD:  diffuse (constant) component in SDF
1550 >    * prSpecSD, ptSpecSD:  non-diffuse ("specular") component in SDF
1551 >    * albedo:              sum of above, inverse absorption probability */
1552 >   prDiff   = colorAvg(nd.rdiff);
1553 >   ptDiff   = colorAvg(nd.tdiff);
1554 >   prDiffSD = patAlb * SDdirectHemi(nd.vray, SDsampDf | SDsampR, nd.sd);
1555 >   ptDiffSD = patAlb * SDdirectHemi(nd.vray, SDsampDf | SDsampT, nd.sd);
1556 >   prSpecSD = SDdirectHemi(nd.vray, SDsampSp | SDsampR, nd.sd);
1557 >   ptSpecSD = patAlb * SDdirectHemi(nd.vray, SDsampSp | SDsampT, nd.sd);
1558 >   albedo   = prDiff + ptDiff + prDiffSD + ptDiffSD + prSpecSD + ptSpecSD;
1559 >
1560 >   /*    
1561 >   if (albedo > 1)
1562 >      objerror(mat, WARNING, "Invalid albedo");
1563 >   */
1564          
1565 <      while (j-- > 0) {
1566 <         /* Sum up non-diffuse transmittance */
1567 <         cdarr [i + j] = (*tdf -> comp [j].func -> getCDist)(nd.vray, &tdf -> comp [j]);
1568 <        
1569 <         if (!cdarr [i + j])
1548 <            cdarr [i + j] = &SDemptyCD;
1549 <         else bsdfVal.cieY += cdarr [i + j] -> cTotal;
1550 <      }
1565 >   /* Insert direct and indirect photon hits if diffuse component */
1566 >   if (prDiff + ptDiff + prDiffSD + ptDiffSD > FTINY)
1567 >      addPhotons(rayIn);        
1568 >
1569 >   xi = pmapRandom(rouletteState);
1570        
1571 <      while (i-- > 0) {
1572 <         /* Sum up non-diffuse reflectance */
1573 <         cdarr [i] = (*rdf -> comp [i].func -> getCDist)(nd.vray, &rdf -> comp [i]);
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);
1580 >      diffPhotonScatter(nd.pnorm, &rayOut);
1581 >   }
1582 >  
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);
1589 >      transmitted = 1;
1590 >   }
1591 >  
1592 >   else {   /* Sample SDF */
1593 >      if ((xi -= prDiffSD) <= 0) {
1594 >         /* Diffuse SDF reflection (constant component) */
1595 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1596 >                               SDsampDf | SDsampR, nd.sd)))
1597 >            objerror(mat, USER, transSDError(err));
1598          
1599 <         if (!cdarr [i])
1600 <            cdarr [i] = &SDemptyCD;
1601 <         else bsdfVal.cieY += cdarr [i] -> cTotal;
1599 >         /* Apply pattern to spectral component */
1600 >         ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1601 >         multcolor(bsdfRGB, rayIn -> pcol);
1602 >         photonRay(rayIn, &rayOut, PMAP_DIFFREFL, bsdfRGB);
1603        }
1560      
1561      if (bsdfVal.cieY <= FTINY) {
1562         /* Don't bother sampling, just absorb photon */
1563         if (cdarr)
1564            free(cdarr);
1565         return 0;
1566      }      
1567      
1568      /* Insert direct and indirect photon hits if diffuse component */
1569      if (rhoDiff > FTINY || nd.sd -> tLamb.cieY > FTINY)
1570         addPhotons(rayIn);    
1571        
1572      xi = pmapRandom(rouletteState);
1573      
1574      if ((xi -= rhoDiff) <= 0) {
1575         /* Diffuse reflection */
1576         photonRay(rayIn, &rayOut, PMAP_DIFFREFL, nd.rdiff);
1577         diffPhotonScatter(nd.pnorm, &rayOut);
1578      }
1579      else if ((xi -= nd.sd -> tLamb.cieY) <= 0) {
1580         /* Diffuse transmission */
1581         flipsurface(rayIn);
1582         photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff);
1583         bsdfVal.spec = nd.sd -> tLamb.spec;
1584         diffPhotonScatter(nd.pnorm, &rayOut);
1585      }
1586      else {
1587         int rayOutType;
1588         COLOR bsdfRGB;
1589            
1590         /* Non-diffuse CDF inversion (?) */
1591         for (i = 0; i < n && (xi -= cdarr [i] -> cTotal) > 0; i++);
1592        
1593         if (i >= n) {
1594            /* Absorbed -- photon went Deer Hunter */
1595            if (cdarr)
1596               free(cdarr);
1597            return 0;
1598         }
1604  
1605 <         if (i < nr) {
1606 <            /* Non-diffuse reflection */
1607 <            sdc = &rdf -> comp [i];
1608 <            rayOutType = PMAP_SPECREFL;
1609 <         }
1605 <         else {
1606 <            /* Non-diffuse transmission */
1607 <            sdc = &tdf -> comp [i - nr];
1608 <            rayOutType = PMAP_SPECTRANS;
1609 <         }
1605 >      else if ((xi -= ptDiffSD) <= 0) {
1606 >         /* Diffuse SDF transmission (constant component) */
1607 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1608 >                               SDsampDf | SDsampT, nd.sd)))
1609 >            objerror(mat, USER, transSDError(err));
1610          
1611 <         /* Generate non-diff sample dir */
1612 <         VCOPY(rayOut.rdir, nd.vray);
1613 <         err = (*sdc -> func -> sampCDist)
1614 <               (rayOut.rdir, pmapRandom(scatterState), cdarr [i]);              
1615 <         if (err)
1616 <            objerror(mat, USER, transSDError(SDEinternal));
1617 <
1618 <         /* Get colour */
1619 <         j = (*sdc -> func -> getBSDFs)(coef, rayOut.rdir, nd.vray, sdc);
1620 <        
1621 <         if (j <= 0) {
1622 <            sprintf(SDerrorDetail, "BSDF \"%s\" sampling value error",
1623 <                    nd.sd -> name);
1624 <            objerror(mat, USER, transSDError(SDEinternal));
1625 <         }
1626 <        
1627 <         bsdfVal.spec = sdc -> cspec [0];
1628 <         rhoDiff = coef [0];
1629 <        
1630 <         while (--j) {
1631 <            c_cmix(&bsdfVal.spec, rhoDiff, &bsdfVal.spec, coef [j],
1632 <                   &sdc -> cspec [j]);
1633 <            rhoDiff += coef [j];
1634 <         }
1635 <        
1636 <         /* ? */
1637 <         c_ccvt(&bsdfVal.spec, C_CSXY + C_CSSPEC);
1611 >         /* Apply pattern to spectral component */
1612           ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1613 <        
1614 <         /* Xform outgoing dir to world coords */
1615 <         if ((err = SDmapDir(rayOut.rdir, nd.fromloc, rayOut.rdir))) {
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, pmapRandom(scatterState),
1624 >                               SDsampSp | SDsampR, nd.sd)))
1625              objerror(mat, USER, transSDError(err));
1643            return 0;
1644         }
1626          
1627 <         photonRay(rayIn, &rayOut, rayOutType, bsdfRGB);
1627 >         ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1628 >         photonRay(rayIn, &rayOut, PMAP_SPECREFL, bsdfRGB);
1629        }
1630        
1631 <      if (cdarr)
1632 <         free(cdarr);
1631 >      else {
1632 >         /* Non-diffuse ("specular") SDF transmission */
1633 >         if ((err = SDsampBSDF(&bsdfVal, nd.vray, pmapRandom(scatterState),
1634 >                               SDsampSp | SDsampT, nd.sd)))
1635 >            objerror(mat, USER, transSDError(err));
1636 >
1637 >         /* Apply pattern to spectral component */
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 */
1647 >      if ((err = SDmapDir(rayOut.rdir, nd.fromloc, nd.vray))) {
1648 >         objerror(mat, USER, transSDError(err));
1649 >         return 0;
1650 >      }
1651     }
1652 <                        
1653 <   /* Clean up BSDF */
1652 >      
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines