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.3 by rschregle, Wed Apr 22 20:28:16 2015 UTC vs.
Revision 2.10 by greg, Tue Sep 1 16:27:52 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    
10   $Id$
13   */
14  
15  
# Line 23 | Line 25
25  
26  
27  
26 extern int contrib;     /* coeff/contrib flag */
27
28
29
28   static void setPmapContribParams (PhotonMap *pmap, LUTAB *srcContrib)
29   /* Set parameters for light source contributions */
30   {
# Line 55 | 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 103 | 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;
107 <
104 >
105     setcolor(irrad, 0, 0, 0);
106  
107     if (!pmap -> maxGather)
# Line 115 | 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 */
120   worldfunc(RCCONTEXT, ray);
117     raycontrib(rayCoeff, ray, PRIMARY);
118  
123   /* Save incident ray's direction and hitpoint */
124   VCOPY(rdir, ray -> rdir);
125   VCOPY(rop, ray -> rop);
126
119     /* Lookup photons */
120     pmap -> squeueEnd = 0;
121     findPhotons(pmap, ray);
# Line 164 | 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) {
172 <            /* Photon's emitting light source has modifier whose
173 <             * contributions are sought */
174 <            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);
181 <            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 >             */
176 >            rayorigin(&srcRay, SHADOW, NULL, NULL);
177 >            srcRay.rsrc = primary -> srcIdx;
178 >            VCOPY(srcRay.rorg, primary -> pos);
179 >            decodedir(srcRay.rdir, primary -> dir);
180 >
181 >            if (!(sp->sflags & SDISTANT ? 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],
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]
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;
208 <            }
208 >         }
209                      
210 <            multcolor(flux, rayCoeff);
211 <            addcolor(srcContrib -> cbin [srcBin], flux);
203 <         }
204 <         else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname);
210 >         multcolor(flux, rayCoeff);
211 >         addcolor(srcContrib -> cbin [srcBin], flux);
212        }
213     }
214 <  
208 <   /* Restore incident ray's direction and hitpoint */
209 <   VCOPY(ray -> rdir, rdir);
210 <   VCOPY(ray -> rop, rop);
211 <    
214 >        
215     return;
216   }
217  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines