This repository has been archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
geometry.h
60 lines (46 loc) · 1.13 KB
/
geometry.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
// Copyright (c) 2016 Kai Luo. All rights reserved.
#ifndef ZLI_GEOMETRY_H_
#define ZLI_GEOMETRY_H_
#include <functional>
#include <iostream>
#include <memory>
#include "boundbox.h"
#include "bsdf.h"
#include "core_math.h"
#include "ray.h"
#include "spectrum.h"
namespace zLi {
struct Geometry;
struct RaySurfaceIntersection;
struct Geometry {
std::function<std::optional<RaySurfaceIntersection>(const Ray &)> Intersect;
// emitted radiance
std::function<Spectrum()> Le;
// reflectance
std::function<Spectrum()> R;
// @args: position
// @return: normal
std::function<Vector3f(const Vector3f &)> Normal;
std::function<BSDF()> bsdf;
std::function<BoundBox()> Bounds;
};
inline void CheckGeometry(const Geometry &g) {
assert(g.Intersect);
assert(g.Le);
assert(g.R);
assert(g.Normal);
assert(g.bsdf);
assert(g.Bounds);
}
struct RaySurfaceIntersection {
Float t;
Ray ray;
Geometry g;
Ray SpawnRay(const Vector3f &d) const { return Ray(ray(t), d, 1e-3); }
Ray SpawnRayTowards(const Vector3f &p) const {
auto d = (p - ray(t)).Normalize();
return SpawnRay(d);
}
};
} // end namespace zLi
#endif