--- ray/src/rt/pmapcontrib.c 2015/04/21 19:16:51 2.2 +++ ray/src/rt/pmapcontrib.c 2015/05/20 14:44:12 2.7 @@ -3,11 +3,11 @@ Photon map support for light source contributions Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) - (c) Fraunhofer Institute for Solar Energy Systems, - Lucerne University of Applied Sciences & Arts + (c) Lucerne University of Applied Sciences and Arts, + supported by the Swiss National Science Foundation (SNSF, #147053) ================================================================== - $Id: pmapcontrib.c,v 2.2 2015/04/21 19:16:51 greg Exp $ + $Id: pmapcontrib.c,v 2.7 2015/05/20 14:44:12 greg Exp $ */ @@ -23,10 +23,6 @@ -extern int contrib; /* coeff/contrib flag */ - - - static void setPmapContribParams (PhotonMap *pmap, LUTAB *srcContrib) /* Set parameters for light source contributions */ { @@ -103,8 +99,7 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i PhotonSQNode *sq; float r, invArea; RREAL rayCoeff [3]; - FVECT rdir, rop; - + setcolor(irrad, 0, 0, 0); if (!pmap -> maxGather) @@ -115,15 +110,10 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i if (islight(objptr(ray -> ro -> omod) -> otype)) return; - /* Set context for binning function evaluation and get cumulative path + /* Get cumulative path * coefficient up to photon lookup point */ - worldfunc(RCCONTEXT, ray); raycontrib(rayCoeff, ray, PRIMARY); - /* Save incident ray's direction and hitpoint */ - VCOPY(rdir, ray -> rdir); - VCOPY(rop, ray -> rop); - /* Lookup photons */ pmap -> squeueEnd = 0; findPhotons(pmap, ray); @@ -164,51 +154,62 @@ void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i if (pmap -> srcContrib) { const PhotonPrimary *primary = pmap -> primary + sq -> photon -> primary; - OBJREC *srcMod = objptr(source [primary -> srcIdx].so -> omod); + const SRCREC *sp = &source[primary -> srcIdx]; + OBJREC *srcMod = objptr(sp -> so -> omod); MODCONT *srcContrib = (MODCONT*)lu_find(pmap -> srcContrib, srcMod -> oname) -> data; - - if (srcContrib) { - /* Photon's emitting light source has modifier whose - * contributions are sought */ - int srcBin; + if (!srcContrib) + continue; - /* Set incident dir and origin of photon's primary ray on - * light source for dummy shadow ray, and evaluate binning - * function */ - VCOPY(ray -> rdir, primary -> dir); - VCOPY(ray -> rop, primary -> org); - srcBin = evalue(srcContrib -> binv) + .5; + /* Photon's emitting light source has modifier whose + * contributions are sought */ + double srcBinReal; + int srcBin; + RAY srcRay; - if (srcBin < 0 || srcBin >= srcContrib -> nbins) { - error(WARNING, "bad bin number (ignored)"); - continue; - } + if (srcContrib -> binv -> type != NUM) { + /* Use intersection function to set shadow ray parameters + * if it's not simply a constant + */ + rayorigin(&srcRay, SHADOW, NULL, NULL); + srcRay.rsrc = primary -> srcIdx; + VCOPY(srcRay.rorg, primary -> pos); + decodedir(srcRay.rdir, primary -> dir); + + if (!(sp->sflags & SDISTANT ? sourcehit(&srcRay) + : (*ofun[sp -> so -> otype].funp)(sp -> so, &srcRay))) + continue; /* XXX shouldn't happen! */ + + worldfunc(RCCONTEXT, &srcRay); + set_eparams((char *)srcContrib -> params); + } + + if ((srcBinReal = evalue(srcContrib -> binv)) < -.5) + continue; /* silently ignore negative bins */ + + if ((srcBin = srcBinReal + .5) >= srcContrib -> nbins) { + error(WARNING, "bad bin number (ignored)"); + continue; + } - if (!contrib) { - /* Ray coefficient mode; normalise by light source radiance - * after applying distrib pattern */ - int j; - raytexture(ray, srcMod -> omod); - setcolor(ray -> rcol, srcMod -> oargs.farg [0], + if (!contrib) { + /* Ray coefficient mode; normalise by light source radiance + * after applying distrib pattern */ + int j; + raytexture(ray, srcMod -> omod); + setcolor(ray -> rcol, srcMod -> oargs.farg [0], srcMod -> oargs.farg [1], srcMod -> oargs.farg [2]); - multcolor(ray -> rcol, ray -> pcol); - for (j = 0; j < 3; j++) - flux [j] = ray -> rcol [j] ? flux [j] / ray -> rcol [j] + multcolor(ray -> rcol, ray -> pcol); + for (j = 0; j < 3; j++) + flux [j] = ray -> rcol [j] ? flux [j] / ray -> rcol [j] : 0; - } + } - multcolor(flux, rayCoeff); - addcolor(srcContrib -> cbin [srcBin], flux); - } - else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname); + multcolor(flux, rayCoeff); + addcolor(srcContrib -> cbin [srcBin], flux); } } - - /* Restore incident ray's direction and hitpoint */ - VCOPY(ray -> rdir, rdir); - VCOPY(ray -> rop, rop); - + return; } @@ -268,7 +269,9 @@ void distribPhotonContrib (PhotonMap* pm) /* Record start time and enable progress report signal handler */ repStartTime = time(NULL); - signal(SIGCONT, pmapDistribReport); + #ifdef SIGCONT + signal(SIGCONT, pmapDistribReport); + #endif for (srcIdx = 0; srcIdx < nsources; srcIdx++) { unsigned portCnt = 0, passCnt = 0, prePassCnt = 0; @@ -437,7 +440,7 @@ void distribPhotonContrib (PhotonMap* pm) if (photonRepTime > 0 && time(NULL) >= repLastTime + photonRepTime) pmapDistribReport(); - #ifndef BSD + #ifdef SIGCONT else signal(SIGCONT, pmapDistribReport); #endif } @@ -468,7 +471,9 @@ void distribPhotonContrib (PhotonMap* pm) /* ================================================================ * POST-DISTRIBUTION - Set photon flux and build kd-tree, etc. * ================================================================ */ - signal(SIGCONT, SIG_DFL); + #ifdef SIGCONT + signal(SIGCONT, SIG_DFL); + #endif free(emap.samples); if (!pm -> heapEnd)