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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines