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.2 by greg, Tue Apr 21 19:16:51 2015 UTC vs.
Revision 2.8 by greg, Thu May 21 13:54:59 2015 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines