| 51 |
|
#endif |
| 52 |
|
extern OBJECT ambset [MAXASET+1]; |
| 53 |
|
|
| 54 |
+ |
/* Callback to print photon attributes acc. to user defined format */ |
| 55 |
+ |
int (*printPhoton)(RAY *r, Photon *p, PhotonMap *pm); |
| 56 |
|
|
| 57 |
|
|
| 58 |
+ |
|
| 59 |
|
void initPhotonMap (PhotonMap *pmap, PhotonMapType t) |
| 60 |
|
/* Init photon map 'n' stuff... */ |
| 61 |
|
{ |
| 238 |
|
} |
| 239 |
|
|
| 240 |
|
/* Adjust flux according to distribution ratio and ray weight */ |
| 241 |
< |
copycolor(photonFlux, ray -> rcol); |
| 241 |
> |
copycolor(photonFlux, ray -> rcol); |
| 242 |
> |
#if 0 |
| 243 |
> |
/* Factored out ray -> rweight as deprecated (?) for pmap, and infact |
| 244 |
> |
erroneously attenuates volume photon flux based on extinction, |
| 245 |
> |
which is already factored in by photonParticipate() */ |
| 246 |
|
scalecolor(photonFlux, |
| 247 |
|
ray -> rweight / (pmap -> distribRatio ? pmap -> distribRatio |
| 248 |
|
: 1)); |
| 249 |
+ |
#else |
| 250 |
+ |
scalecolor(photonFlux, |
| 251 |
+ |
1.0 / (pmap -> distribRatio ? pmap -> distribRatio : 1)); |
| 252 |
+ |
#endif |
| 253 |
|
setPhotonFlux(&photon, photonFlux); |
| 254 |
|
|
| 255 |
|
/* Set photon position and flags */ |
| 298 |
|
flushPhotonHeap(pmap); |
| 299 |
|
|
| 300 |
|
pmap -> numPhotons++; |
| 301 |
+ |
|
| 302 |
+ |
/* Print photon attributes */ |
| 303 |
+ |
if (printPhoton) |
| 304 |
+ |
/* Non-const kludge */ |
| 305 |
+ |
printPhoton((RAY*)ray, &photon, pmap); |
| 306 |
|
|
| 307 |
|
return 0; |
| 308 |
|
} |
| 517 |
|
|
| 518 |
|
/* Search position is ray -> rorg for volume photons, since we have no |
| 519 |
|
intersection point. Normals are ignored -- these are incident |
| 520 |
< |
directions). */ |
| 520 |
> |
directions). */ |
| 521 |
> |
/* NOTE: status returned by XXX_FindPhotons() is currently ignored; |
| 522 |
> |
if no photons are found, an empty queue is returned under the |
| 523 |
> |
assumption all photons are too distant to contribute significant |
| 524 |
> |
flux. */ |
| 525 |
|
if (isVolumePmap(pmap)) { |
| 526 |
|
#ifdef PMAP_OOC |
| 527 |
|
OOC_FindPhotons(pmap, ray -> rorg, NULL); |
| 611 |
|
|
| 612 |
|
|
| 613 |
|
|
| 614 |
< |
void find1Photon (PhotonMap *pmap, const RAY* ray, Photon *photon) |
| 614 |
> |
Photon *find1Photon (PhotonMap *pmap, const RAY* ray, Photon *photon) |
| 615 |
|
{ |
| 616 |
< |
pmap -> maxDist2 = thescene.cusize; /* ? */ |
| 616 |
> |
/* Init (squared) search radius to avg photon dist to centre of gravity */ |
| 617 |
> |
float maxDist2_0 = pmap -> CoGdist; |
| 618 |
> |
int found = 0; |
| 619 |
> |
#ifdef PMAP_LOOKUP_REDO |
| 620 |
> |
#define REDO 1 |
| 621 |
> |
#else |
| 622 |
> |
#define REDO 0 |
| 623 |
> |
#endif |
| 624 |
|
|
| 625 |
+ |
do { |
| 626 |
+ |
pmap -> maxDist2 = maxDist2_0; |
| 627 |
|
#ifdef PMAP_OOC |
| 628 |
< |
OOC_Find1Photon(pmap, ray -> rop, ray -> ron, photon); |
| 628 |
> |
found = OOC_Find1Photon(pmap, ray -> rop, ray -> ron, photon); |
| 629 |
|
#else |
| 630 |
< |
kdT_Find1Photon(pmap, ray -> rop, ray -> ron, photon); |
| 631 |
< |
#endif |
| 630 |
> |
found = kdT_Find1Photon(pmap, ray -> rop, ray -> ron, photon); |
| 631 |
> |
#endif |
| 632 |
> |
if (found < 0) { |
| 633 |
> |
/* Expand search radius to retry */ |
| 634 |
> |
maxDist2_0 *= 2; |
| 635 |
> |
#ifdef PMAP_LOOKUP_WARN |
| 636 |
> |
sprintf(errmsg, "failed 1-NN photon lookup" |
| 637 |
> |
#ifdef PMAP_LOOKUP_REDO |
| 638 |
> |
", retrying with search radius %.2f", maxDist2_0 |
| 639 |
> |
#endif |
| 640 |
> |
); |
| 641 |
> |
error(WARNING, errmsg); |
| 642 |
> |
#endif |
| 643 |
> |
} |
| 644 |
> |
} while (REDO && found < 0); |
| 645 |
> |
|
| 646 |
> |
/* Return photon buffer containing valid photon, else NULL */ |
| 647 |
> |
return found < 0 ? NULL : photon; |
| 648 |
|
} |
| 649 |
|
|
| 650 |
|
|