-
Notifications
You must be signed in to change notification settings - Fork 1
/
mirror.cc
60 lines (50 loc) · 1.42 KB
/
mirror.cc
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
#include "mirror.h"
#include "onb.h"
#include "random.h"
namespace Renzoku {
Mirror::Mirror() : kd(DefaultRgb::white) {
}
Mirror::Mirror(const Rgb &kd) : kd(kd) {
}
/**
* Convention:
*
* in, out are out-going vectors from the intersection point.
*/
Rgb Mirror::sample(Random &rd, const Onb &uvn, const Vec3 &wo, Vec3 &wi, Float &pdf) {
Vec3 nn = uvn.n();
Float dot_wn = dot(wo, nn);
if (dot_wn <= ZERO_EPSILON) {
wi = Vec3(0.0f, 0.0f, 0.0f);
pdf = 0.0f;
return DefaultRgb::black;
}
wi = 2.0f * dot_wn * nn - wo; // wi is still a unit vector
pdf = 1.0f;
return kd / dot(wi, nn);
}
Rgb Mirror::eval(const Onb &uvn, const Vec3 &wo, const Vec3 &wi) {
Vec3 nn = uvn.n();
Float dot_wn = dot(wo, nn);
if (dot_wn <= ZERO_EPSILON)
return DefaultRgb::black;
Vec3 wr = 2.0f * dot_wn * nn - wo;
if (fabs(dot(wr, wi)) >= 1.0f - ZERO_EPSILON) {
// reflection BSDF based on delta distribution
return kd / dot(wi, uvn.n());
}
return DefaultRgb::black;
}
Float Mirror::pdf(const Onb &uvn, const Vec3 &wo, const Vec3 &wi) {
Vec3 nn = uvn.n();
Float dot_wn = dot(wo, nn);
if (dot_wn <= ZERO_EPSILON)
return 0.0f;
Vec3 wr = 2.0f * dot_wn * nn - wo;
if (fabs(dot(wr, wi)) >= 1.0f - ZERO_EPSILON) {
// reflection BSDF based on delta distribution
return 1.0f;
}
return 0.0f;
}
}