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.9 by greg, Tue Sep 1 16:27:52 2015 UTC vs.
Revision 2.16 by rschregle, Mon Jun 11 12:46:51 2018 UTC

# Line 106 | 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 >      /* Update maximum photon path distance */
129 >      rayOut -> rmax = rayIn -> rmax - rayIn -> rot;
130 >   }
131   }
132  
133  
# Line 132 | Line 137 | static void addPhotons (const RAY *r)
137   {
138     if (!r -> rlvl)
139        /* Add direct photon map at primary hitpoint */
140 <      addPhoton(directPmap, r);
140 >      newPhoton(directPmap, r);
141     else {
142        /* Add global or precomputed photon map at indirect hitpoint */
143 <      addPhoton(preCompPmap ? preCompPmap : globalPmap, r);
143 >      newPhoton(preCompPmap ? preCompPmap : globalPmap, r);
144  
145        /* Store caustic photon if specular flag set */
146        if (PMAP_CAUSTICRAY(r))
147 <         addPhoton(causticPmap, r);
147 >         newPhoton(causticPmap, r);
148          
149        /* Store in contribution photon map */
150 <      addPhoton(contribPmap, r);
150 >      newPhoton(contribPmap, r);
151     }
152   }
153  
# Line 978 | Line 983 | static int aliasPhotonScatter (OBJREC *mat, RAY *rayIn
983    
984     /* Straight replacement? */
985     if (!mat -> oargs.nsargs) {
986 <      mat = objptr(mat -> omod);
987 <      photonScatter [mat -> otype] (mat, rayIn);
986 >      /* Skip void modifier! */
987 >      if (mat -> omod != OVOID) {  
988 >         mat = objptr(mat -> omod);
989 >         photonScatter [mat -> otype] (mat, rayIn);
990 >      }
991        
992        return 0;
993     }
# Line 1250 | Line 1258 | static int mx_dataPhotonScatter (OBJREC *mat, RAY *ray
1258     if (errno)
1259        objerror(mat, WARNING, "compute error");
1260     else {
1261 <      mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]);
1262 <      photonScatter [mat -> otype] (mat, rayIn);
1261 >      OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1];
1262 >      
1263 >      if (mxMod != OVOID) {
1264 >         mat = objptr(mxMod);
1265 >         photonScatter [mat -> otype] (mat, rayIn);
1266 >      }
1267 >      else {
1268 >         /* Transfer ray if no modifier */
1269 >         RAY rayOut;
1270 >        
1271 >         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1272 >         tracePhoton(&rayOut);      
1273 >      }            
1274     }
1275    
1276     return 0;
# Line 1303 | Line 1322 | static int mx_pdataPhotonScatter (OBJREC *mat, RAY *ra
1322     if (errno)
1323        objerror(mat, WARNING, "compute error");
1324     else {
1325 <      mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]);
1326 <      photonScatter [mat -> otype] (mat, rayIn);
1325 >      OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1];
1326 >      
1327 >      if (mxMod != OVOID) {
1328 >         mat = objptr(mxMod);
1329 >         photonScatter [mat -> otype] (mat, rayIn);
1330 >      }
1331 >      else {
1332 >         /* Transfer ray if no modifier */
1333 >         RAY rayOut;
1334 >        
1335 >         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1336 >         tracePhoton(&rayOut);      
1337 >      }      
1338     }  
1339    
1340     return 0;
# Line 1343 | Line 1373 | static int mx_funcPhotonScatter (OBJREC *mat, RAY *ray
1373     if (errno)
1374        objerror(mat, WARNING, "compute error");
1375     else {        
1376 <      mat = objptr(mod [pmapRandom(rouletteState) < coef ? 0 : 1]);
1377 <      photonScatter [mat -> otype] (mat, rayIn);
1376 >      OBJECT mxMod = mod [pmapRandom(rouletteState) < coef ? 0 : 1];
1377 >      
1378 >      if (mxMod != OVOID) {
1379 >         mat = objptr(mxMod);
1380 >         photonScatter [mat -> otype] (mat, rayIn);
1381 >      }
1382 >      else {
1383 >         /* Transfer ray if no modifier */
1384 >         RAY rayOut;
1385 >        
1386 >         photonRay(rayIn, &rayOut, PMAP_XFER, NULL);
1387 >         tracePhoton(&rayOut);      
1388 >      }
1389     }
1390    
1391     return 0;
# Line 1406 | Line 1447 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1447         mat -> oargs.nfargs % 3)
1448        objerror(mat, USER, "bad # arguments");
1449        
1450 <        hitFront = (rayIn -> rod > 0);
1450 >   hitFront = (rayIn -> rod > 0);
1451  
1452 <        /* Load cal file */
1453 <        mf = getfunc(mat, 5, 0x1d, 1);
1413 <        
1414 <        /* Get thickness */
1415 <        nd.thick = evalue(mf -> ep [0]);
1416 <        if ((-FTINY <= nd.thick) & (nd.thick <= FTINY))
1417 <                nd.thick = .0;
1452 >   /* Load cal file */
1453 >   mf = getfunc(mat, 5, 0x1d, 1);
1454  
1455 +   /* Get thickness */
1456 +   nd.thick = evalue(mf -> ep [0]);
1457 +   if ((-FTINY <= nd.thick) & (nd.thick <= FTINY))
1458 +      nd.thick = .0;
1459 +
1460     /* Get BSDF data */
1461     nd.sd = loadBSDF(mat -> oargs.sarg [1]);
1462    
# Line 1438 | Line 1479 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1479     else setcolor(nd.rdiff, mat -> oargs.farg [3], mat -> oargs.farg [4],
1480                   mat -> oargs.farg [5]);
1481  
1482 <        /* Extra diffuse transmittance from material def */
1483 <        if (mat -> oargs.nfargs < 9)
1484 <           setcolor(nd.tdiff, .0, .0, .0);
1482 >   /* Extra diffuse transmittance from material def */
1483 >   if (mat -> oargs.nfargs < 9)
1484 >      setcolor(nd.tdiff, .0, .0, .0);
1485     else setcolor(nd.tdiff, mat -> oargs.farg [6], mat -> oargs.farg [7],
1486                   mat -> oargs.farg [8]);
1487                
1488     nd.mp = mat;
1489     nd.pr = rayIn;
1490 <        
1490 >
1491     /* Get modifiers */
1492     raytexture(rayIn, mat -> omod);
1493    
1494     /* Modify diffuse values */
1495     multcolor(nd.rdiff, rayIn -> pcol);
1496     multcolor(nd.tdiff, rayIn -> pcol);
1497 <                
1497 >
1498     /* Get up vector & xform to world coords */
1499     upvec [0] = evalue(mf -> ep [1]);
1500     upvec [1] = evalue(mf -> ep [2]);
# Line 1500 | Line 1541 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1541     nd.sr_vpsa [1] = sqrt(nd.sr_vpsa [1]);
1542  
1543     /* Orient perturbed normal towards incident side */
1544 <   if (!hitFront) {                    
1544 >   if (!hitFront) {
1545        nd.pnorm [0] = -nd.pnorm [0];
1546        nd.pnorm [1] = -nd.pnorm [1];
1547        nd.pnorm [2] = -nd.pnorm [2];
# Line 1544 | Line 1585 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1585    
1586     else if ((xi -= ptDiff) <= 0) {
1587        /* Diffuse transmission (extra component in material def) */
1547      flipsurface(rayIn);
1548      nd.thick = -nd.thick;
1588        photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, nd.tdiff);
1589        diffPhotonScatter(nd.pnorm, &rayOut);
1590        transmitted = 1;
# Line 1574 | Line 1613 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1613           ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1614           multcolor(bsdfRGB, rayIn -> pcol);
1615           addcolor(bsdfRGB, nd.tdiff);      
1577         flipsurface(rayIn);  /* Necessary? */
1578         nd.thick = -nd.thick;
1616           photonRay(rayIn, &rayOut, PMAP_DIFFTRANS, bsdfRGB);
1617           transmitted = 1;
1618        }
# Line 1599 | Line 1636 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1636           /* Apply pattern to spectral component */
1637           ccy2rgb(&bsdfVal.spec, bsdfVal.cieY, bsdfRGB);
1638           multcolor(bsdfRGB, rayIn -> pcol);
1602         flipsurface(rayIn);  /* Necessary? */
1603         nd.thick = -nd.thick;
1639           photonRay(rayIn, &rayOut, PMAP_SPECTRANS, bsdfRGB);
1640           transmitted = 1;
1641        }      
# Line 1615 | Line 1650 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1650     /* Clean up */
1651     SDfreeCache(nd.sd);
1652  
1653 <   /* Need to offset ray origin to get past detail geometry? */
1653 >   /* Offset outgoing photon origin by thickness to bypass proxy geometry */
1654     if (transmitted && nd.thick != 0)
1655        VSUM(rayOut.rorg, rayOut.rorg, rayIn -> ron, -nd.thick);
1656  
# Line 1626 | Line 1661 | static int bsdfPhotonScatter (OBJREC *mat, RAY *rayIn)
1661  
1662  
1663   static int lightPhotonScatter (OBJREC* mat, RAY* ray)
1664 < /* Light sources doan' reflect */
1664 > /* Light sources doan' reflect, mang */
1665   {
1666     return 0;
1667   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines