ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/pmapcontrib.c
(Generate patch)

Comparing ray/src/rt/pmapcontrib.c (file contents):
Revision 2.1 by greg, Tue Feb 24 19:39:26 2015 UTC vs.
Revision 2.9 by greg, Tue Aug 18 18:45:55 2015 UTC

# Line 1 | Line 1
1 + #ifndef lint
2 + static const char RCSid[] = "$Id$";
3 + #endif
4   /*
5     ==================================================================
6     Photon map support for light source contributions
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  
9 >   (c) Lucerne University of Applied Sciences and Arts,
10 >   supported by the Swiss National Science Foundation (SNSF, #147053)
11     ==================================================================
12    
13     $Id$
# Line 20 | Line 23
23   #include "pmapdiag.h"
24   #include "rcontrib.h"
25   #include "otypes.h"
23 #include <signal.h>
26  
27  
28  
27 extern int contrib;     /* coeff/contrib flag */
28
29
30
29   static void setPmapContribParams (PhotonMap *pmap, LUTAB *srcContrib)
30   /* Set parameters for light source contributions */
31   {
# Line 56 | Line 54 | static void checkPmapContribs (const PhotonMap *pmap,
54        if (primary -> srcIdx < 0 || primary -> srcIdx >= nsources)
55           error(INTERNAL, "invalid light source index in photon map");
56          
57 <      srcMod = objptr(source [primary -> srcIdx].so -> omod);
57 >      srcMod = findmaterial(source [primary -> srcIdx].so);
58        if ((MODCONT*)lu_find(srcContrib, srcMod -> oname) -> data)
59           ++found;
60     }
# Line 104 | Line 102 | void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i
102     PhotonSQNode   *sq;
103     float          r, invArea;
104     RREAL          rayCoeff [3];
105 <   FVECT          rdir, rop;
108 <
105 >
106     setcolor(irrad, 0, 0, 0);
107  
108     if (!pmap -> maxGather)
# Line 116 | Line 113 | void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i
113        if (islight(objptr(ray -> ro -> omod) -> otype))
114           return;
115  
116 <   /* Set context for binning function evaluation and get cumulative path
116 >   /* Get cumulative path
117      * coefficient up to photon lookup point */
121   worldfunc(RCCONTEXT, ray);
118     raycontrib(rayCoeff, ray, PRIMARY);
119  
124   /* Save incident ray's direction and hitpoint */
125   VCOPY(rdir, ray -> rdir);
126   VCOPY(rop, ray -> rop);
127
120     /* Lookup photons */
121     pmap -> squeueEnd = 0;
122     findPhotons(pmap, ray);
# Line 165 | Line 157 | void photonContrib (PhotonMap *pmap, RAY *ray, COLOR i
157        if (pmap -> srcContrib) {
158           const PhotonPrimary *primary = pmap -> primary +
159                                          sq -> photon -> primary;
160 <         OBJREC *srcMod = objptr(source [primary -> srcIdx].so -> omod);
160 >         const SRCREC *sp = &source[primary -> srcIdx];
161 >         OBJREC *srcMod = findmaterial(sp -> so);
162           MODCONT *srcContrib = (MODCONT*)lu_find(pmap -> srcContrib,
163                                                   srcMod -> oname) -> data;
164 <        
165 <         if (srcContrib) {
173 <            /* Photon's emitting light source has modifier whose
174 <             * contributions are sought */
175 <            int srcBin;
164 >         if (!srcContrib)
165 >            continue;
166  
167 <            /* Set incident dir and origin of photon's primary ray on
168 <             * light source for dummy shadow ray, and evaluate binning
169 <             * function */
170 <            VCOPY(ray -> rdir, primary -> dir);
171 <            VCOPY(ray -> rop, primary -> org);
182 <            srcBin = evalue(srcContrib -> binv) + .5;
167 >         /* Photon's emitting light source has modifier whose
168 >          * contributions are sought */
169 >         double srcBinReal;
170 >         int srcBin;
171 >         RAY srcRay;
172  
173 <            if (srcBin < 0 || srcBin >= srcContrib -> nbins) {
174 <               error(WARNING, "bad bin number (ignored)");
175 <               continue;
176 <            }
173 >         if (srcContrib -> binv -> type != NUM) {
174 >            /* Use intersection function to set shadow ray parameters
175 >             * if it's not simply a constant
176 >             */
177 >            rayorigin(&srcRay, SHADOW, NULL, NULL);
178 >            srcRay.rsrc = primary -> srcIdx;
179 >            VCOPY(srcRay.rorg, primary -> pos);
180 >            decodedir(srcRay.rdir, primary -> dir);
181 >
182 >            if (!(sp->sflags & SDISTANT ? sourcehit(&srcRay)
183 >                        : (*ofun[sp -> so -> otype].funp)(sp -> so, &srcRay)))
184 >                continue;               /* XXX shouldn't happen! */
185 >
186 >            worldfunc(RCCONTEXT, &srcRay);
187 >            set_eparams((char *)srcContrib -> params);
188 >         }
189 >
190 >         if ((srcBinReal = evalue(srcContrib -> binv)) < -.5)
191 >             continue;          /* silently ignore negative bins */
192 >  
193 >         if ((srcBin = srcBinReal + .5) >= srcContrib -> nbins) {
194 >             error(WARNING, "bad bin number (ignored)");
195 >             continue;
196 >         }
197              
198 <            if (!contrib) {
199 <               /* Ray coefficient mode; normalise by light source radiance
200 <                * after applying distrib pattern */
201 <               int j;
202 <               raytexture(ray, srcMod -> omod);
203 <               setcolor(ray -> rcol, srcMod -> oargs.farg [0],
198 >         if (!contrib) {
199 >             /* Ray coefficient mode; normalise by light source radiance
200 >              * after applying distrib pattern */
201 >             int j;
202 >             raytexture(ray, srcMod -> omod);
203 >             setcolor(ray -> rcol, srcMod -> oargs.farg [0],
204                          srcMod -> oargs.farg [1], srcMod -> oargs.farg [2]);
205 <               multcolor(ray -> rcol, ray -> pcol);
206 <               for (j = 0; j < 3; j++)
207 <                  flux [j] = ray -> rcol [j] ? flux [j] / ray -> rcol [j]
205 >             multcolor(ray -> rcol, ray -> pcol);
206 >             for (j = 0; j < 3; j++)
207 >                flux [j] = ray -> rcol [j] ? flux [j] / ray -> rcol [j]
208                                               : 0;
209 <            }
209 >         }
210                      
211 <            multcolor(flux, rayCoeff);
212 <            addcolor(srcContrib -> cbin [srcBin], flux);
204 <         }
205 <         else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname);
211 >         multcolor(flux, rayCoeff);
212 >         addcolor(srcContrib -> cbin [srcBin], flux);
213        }
214     }
215 <  
209 <   /* Restore incident ray's direction and hitpoint */
210 <   VCOPY(ray -> rdir, rdir);
211 <   VCOPY(ray -> rop, rop);
212 <    
215 >        
216     return;
217   }
218  
# Line 269 | Line 272 | void distribPhotonContrib (PhotonMap* pm)
272  
273     /* Record start time and enable progress report signal handler */
274     repStartTime = time(NULL);
275 <   signal(SIGCONT, pmapDistribReport);
275 >   #ifdef SIGCONT  
276 >      signal(SIGCONT, pmapDistribReport);
277 >   #endif  
278    
279     for (srcIdx = 0; srcIdx < nsources; srcIdx++) {
280        unsigned portCnt = 0, passCnt = 0, prePassCnt = 0;
# Line 438 | Line 443 | void distribPhotonContrib (PhotonMap* pm)
443                       if (photonRepTime > 0 &&
444                           time(NULL) >= repLastTime + photonRepTime)
445                          pmapDistribReport();
446 <                     #ifndef BSD
446 >                     #ifdef SIGCONT
447                          else signal(SIGCONT, pmapDistribReport);
448                       #endif
449                    }
# Line 469 | Line 474 | void distribPhotonContrib (PhotonMap* pm)
474     /* ================================================================
475      * POST-DISTRIBUTION - Set photon flux and build kd-tree, etc.
476      * ================================================================ */
477 <   signal(SIGCONT, SIG_DFL);
477 >   #ifdef SIGCONT    
478 >      signal(SIGCONT, SIG_DFL);
479 >   #endif  
480     free(emap.samples);
481  
482     if (!pm -> heapEnd)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines