| 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 |
> |
/* if modifier in include/exclude 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)); |
| 243 |
< |
setPhotonFlux(&photon, photonFlux); |
| 244 |
< |
|
| 245 |
< |
/* Set photon position and flags */ |
| 246 |
< |
VCOPY(photon.pos, ray -> rop); |
| 247 |
< |
photon.flags = 0; |
| 235 |
< |
photon.caustic = PMAP_CAUSTICRAY(ray); |
| 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 photon position and flags */ |
| 245 |
> |
VCOPY(photon.pos, ray -> rop); |
| 246 |
> |
photon.flags = 0; |
| 247 |
> |
photon.caustic = PMAP_CAUSTICRAY(ray); |
| 248 |
|
|
| 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]); |
| 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 */ |
| 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 |
|
} |