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$ |
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 |
|
{ |
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) |
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); |
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) { |
163 |
|
/* Photon's emitting light source has modifier whose |
164 |
|
* contributions are sought */ |
165 |
+ |
double srcBinReal; |
166 |
|
int srcBin; |
167 |
+ |
RAY srcRay; |
168 |
|
|
169 |
< |
/* Set incident dir and origin of photon's primary ray on |
170 |
< |
* light source for dummy shadow ray, and evaluate binning |
171 |
< |
* function */ |
172 |
< |
VCOPY(ray -> rdir, primary -> dir); |
173 |
< |
VCOPY(ray -> rop, primary -> org); |
174 |
< |
srcBin = evalue(srcContrib -> binv) + .5; |
175 |
< |
|
176 |
< |
if (srcBin < 0 || srcBin >= srcContrib -> nbins) { |
169 |
> |
if (srcContrib -> binv -> type != NUM) { |
170 |
> |
/* Use intersection function to set shadow ray parameters |
171 |
> |
*/ |
172 |
> |
rayorigin(&srcRay, SHADOW, NULL, NULL); |
173 |
> |
srcRay.rsrc = primary -> srcIdx; |
174 |
> |
VCOPY(srcRay.rorg, primary -> pos); |
175 |
> |
VCOPY(srcRay.rdir, primary -> dir); |
176 |
> |
if (!(source [primary -> srcIdx].sflags & SDISTANT ? |
177 |
> |
sourcehit(&srcRay) : |
178 |
> |
(*ofun[sp -> so -> otype].funp)(sp -> so, &srcRay))) |
179 |
> |
continue; /* XXX shouldn't happen! */ |
180 |
> |
worldfunc(RCCONTEXT, &srcRay); |
181 |
> |
set_eparams((char *)srcContrib -> params); |
182 |
> |
} |
183 |
> |
if ((srcBinReal = evalue(srcContrib -> binv)) < -.5) |
184 |
> |
continue; /* silently ignore negative bins */ |
185 |
> |
|
186 |
> |
if ((srcBin = srcBinReal + .5) >= srcContrib -> nbins) { |
187 |
|
error(WARNING, "bad bin number (ignored)"); |
188 |
|
continue; |
189 |
|
} |
207 |
|
else fprintf(stderr, "Skipped contrib from %s\n", srcMod -> oname); |
208 |
|
} |
209 |
|
} |
210 |
< |
|
208 |
< |
/* Restore incident ray's direction and hitpoint */ |
209 |
< |
VCOPY(ray -> rdir, rdir); |
210 |
< |
VCOPY(ray -> rop, rop); |
211 |
< |
|
210 |
> |
|
211 |
|
return; |
212 |
|
} |
213 |
|
|