1 |
+ |
#ifndef lint |
2 |
+ |
static const char RCSid[] = "$Id$"; |
3 |
+ |
#endif |
4 |
|
/* |
5 |
|
================================================================== |
6 |
|
Photon map main module |
11 |
|
supported by the Swiss National Science Foundation (SNSF, #147053) |
12 |
|
================================================================== |
13 |
|
|
11 |
– |
$Id$ |
14 |
|
*/ |
15 |
|
|
16 |
|
|
326 |
|
double totalFlux = 0; |
327 |
|
PhotonMap *pm; |
328 |
|
|
329 |
< |
for (t = 0; t < NUM_PMAP_TYPES && !photonMaps [t]; t++); |
329 |
> |
for (t = 0; t < NUM_PMAP_TYPES && !pmaps [t]; t++); |
330 |
|
if (t >= NUM_PMAP_TYPES) |
331 |
|
error(USER, "no photon maps defined"); |
332 |
|
|
344 |
|
|
345 |
|
/* Initialise all defined photon maps */ |
346 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
347 |
< |
initPhotonMap(photonMaps [t], t); |
347 |
> |
initPhotonMap(pmaps [t], t); |
348 |
|
|
349 |
|
initPhotonEmissionFuncs(); |
350 |
|
initPhotonScatterFuncs(); |
436 |
|
sprintf(errmsg, "too many prepasses"); |
437 |
|
|
438 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
439 |
< |
if (photonMaps [t] && !photonMaps [t] -> heapEnd) { |
439 |
> |
if (pmaps [t] && !pmaps [t] -> heapEnd) { |
440 |
|
sprintf(errmsg2, ", no %s photons stored", pmapName [t]); |
441 |
|
strcat(errmsg, errmsg2); |
442 |
|
} |
449 |
|
numEmit = FHUGE; |
450 |
|
|
451 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
452 |
< |
if (photonMaps [t]) |
453 |
< |
numEmit = min(photonMaps [t] -> distribTarget, numEmit); |
452 |
> |
if (pmaps [t]) |
453 |
> |
numEmit = min(pmaps [t] -> distribTarget, numEmit); |
454 |
|
|
455 |
|
numEmit *= preDistrib; |
456 |
|
} |
471 |
|
* Since this biases the photon density, addPhoton() promotes the |
472 |
|
* flux of stored photons to compensate. */ |
473 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
474 |
< |
if ((pm = photonMaps [t])) { |
474 |
> |
if ((pm = pmaps [t])) { |
475 |
|
pm -> distribRatio = (double)pm -> distribTarget / |
476 |
|
pm -> heapEnd - 1; |
477 |
|
|
496 |
|
/* Normalise distribution ratios and calculate number of photons to |
497 |
|
* emit in main pass */ |
498 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
499 |
< |
if ((pm = photonMaps [t])) |
499 |
> |
if ((pm = pmaps [t])) |
500 |
|
pm -> distribRatio /= maxDistribRatio; |
501 |
|
|
502 |
|
if ((numEmit = repProgress * maxDistribRatio) < FTINY) |
583 |
|
} |
584 |
|
|
585 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
586 |
< |
if (photonMaps [t] && !photonMaps [t] -> heapEnd) { |
586 |
> |
if (pmaps [t] && !pmaps [t] -> heapEnd) { |
587 |
|
/* Double preDistrib in case a photon map is empty and redo |
588 |
|
* pass 1 --> possibility of infinite loop for pathological |
589 |
|
* scenes (e.g. absorbing materials) */ |
611 |
|
totalFlux /= repProgress; |
612 |
|
|
613 |
|
for (t = 0; t < NUM_PMAP_TYPES; t++) |
614 |
< |
if (photonMaps [t]) { |
614 |
> |
if (pmaps [t]) { |
615 |
|
if (photonRepTime) { |
616 |
|
sprintf(errmsg, "\nBuilding %s photon map...\n", pmapName [t]); |
617 |
|
eputs(errmsg); |
618 |
|
fflush(stderr); |
619 |
|
} |
620 |
|
|
621 |
< |
balancePhotons(photonMaps [t], &totalFlux); |
621 |
> |
balancePhotons(pmaps [t], &totalFlux); |
622 |
|
} |
623 |
|
|
624 |
|
/* Precompute photon irradiance if necessary */ |