15 |
|
|
16 |
|
#include "pmapdata.h" /* Includes pmapkdt.h */ |
17 |
|
#include "source.h" |
18 |
+ |
#include "otspecial.h" |
19 |
+ |
#include "random.h" |
20 |
|
|
21 |
|
|
22 |
|
|
348 |
|
if (norm && DOT(norm, p -> norm) <= PMAP_NORM_TOL * 127 * frandom()) |
349 |
|
return; |
350 |
|
|
351 |
< |
if (isContribPmap(pmap) && pmap -> srcContrib) { |
352 |
< |
/* Lookup in contribution photon map */ |
353 |
< |
OBJREC *srcMod; |
354 |
< |
const int srcIdx = photonSrcIdx(pmap, p); |
355 |
< |
|
356 |
< |
if (srcIdx < 0 || srcIdx >= nsources) |
357 |
< |
error(INTERNAL, "invalid light source index in photon map"); |
358 |
< |
|
359 |
< |
srcMod = findmaterial(source [srcIdx].so); |
351 |
> |
if (isContribPmap(pmap)) { |
352 |
> |
/* Lookup in contribution photon map; filter according to emitting |
353 |
> |
* light source if contrib list set, else accept all */ |
354 |
> |
|
355 |
> |
if (pmap -> srcContrib) { |
356 |
> |
OBJREC *srcMod; |
357 |
> |
const int srcIdx = photonSrcIdx(pmap, p); |
358 |
> |
|
359 |
> |
if (srcIdx < 0 || srcIdx >= nsources) |
360 |
> |
error(INTERNAL, "invalid light source index in photon map"); |
361 |
> |
|
362 |
> |
srcMod = findmaterial(source [srcIdx].so); |
363 |
|
|
364 |
< |
/* Reject photon if contributions from light source which emitted it |
365 |
< |
* are not sought */ |
366 |
< |
if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data) |
367 |
< |
return; |
364 |
> |
/* Reject photon if contributions from light source which emitted it |
365 |
> |
* are not sought */ |
366 |
> |
if (!lu_find(pmap -> srcContrib, srcMod -> oname) -> data) |
367 |
> |
return; |
368 |
> |
} |
369 |
|
|
370 |
|
/* Reject non-caustic photon if lookup for caustic contribs */ |
371 |
|
if (pmap -> lookupCaustic & !p -> caustic) |
419 |
|
|
420 |
|
|
421 |
|
|
422 |
< |
void kdT_FindPhotons (struct PhotonMap *pmap, const FVECT pos, |
423 |
< |
const FVECT norm) |
422 |
> |
int kdT_FindPhotons (struct PhotonMap *pmap, const FVECT pos, |
423 |
> |
const FVECT norm) |
424 |
|
{ |
425 |
|
float p [3], n [3]; |
426 |
|
|
427 |
|
/* Photon pos & normal stored at lower precision */ |
428 |
|
VCOPY(p, pos); |
429 |
< |
VCOPY(n, norm); |
430 |
< |
kdT_FindNearest(pmap, p, n, 1); |
429 |
> |
if (norm) |
430 |
> |
VCOPY(n, norm); |
431 |
> |
kdT_FindNearest(pmap, p, norm ? n : NULL, 1); |
432 |
> |
|
433 |
> |
/* Return success or failure (empty queue => none found) */ |
434 |
> |
return pmap -> squeue.tail ? 0 : -1; |
435 |
|
} |
436 |
|
|
437 |
|
|
470 |
|
d2 = DOT(dv, dv); |
471 |
|
|
472 |
|
if (d2 < pmap -> maxDist2 && |
473 |
< |
DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom()) { |
473 |
> |
(!norm || DOT(norm, p -> norm) > PMAP_NORM_TOL * 127 * frandom())) { |
474 |
|
/* Closest photon so far with similar normal. We allow for tolerance |
475 |
|
* to account for perturbation in the latter; note the photon normal |
476 |
|
* is coded in the range [-127,127], hence we factor this in */ |
481 |
|
|
482 |
|
|
483 |
|
|
484 |
< |
void kdT_Find1Photon (struct PhotonMap *pmap, const FVECT pos, |
485 |
< |
const FVECT norm, Photon *photon) |
484 |
> |
int kdT_Find1Photon (struct PhotonMap *pmap, const FVECT pos, |
485 |
> |
const FVECT norm, Photon *photon) |
486 |
|
{ |
487 |
|
float p [3], n [3]; |
488 |
< |
Photon *pnn; |
488 |
> |
Photon *pnn = NULL; |
489 |
|
|
490 |
|
/* Photon pos & normal stored at lower precision */ |
491 |
|
VCOPY(p, pos); |
492 |
< |
VCOPY(n, norm); |
493 |
< |
kdT_Find1Nearest(pmap, p, n, &pnn, 1); |
494 |
< |
memcpy(photon, pnn, sizeof(Photon)); |
492 |
> |
if (norm) |
493 |
> |
VCOPY(n, norm); |
494 |
> |
kdT_Find1Nearest(pmap, p, norm ? n : NULL, &pnn, 1); |
495 |
> |
if (!pnn) |
496 |
> |
/* No photon found => failed */ |
497 |
> |
return -1; |
498 |
> |
else { |
499 |
> |
/* Copy found photon => successs */ |
500 |
> |
memcpy(photon, pnn, sizeof(Photon)); |
501 |
> |
return 0; |
502 |
> |
} |
503 |
|
} |
504 |
|
|
505 |
|
|