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.6 by greg, Wed May 20 13:43:28 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 20 | Line 20
20   #include "pmapdiag.h"
21   #include "rcontrib.h"
22   #include "otypes.h"
23 #include <signal.h>
23  
24  
25  
27 extern int contrib;     /* coeff/contrib flag */
28
29
30
26   static void setPmapContribParams (PhotonMap *pmap, LUTAB *srcContrib)
27   /* Set parameters for light source contributions */
28   {
# Line 104 | 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;
108 <
102 >
103     setcolor(irrad, 0, 0, 0);
104  
105     if (!pmap -> maxGather)
# Line 116 | 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 */
121   worldfunc(RCCONTEXT, ray);
115     raycontrib(rayCoeff, ray, PRIMARY);
116  
124   /* Save incident ray's direction and hitpoint */
125   VCOPY(rdir, ray -> rdir);
126   VCOPY(rop, ray -> rop);
127
117     /* Lookup photons */
118     pmap -> squeueEnd = 0;
119     findPhotons(pmap, ray);
# Line 165 | 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 >         SRCREC *sp = &source[primary -> srcIdx];
158 >         OBJREC *srcMod = objptr(sp -> so -> omod);
159           MODCONT *srcContrib = (MODCONT*)lu_find(pmap -> srcContrib,
160                                                   srcMod -> oname) -> data;
161 <        
162 <         if (srcContrib) {
173 <            /* Photon's emitting light source has modifier whose
174 <             * contributions are sought */
175 <            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);
182 <            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 >            VCOPY(srcRay.rdir, primary -> dir);
178 >            if (!(source [primary -> srcIdx].sflags & SDISTANT ?
179 >                        sourcehit(&srcRay) :
180 >                        (*ofun[sp -> so -> otype].funp)(sp -> so, &srcRay)))
181 >                continue;               /* XXX shouldn't happen! */
182 >            worldfunc(RCCONTEXT, &srcRay);
183 >            set_eparams((char *)srcContrib -> params);
184 >         }
185 >
186 >         if ((srcBinReal = evalue(srcContrib -> binv)) < -.5)
187 >             continue;          /* silently ignore negative bins */
188 >  
189 >         if ((srcBin = srcBinReal + .5) >= srcContrib -> nbins) {
190 >             error(WARNING, "bad bin number (ignored)");
191 >             continue;
192 >         }
193              
194 <            if (!contrib) {
195 <               /* Ray coefficient mode; normalise by light source radiance
196 <                * after applying distrib pattern */
197 <               int j;
198 <               raytexture(ray, srcMod -> omod);
199 <               setcolor(ray -> rcol, srcMod -> oargs.farg [0],
194 >         if (!contrib) {
195 >             /* Ray coefficient mode; normalise by light source radiance
196 >              * after applying distrib pattern */
197 >             int j;
198 >             raytexture(ray, srcMod -> omod);
199 >             setcolor(ray -> rcol, srcMod -> oargs.farg [0],
200                          srcMod -> oargs.farg [1], srcMod -> oargs.farg [2]);
201 <               multcolor(ray -> rcol, ray -> pcol);
202 <               for (j = 0; j < 3; j++)
203 <                  flux [j] = ray -> rcol [j] ? flux [j] / ray -> rcol [j]
201 >             multcolor(ray -> rcol, ray -> pcol);
202 >             for (j = 0; j < 3; j++)
203 >                flux [j] = ray -> rcol [j] ? flux [j] / ray -> rcol [j]
204                                               : 0;
205 <            }
205 >         }
206                      
207 <            multcolor(flux, rayCoeff);
208 <            addcolor(srcContrib -> cbin [srcBin], flux);
204 <         }
205 <         else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname);
207 >         multcolor(flux, rayCoeff);
208 >         addcolor(srcContrib -> cbin [srcBin], flux);
209        }
210     }
211 <  
209 <   /* Restore incident ray's direction and hitpoint */
210 <   VCOPY(ray -> rdir, rdir);
211 <   VCOPY(ray -> rop, rop);
212 <    
211 >        
212     return;
213   }
214  
# Line 269 | Line 268 | void distribPhotonContrib (PhotonMap* pm)
268  
269     /* Record start time and enable progress report signal handler */
270     repStartTime = time(NULL);
271 <   signal(SIGCONT, pmapDistribReport);
271 >   #ifdef SIGCONT  
272 >      signal(SIGCONT, pmapDistribReport);
273 >   #endif  
274    
275     for (srcIdx = 0; srcIdx < nsources; srcIdx++) {
276        unsigned portCnt = 0, passCnt = 0, prePassCnt = 0;
# Line 438 | Line 439 | void distribPhotonContrib (PhotonMap* pm)
439                       if (photonRepTime > 0 &&
440                           time(NULL) >= repLastTime + photonRepTime)
441                          pmapDistribReport();
442 <                     #ifndef BSD
442 >                     #ifdef SIGCONT
443                          else signal(SIGCONT, pmapDistribReport);
444                       #endif
445                    }
# Line 469 | Line 470 | void distribPhotonContrib (PhotonMap* pm)
470     /* ================================================================
471      * POST-DISTRIBUTION - Set photon flux and build kd-tree, etc.
472      * ================================================================ */
473 <   signal(SIGCONT, SIG_DFL);
473 >   #ifdef SIGCONT    
474 >      signal(SIGCONT, SIG_DFL);
475 >   #endif  
476     free(emap.samples);
477  
478     if (!pm -> heapEnd)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines