1 |
+ |
#ifndef lint |
2 |
+ |
static const char RCSid[] = "$Id$"; |
3 |
+ |
#endif |
4 |
|
/* |
5 |
|
================================================================== |
6 |
|
Photon map support routines for emission from light sources |
7 |
|
|
8 |
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
9 |
|
(c) Fraunhofer Institute for Solar Energy Systems, |
10 |
< |
Lucerne University of Applied Sciences & Arts |
10 |
> |
(c) Lucerne University of Applied Sciences and Arts, |
11 |
> |
supported by the Swiss National Science Foundation (SNSF, #147053) |
12 |
|
================================================================== |
13 |
< |
|
10 |
< |
$Id$ |
13 |
> |
|
14 |
|
*/ |
15 |
|
|
16 |
|
|
19 |
|
#include "pmap.h" |
20 |
|
#include "pmaprand.h" |
21 |
|
#include "otypes.h" |
22 |
+ |
#include "otspecial.h" |
23 |
|
|
24 |
< |
|
25 |
< |
|
26 |
< |
SRCREC *photonPorts = NULL; /* Photon port list */ |
24 |
> |
/* List of photon port modifier names */ |
25 |
> |
char *photonPortList [MAXSET + 1] = {NULL}; |
26 |
> |
/* Photon port objects (with modifiers in photonPortMods) */ |
27 |
> |
SRCREC *photonPorts = NULL; |
28 |
|
unsigned numPhotonPorts = 0; |
29 |
|
|
30 |
|
void (*photonPartition [NUMOTYPE]) (EmissionMap*); |
31 |
|
void (*photonOrigin [NUMOTYPE]) (EmissionMap*); |
32 |
|
|
28 |
– |
extern OBJECT ambset []; |
29 |
– |
|
33 |
|
|
34 |
|
|
35 |
|
static int flatPhotonPartition2 (EmissionMap* emap, unsigned long mp, |
521 |
|
|
522 |
|
|
523 |
|
|
524 |
< |
void getPhotonPorts () |
525 |
< |
/* Find geometry declared as photon ports */ |
524 |
> |
void getPhotonPorts (char **portList) |
525 |
> |
/* Find geometry declared as photon ports from modifiers in portList */ |
526 |
|
{ |
527 |
|
OBJECT i; |
528 |
< |
OBJREC* obj; |
528 |
> |
OBJREC *obj, *mat; |
529 |
> |
char **lp; |
530 |
|
|
531 |
< |
/* Check for missing port modifiers */ |
532 |
< |
if (!ambset [0]) |
529 |
< |
error(USER, "no photon ports found"); |
531 |
> |
/* Init photon port objects */ |
532 |
> |
photonPorts = NULL; |
533 |
|
|
534 |
+ |
if (!portList [0]) |
535 |
+ |
return; |
536 |
+ |
|
537 |
|
for (i = 0; i < nobjects; i++) { |
538 |
|
obj = objptr(i); |
539 |
+ |
mat = findmaterial(obj); |
540 |
|
|
541 |
< |
if (inset(ambset, obj -> omod)) { |
542 |
< |
/* Add photon port */ |
543 |
< |
photonPorts = (SRCREC*)realloc(photonPorts, |
544 |
< |
(numPhotonPorts + 1) * |
545 |
< |
sizeof(SRCREC)); |
539 |
< |
if (!photonPorts) |
540 |
< |
error(USER, "can't allocate photon ports"); |
541 |
< |
|
542 |
< |
photonPorts [numPhotonPorts].so = obj; |
543 |
< |
photonPorts [numPhotonPorts].sflags = 0; |
541 |
> |
/* Check if object is a surface and NOT a light source (duh) and |
542 |
> |
* resolve its material via any aliases, then check for inclusion in |
543 |
> |
* modifier list */ |
544 |
> |
if (issurface(obj -> otype) && mat && !islight(mat -> otype)) { |
545 |
> |
for (lp = portList; *lp && strcmp(mat -> oname, *lp); lp++); |
546 |
|
|
547 |
< |
if (!sfun [obj -> otype].of || !sfun[obj -> otype].of -> setsrc) |
548 |
< |
objerror(obj, USER, "illegal photon port"); |
547 |
> |
if (*lp) { |
548 |
> |
/* Add photon port */ |
549 |
> |
photonPorts = (SRCREC*)realloc(photonPorts, |
550 |
> |
(numPhotonPorts + 1) * |
551 |
> |
sizeof(SRCREC)); |
552 |
> |
if (!photonPorts) |
553 |
> |
error(USER, "can't allocate photon ports"); |
554 |
|
|
555 |
< |
setsource(photonPorts + numPhotonPorts, obj); |
556 |
< |
numPhotonPorts++; |
555 |
> |
photonPorts [numPhotonPorts].so = obj; |
556 |
> |
photonPorts [numPhotonPorts].sflags = 0; |
557 |
> |
|
558 |
> |
if (!sfun [obj -> otype].of || !sfun[obj -> otype].of -> setsrc) |
559 |
> |
objerror(obj, USER, "illegal photon port"); |
560 |
> |
|
561 |
> |
setsource(photonPorts + numPhotonPorts, obj); |
562 |
> |
numPhotonPorts++; |
563 |
> |
} |
564 |
|
} |
565 |
|
} |
566 |
+ |
|
567 |
+ |
if (!numPhotonPorts) |
568 |
+ |
error(USER, "no valid photon ports found"); |
569 |
|
} |
570 |
|
|
571 |
|
|
608 |
|
unsigned i, t, p; |
609 |
|
double phi, cosTheta, sinTheta, du, dv, dOmega, thetaScale; |
610 |
|
EmissionSample* sample; |
611 |
< |
const OBJREC* mod = objptr(emap -> src -> so -> omod); |
611 |
> |
const OBJREC* mod = findmaterial(emap -> src -> so); |
612 |
|
static RAY r; |
613 |
|
#if 0 |
614 |
|
static double lastCosNorm = FHUGE; |
615 |
|
static SRCREC *lastSrc = NULL, *lastPort = NULL; |
616 |
|
#endif |
617 |
|
|
618 |
+ |
setcolor(emap -> partFlux, 0, 0, 0); |
619 |
+ |
|
620 |
|
photonOrigin [emap -> src -> so -> otype] (emap); |
621 |
|
cosTheta = DOT(emap -> ws, emap -> wh); |
622 |
|
|
639 |
|
#endif |
640 |
|
|
641 |
|
/* Need to recompute flux & PDF */ |
623 |
– |
setcolor(emap -> partFlux, 0, 0, 0); |
642 |
|
emap -> cdf = 0; |
643 |
|
emap -> numSamples = 0; |
644 |
|
|
687 |
|
|
688 |
|
VCOPY(r.rorg, emap -> photonOrg); |
689 |
|
VCOPY(r.rop, emap -> photonOrg); |
690 |
< |
r.rmax = FHUGE; |
690 |
> |
r.rmax = 0; |
691 |
|
|
692 |
|
for (t = 0; t < emap -> numTheta; t++) { |
693 |
|
for (p = 0; p < emap -> numPhi; p++) { |
757 |
|
unsigned long i, lo, hi; |
758 |
|
const EmissionSample* sample = emap -> samples; |
759 |
|
RREAL du, dv, cosTheta, cosThetaSqr, sinTheta, phi; |
760 |
< |
const OBJREC* mod = objptr(emap -> src -> so -> omod); |
760 |
> |
const OBJREC* mod = findmaterial(emap -> src -> so); |
761 |
|
|
762 |
|
/* Choose a new origin within current partition for every |
763 |
|
emitted photon to break up clustering artifacts */ |
764 |
|
photonOrigin [emap -> src -> so -> otype] ((EmissionMap*)emap); |
765 |
+ |
/* If we have a local glow source with a maximum radius, then |
766 |
+ |
restrict our photon to the specified distance, otherwise we set |
767 |
+ |
the limit imposed by photonMaxDist (or no limit if 0) */ |
768 |
+ |
if (mod -> otype == MAT_GLOW && !(emap -> src -> sflags & SDISTANT) |
769 |
+ |
&& mod -> oargs.farg[3] > FTINY) |
770 |
+ |
ray -> rmax = mod -> oargs.farg[3]; |
771 |
+ |
else |
772 |
+ |
ray -> rmax = photonMaxDist; |
773 |
|
rayorigin(ray, PRIMARY, NULL, NULL); |
748 |
– |
ray -> rmax = FHUGE; |
774 |
|
|
775 |
|
if (!emap -> numSamples) { |
776 |
|
/* Source is unmodified and has no port, and either local with |