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.4 by rschregle, Fri May 8 13:20:23 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
# Line 23 | Line 26
26  
27  
28  
26 extern int contrib;     /* coeff/contrib flag */
27
28
29
29   static void setPmapContribParams (PhotonMap *pmap, LUTAB *srcContrib)
30   /* Set parameters for light source contributions */
31   {
# Line 55 | 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 103 | 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;
107 <
105 >
106     setcolor(irrad, 0, 0, 0);
107  
108     if (!pmap -> maxGather)
# Line 115 | 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 */
120   worldfunc(RCCONTEXT, ray);
118     raycontrib(rayCoeff, ray, PRIMARY);
119  
123   /* Save incident ray's direction and hitpoint */
124   VCOPY(rdir, ray -> rdir);
125   VCOPY(rop, ray -> rop);
126
120     /* Lookup photons */
121     pmap -> squeueEnd = 0;
122     findPhotons(pmap, ray);
# Line 164 | 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) {
172 <            /* Photon's emitting light source has modifier whose
173 <             * contributions are sought */
174 <            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);
181 <            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);
203 <         }
204 <         else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname);
211 >         multcolor(flux, rayCoeff);
212 >         addcolor(srcContrib -> cbin [srcBin], flux);
213        }
214     }
215 <  
208 <   /* Restore incident ray's direction and hitpoint */
209 <   VCOPY(ray -> rdir, rdir);
210 <   VCOPY(ray -> rop, rop);
211 <    
215 >        
216     return;
217   }
218  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines