45 |
|
#include "pmapkdt.c" |
46 |
|
#endif |
47 |
|
|
48 |
+ |
/* Ambient include/exclude set (from ambient.c) */ |
49 |
+ |
#ifndef MAXASET |
50 |
+ |
#define MAXASET 4095 |
51 |
+ |
#endif |
52 |
+ |
extern OBJECT ambset [MAXASET+1]; |
53 |
|
|
54 |
|
|
55 |
+ |
|
56 |
|
void initPhotonMap (PhotonMap *pmap, PhotonMapType t) |
57 |
|
/* Init photon map 'n' stuff... */ |
58 |
|
{ |
202 |
|
|
203 |
|
int newPhoton (PhotonMap* pmap, const RAY* ray) |
204 |
|
{ |
205 |
< |
unsigned i, inROI = 0; |
205 |
> |
unsigned i; |
206 |
|
Photon photon; |
207 |
|
COLOR photonFlux; |
208 |
|
|
214 |
|
if (ray -> robj > -1 && islight(objptr(ray -> ro -> omod) -> otype)) |
215 |
|
return -1; |
216 |
|
|
217 |
< |
/* Store photon if within a region of interest (for ze Ecksperts!) */ |
218 |
< |
if (!pmapNumROI || !pmapROI) |
219 |
< |
inROI = 1; |
220 |
< |
else { |
217 |
> |
/* Ignore photon if modifier in/outside exclude/include set */ |
218 |
> |
if (ambincl != -1 && ray -> ro && |
219 |
> |
ambincl != inset(ambset, ray -> ro -> omod)) |
220 |
> |
return -1; |
221 |
> |
|
222 |
> |
if (pmapNumROI && pmapROI) { |
223 |
> |
unsigned inROI = 0; |
224 |
> |
|
225 |
> |
/* Store photon if within a region of interest (for ze Ecksperts!) */ |
226 |
|
for (i = 0; !inROI && i < pmapNumROI; i++) |
227 |
|
inROI = (ray -> rop [0] >= pmapROI [i].min [0] && |
228 |
|
ray -> rop [0] <= pmapROI [i].max [0] && |
230 |
|
ray -> rop [1] <= pmapROI [i].max [1] && |
231 |
|
ray -> rop [2] >= pmapROI [i].min [2] && |
232 |
|
ray -> rop [2] <= pmapROI [i].max [2]); |
233 |
+ |
if (!inROI) |
234 |
+ |
return -1; |
235 |
|
} |
236 |
< |
|
237 |
< |
if (inROI) { |
238 |
< |
/* Adjust flux according to distribution ratio and ray weight */ |
239 |
< |
copycolor(photonFlux, ray -> rcol); |
240 |
< |
scalecolor(photonFlux, |
241 |
< |
ray -> rweight / (pmap -> distribRatio ? pmap -> distribRatio |
242 |
< |
: 1)); |
230 |
< |
setPhotonFlux(&photon, photonFlux); |
231 |
< |
|
232 |
< |
/* Set photon position and flags */ |
233 |
< |
VCOPY(photon.pos, ray -> rop); |
234 |
< |
photon.flags = 0; |
235 |
< |
photon.caustic = PMAP_CAUSTICRAY(ray); |
236 |
> |
|
237 |
> |
/* Adjust flux according to distribution ratio and ray weight */ |
238 |
> |
copycolor(photonFlux, ray -> rcol); |
239 |
> |
scalecolor(photonFlux, |
240 |
> |
ray -> rweight / (pmap -> distribRatio ? pmap -> distribRatio |
241 |
> |
: 1)); |
242 |
> |
setPhotonFlux(&photon, photonFlux); |
243 |
|
|
244 |
< |
/* Set contrib photon's primary ray and subprocess index (the latter |
245 |
< |
* to linearise the primary ray indices after photon distribution is |
246 |
< |
* complete). Also set primary ray's source index, thereby marking it |
247 |
< |
* as used. */ |
241 |
< |
if (isContribPmap(pmap)) { |
242 |
< |
photon.primary = pmap -> numPrimary; |
243 |
< |
photon.proc = PMAP_GETRAYPROC(ray); |
244 |
< |
pmap -> lastPrimary.srcIdx = ray -> rsrc; |
245 |
< |
} |
246 |
< |
else photon.primary = 0; |
247 |
< |
|
248 |
< |
/* Set normal */ |
249 |
< |
for (i = 0; i <= 2; i++) |
250 |
< |
photon.norm [i] = 127.0 * (isVolumePmap(pmap) ? ray -> rdir [i] |
251 |
< |
: ray -> ron [i]); |
244 |
> |
/* Set photon position and flags */ |
245 |
> |
VCOPY(photon.pos, ray -> rop); |
246 |
> |
photon.flags = 0; |
247 |
> |
photon.caustic = PMAP_CAUSTICRAY(ray); |
248 |
|
|
249 |
< |
if (!pmap -> heapBuf) { |
250 |
< |
/* Lazily allocate heap buffa */ |
249 |
> |
/* Set contrib photon's primary ray and subprocess index (the latter |
250 |
> |
* to linearise the primary ray indices after photon distribution is |
251 |
> |
* complete). Also set primary ray's source index, thereby marking it |
252 |
> |
* as used. */ |
253 |
> |
if (isContribPmap(pmap)) { |
254 |
> |
photon.primary = pmap -> numPrimary; |
255 |
> |
photon.proc = PMAP_GETRAYPROC(ray); |
256 |
> |
pmap -> lastPrimary.srcIdx = ray -> rsrc; |
257 |
> |
} |
258 |
> |
else photon.primary = 0; |
259 |
> |
|
260 |
> |
/* Set normal */ |
261 |
> |
for (i = 0; i <= 2; i++) |
262 |
> |
photon.norm [i] = 127.0 * (isVolumePmap(pmap) ? ray -> rdir [i] |
263 |
> |
: ray -> ron [i]); |
264 |
> |
|
265 |
> |
if (!pmap -> heapBuf) { |
266 |
> |
/* Lazily allocate heap buffa */ |
267 |
|
#if NIX |
268 |
< |
/* Randomise buffa size to temporally decorellate flushes in |
269 |
< |
* multiprocessing mode */ |
270 |
< |
srandom(randSeed + getpid()); |
271 |
< |
pmap -> heapBufSize = PMAP_HEAPBUFSIZE * (0.5 + frandom()); |
268 |
> |
/* Randomise buffa size to temporally decorellate flushes in |
269 |
> |
* multiprocessing mode */ |
270 |
> |
srandom(randSeed + getpid()); |
271 |
> |
pmap -> heapBufSize = PMAP_HEAPBUFSIZE * (0.5 + frandom()); |
272 |
|
#else |
273 |
< |
/* Randomisation disabled for single processes on WIN; also useful |
274 |
< |
* for reproducability during debugging */ |
275 |
< |
pmap -> heapBufSize = PMAP_HEAPBUFSIZE; |
273 |
> |
/* Randomisation disabled for single processes on WIN; also useful |
274 |
> |
* for reproducability during debugging */ |
275 |
> |
pmap -> heapBufSize = PMAP_HEAPBUFSIZE; |
276 |
|
#endif |
277 |
< |
if (!(pmap -> heapBuf = calloc(pmap -> heapBufSize, sizeof(Photon)))) |
278 |
< |
error(SYSTEM, "failed heap buffer allocation in newPhoton"); |
279 |
< |
pmap -> heapBufLen = 0; |
280 |
< |
} |
277 |
> |
if (!(pmap -> heapBuf = calloc(pmap -> heapBufSize, sizeof(Photon)))) |
278 |
> |
error(SYSTEM, "failed heap buffer allocation in newPhoton"); |
279 |
> |
pmap -> heapBufLen = 0; |
280 |
> |
} |
281 |
|
|
282 |
< |
/* Photon initialised; now append to heap buffa */ |
283 |
< |
memcpy(pmap -> heapBuf + pmap -> heapBufLen, &photon, sizeof(Photon)); |
284 |
< |
|
285 |
< |
if (++pmap -> heapBufLen >= pmap -> heapBufSize) |
286 |
< |
/* Heap buffa full, flush to heap file */ |
287 |
< |
flushPhotonHeap(pmap); |
282 |
> |
/* Photon initialised; now append to heap buffa */ |
283 |
> |
memcpy(pmap -> heapBuf + pmap -> heapBufLen, &photon, sizeof(Photon)); |
284 |
> |
|
285 |
> |
if (++pmap -> heapBufLen >= pmap -> heapBufSize) |
286 |
> |
/* Heap buffa full, flush to heap file */ |
287 |
> |
flushPhotonHeap(pmap); |
288 |
|
|
289 |
< |
pmap -> numPhotons++; |
278 |
< |
} |
289 |
> |
pmap -> numPhotons++; |
290 |
|
|
291 |
|
return 0; |
292 |
|
} |
383 |
|
/* Scale photon's flux (hitherto normalised to 1 over RGB); in |
384 |
|
* case of a contrib photon map, this is done per light source, |
385 |
|
* and photonFlux is assumed to be an array */ |
386 |
< |
getPhotonFlux(p, flux); |
386 |
> |
getPhotonFlux(p, flux); |
387 |
|
|
388 |
|
if (photonFlux) { |
389 |
|
scalecolor(flux, photonFlux [isContribPmap(pmap) ? |