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.6 by greg, Wed May 20 13:43:28 2015 UTC

# 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 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 >         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) {
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 >            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);
203 <         }
204 <         else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname);
207 >         multcolor(flux, rayCoeff);
208 >         addcolor(srcContrib -> cbin [srcBin], flux);
209        }
210     }
211 <  
208 <   /* Restore incident ray's direction and hitpoint */
209 <   VCOPY(ray -> rdir, rdir);
210 <   VCOPY(ray -> rop, rop);
211 <    
211 >        
212     return;
213   }
214  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines