1 |
greg |
2.8 |
/* RCSid $Id: pmapsrc.h,v 2.7 2020/08/07 01:21:13 rschregle Exp $ */ |
2 |
rschregle |
2.5 |
|
3 |
greg |
2.1 |
/* |
4 |
rschregle |
2.7 |
====================================================================== |
5 |
greg |
2.1 |
Photon map support routines for emission from light sources |
6 |
|
|
|
7 |
|
|
Roland Schregle (roland.schregle@{hslu.ch, gmail.com}) |
8 |
|
|
(c) Fraunhofer Institute for Solar Energy Systems, |
9 |
rschregle |
2.7 |
supported by the German Research Foundation (DFG) |
10 |
|
|
under the FARESYS project. |
11 |
rschregle |
2.2 |
(c) Lucerne University of Applied Sciences and Arts, |
12 |
rschregle |
2.7 |
supported by the Swiss National Science Foundation (SNSF #147053). |
13 |
|
|
(c) Tokyo University of Science, |
14 |
|
|
supported by the JSPS KAKENHI Grant Number JP19KK0115. |
15 |
|
|
====================================================================== |
16 |
greg |
2.1 |
|
17 |
greg |
2.8 |
$Id: pmapsrc.h,v 2.7 2020/08/07 01:21:13 rschregle Exp $ |
18 |
greg |
2.1 |
*/ |
19 |
|
|
|
20 |
|
|
|
21 |
|
|
|
22 |
|
|
#ifndef PMAPSRC_H |
23 |
|
|
#define PMAPSRC_H |
24 |
|
|
|
25 |
|
|
#include "ray.h" |
26 |
|
|
#include "source.h" |
27 |
|
|
|
28 |
greg |
2.8 |
#ifdef __cplusplus |
29 |
|
|
extern "C" { |
30 |
|
|
#endif |
31 |
greg |
2.1 |
|
32 |
|
|
|
33 |
|
|
/* Data structures for photon emission */ |
34 |
|
|
typedef struct { |
35 |
|
|
unsigned theta, phi; /* Direction indices */ |
36 |
|
|
COLOR pdf; /* Probability of emission in this |
37 |
|
|
direction per RGB */ |
38 |
|
|
float cdf; /* Cumulative probability up to |
39 |
|
|
this sample */ |
40 |
|
|
} EmissionSample; |
41 |
|
|
|
42 |
|
|
typedef struct { |
43 |
|
|
unsigned numTheta, numPhi; /* Num divisions in theta & phi */ |
44 |
|
|
RREAL cosThetaMax; /* cos(source aperture) */ |
45 |
|
|
FVECT uh, vh, wh; /* Emission aperture axes at origin, |
46 |
|
|
w is normal*/ |
47 |
|
|
FVECT us, vs, ws; /* Source surface axes at origin, |
48 |
|
|
w is normal */ |
49 |
|
|
FVECT photonOrg; /* Current photon origin */ |
50 |
|
|
EmissionSample *samples; /* PDF samples for photon emission |
51 |
|
|
directions */ |
52 |
|
|
unsigned long numPartitions; /* Number of surface partitions */ |
53 |
|
|
RREAL partArea; /* Area covered by each partition */ |
54 |
|
|
SRCREC *src, *port; /* Current source and port */ |
55 |
|
|
unsigned long partitionCnt, /* Current surface partition */ |
56 |
|
|
maxPartitions, /* Max allocated partitions */ |
57 |
|
|
numSamples; /* Number of PDF samples */ |
58 |
|
|
unsigned char* partitions; /* Source surface partitions */ |
59 |
|
|
COLOR partFlux; /* Total flux emitted by partition */ |
60 |
|
|
float cdf; /* Cumulative probability */ |
61 |
|
|
} EmissionMap; |
62 |
|
|
|
63 |
|
|
|
64 |
rschregle |
2.7 |
|
65 |
|
|
/* Photon port flags (orientation relative to surface normal): |
66 |
|
|
* Forward, backward, both (bidirectional). */ |
67 |
|
|
#define PMAP_PORTFWD 1 |
68 |
|
|
#define PMAP_PORTBWD 2 |
69 |
|
|
#define PMAP_PORTBI (PMAP_PORTFWD | PMAP_PORTBWD) |
70 |
|
|
|
71 |
greg |
2.1 |
|
72 |
rschregle |
2.6 |
/* Photon ports for emission from geometry en lieu of light sources */ |
73 |
|
|
extern char *photonPortList [MAXSET + 1]; |
74 |
greg |
2.1 |
extern SRCREC *photonPorts; |
75 |
|
|
extern unsigned numPhotonPorts; |
76 |
|
|
|
77 |
|
|
/* Dispatch tables for partitioning light source surfaces and generating |
78 |
|
|
an origin for photon emission */ |
79 |
|
|
extern void (*photonPartition []) (EmissionMap*); |
80 |
|
|
extern void (*photonOrigin []) (EmissionMap*); |
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
rschregle |
2.6 |
void getPhotonPorts (char **portList); |
85 |
|
|
/* Find geometry declared as photon ports from modifiers in portList */ |
86 |
greg |
2.1 |
|
87 |
|
|
void initPhotonEmissionFuncs (); |
88 |
|
|
/* Init photonPartition[] and photonOrigin[] dispatch tables with source |
89 |
|
|
specific emission routines */ |
90 |
|
|
|
91 |
|
|
void initPhotonEmission (EmissionMap *emap, float numPdfSamples); |
92 |
|
|
/* Initialize photon emission from partitioned light source emap -> src; |
93 |
|
|
* this involves integrating the flux emitted from the current photon |
94 |
|
|
* origin emap -> photonOrg and setting up a PDF to sample the emission |
95 |
|
|
* distribution with numPdfSamples samples */ |
96 |
|
|
|
97 |
|
|
void emitPhoton (const EmissionMap*, RAY* ray); |
98 |
|
|
/* Emit photon from current source partition based on emission |
99 |
|
|
distribution and return new photon ray */ |
100 |
|
|
|
101 |
|
|
void multDirectPmap (RAY *r); |
102 |
|
|
/* Factor irradiance from direct photons into r -> rcol; interface to |
103 |
|
|
* direct() */ |
104 |
|
|
|
105 |
|
|
void inscatterVolumePmap (RAY *r, COLOR inscatter); |
106 |
|
|
/* Add inscattering from volume photon map; interface to srcscatter() */ |
107 |
|
|
|
108 |
greg |
2.8 |
#ifdef __cplusplus |
109 |
|
|
} |
110 |
|
|
#endif |
111 |
|
|
|
112 |
greg |
2.1 |
#endif |