-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrdf_point_light.h
292 lines (217 loc) · 7.06 KB
/
brdf_point_light.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#ifndef _BRDF_POINT_LIGHT_H_
#define _BRDF_POINT_LIGHT_H_
#include "common.h"
#include "vec2.h"
#include "vec3.h"
#include "rgb.h"
#include "light.h"
#include "material.h"
#include "onb.h"
#include "local_geometry.h"
namespace Renzoku {
enum BrdfPointLightTag { // maintain for reproducing results in PG14.
VPL_TAG_DEFAULT,
VPL_TAG_NEW_GROUP,
VPL_TAG_HEAL_ARTIFACTS,
VPL_TAG_STANDARD_END,
VPL_TAG_HEAL_END
};
struct BrdfPointLightRef {
int index;
BrdfPointLightRef(int index = -1) : index(index) {}
bool is_valid() const { return index >= 0; }
};
class BrdfPointLight {
public:
/**
* Create a point light without material and parent point light.
* This indicates virtual point lights generated on the light sources.
*/
virtual Light::Type get_light_type() const {
return Light::BRDF_POINT_LIGHT;
}
BrdfPointLight() : distance(0.0f) {}
/**
* Create a VPL.
*
* The parent light can refer to a physical light, or another VPL (through index reference).
*/
inline BrdfPointLight(const LocalGeometry &dg, Rgb contrib, Material *m, const Vec3 &wi, Light *ancestor_light);
inline BrdfPointLight(const LocalGeometry &dg, Rgb contrib, Material *m, const Vec3 &wi, const BrdfPointLightRef &prev);
inline BrdfPointLight(const LocalGeometry &dg, Rgb power, Light *light);
inline BrdfPointLightRef get_prev() const;
inline Light *get_ancestor_light() const;
inline void set_prev(const BrdfPointLightRef &ref);
inline int get_bounce() const;
inline void set_bounce(int bounce);
inline Vec3 org() const;
inline Vec3 normal() const;
inline LocalGeometry get_dg() const;
inline Rgb brdf(const Vec3 &wo) const;
inline Rgb radiance(const Vec3 &wo) const;
inline Rgb power() const;
inline Float get_distance() const;
inline void set_distance(Float distance);
/**
* Contribution = throughput / pdf. Contribution is equivalent to power.
*/
inline Rgb contribution() const;
inline void set_contribution(const Rgb &phi);
/**
* Return the incident ray.
*/
inline Vec3 get_wi() const;
/**
* Return the local coordinate frame at the VPL.
*/
inline Onb get_uvn() const;
inline Material *get_material() const;
inline Float get_radius() const;
inline void set_radius(Float radius);
inline void set_shape(Shape *shape);
inline Shape *get_shape() const;
inline Vec2 get_texture_coords() const;
/**
* Throughput of the path. Does not include probability.
*/
inline Rgb get_throughput() const;
inline void set_throughput(const Rgb &T);
inline void set_pdf(Float pdf);
inline Float pdf() const;
/**
* Return true if VPL is on a light surface (represent direct lighting)
*/
inline bool is_on_light() const;
/**
* Return true if VPL represents indirect lighting
*/
inline bool is_indirect_light() const;
protected:
LocalGeometry dg;
Vec3 wi;
Rgb contrib;
Material *m;
BrdfPointLightRef prev; /// index of the previous VPL on the light subpath
Light *ancestor_light; /// mutual exclusive with prev
int bounce; /// indicate the type of the VPL: bounce-0 means direct illumination.
Float radius; /// radius of the disk that estimates the area the VPL covers on the surface it is located on
Shape *shape; /// the shape on which the VPL is deposit.
Rgb throughput;
Float path_pdf;
Float distance; /// distance to the previous path vertex
protected:
BrdfPointLightTag tag;
public:
inline BrdfPointLightTag get_tag() const;
inline void set_tag(BrdfPointLightTag tag);
};
inline bool BrdfPointLight::is_on_light() const {
return (m == NULL && ancestor_light != NULL);
}
inline bool BrdfPointLight::is_indirect_light() const {
return (m != NULL && (prev.is_valid() || ancestor_light != NULL));
}
inline Vec3 BrdfPointLight::org() const {
return dg.p;
}
inline Vec3 BrdfPointLight::normal() const {
return dg.n;
}
inline LocalGeometry BrdfPointLight::get_dg() const {
return dg;
}
inline Rgb BrdfPointLight::power() const {
return contrib;
}
inline Rgb BrdfPointLight::contribution() const {
return contrib;
}
inline void BrdfPointLight::set_contribution(const Rgb &phi) {
contrib = phi;
}
inline Vec3 BrdfPointLight::get_wi() const {
return wi;
}
inline Float BrdfPointLight::get_distance() const {
return distance;
}
inline void BrdfPointLight::set_distance(Float distance) {
this->distance = distance;
}
inline Onb BrdfPointLight::get_uvn() const {
return dg.uvn;
}
inline Vec2 BrdfPointLight::get_texture_coords() const {
return dg.uv;
}
inline BrdfPointLightRef BrdfPointLight::get_prev() const {
return prev;
}
inline void BrdfPointLight::set_prev(const BrdfPointLightRef &ref) {
prev = ref;
}
inline Light *BrdfPointLight::get_ancestor_light() const {
return ancestor_light;
}
inline int BrdfPointLight::get_bounce() const {
return bounce;
}
inline void BrdfPointLight::set_bounce(int bounce) {
this->bounce = bounce;
}
inline Material *BrdfPointLight::get_material() const {
return m;
}
inline Float BrdfPointLight::get_radius() const {
return radius;
}
inline void BrdfPointLight::set_radius(Float radius) {
this->radius = radius;
}
inline Shape *BrdfPointLight::get_shape() const {
return shape;
}
inline void BrdfPointLight::set_shape(Shape *shape) {
this->shape = shape;
}
inline Rgb BrdfPointLight::brdf(const Vec3 &wo) const {
if (this->is_on_light())
return DefaultRgb::white;
return m->eval(dg, wi, wo);
}
inline void BrdfPointLight::set_pdf(Float pdf) {
this->path_pdf = pdf;
}
inline Float BrdfPointLight::pdf() const {
return path_pdf;
}
inline void BrdfPointLight::set_throughput(const Rgb &T) {
this->throughput = T;
}
inline Rgb BrdfPointLight::get_throughput() const {
return throughput;
}
inline BrdfPointLightTag BrdfPointLight::get_tag() const {
return tag;
}
inline void BrdfPointLight::set_tag(BrdfPointLightTag tag) {
this->tag = tag;
}
inline BrdfPointLight::BrdfPointLight(const LocalGeometry &dg, Rgb power, Material *m, const Vec3 &wi, const BrdfPointLightRef &prev)
: dg(dg), contrib(power), m(m), prev(prev), wi(wi), ancestor_light(NULL), distance(0.0f)
{
}
inline BrdfPointLight::BrdfPointLight(const LocalGeometry &dg, Rgb power, Material *m, const Vec3 &wi, Light *ancestor_light)
: dg(dg), contrib(power), m(m), prev(BrdfPointLightRef()), wi(wi), ancestor_light(ancestor_light), distance(0.0f)
{
}
inline BrdfPointLight::BrdfPointLight(const LocalGeometry &dg, Rgb power, Light *light)
: dg(dg), contrib(power), m(NULL), prev(BrdfPointLightRef()), wi(Vec3()), ancestor_light(ancestor_light), distance(0.0f)
{
}
inline Rgb BrdfPointLight::radiance(const Vec3 &wo) const {
Rgb brdf = this->brdf(wo);
return contrib * brdf;
}
} // end namespace
#endif