forked from BachiLi/redner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redner.cpp
154 lines (132 loc) · 5.27 KB
/
redner.cpp
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
#include "redner.h"
#include "py_utils.h"
#include "pathtracer.h"
#include "camera.h"
#include "scene.h"
#include "shape.h"
#include "material.h"
#include "area_light.h"
#include "envmap.h"
#include "active_pixels.h"
#include "ptr.h"
#include "load_serialized.h"
#include <pybind11/stl.h>
PYBIND11_MODULE(redner, m) {
m.doc() = "Redner"; // optional module docstring
py::class_<ptr<float>>(m, "float_ptr")
.def(py::init<std::size_t>());
py::class_<ptr<int>>(m, "int_ptr")
.def(py::init<std::size_t>());
py::class_<Camera>(m, "Camera")
.def(py::init<int,
int,
ptr<float>,
ptr<float>,
float,
float,
bool>());
py::class_<DCamera>(m, "DCamera")
.def(py::init<ptr<float>, ptr<float>, ptr<float>>());
py::class_<Scene>(m, "Scene")
.def(py::init<const Camera &,
const std::vector<const Shape*> &,
const std::vector<const Material*> &,
const std::vector<const AreaLight*> &,
const std::shared_ptr<const EnvironmentMap> &,
bool>());
py::class_<DScene, std::shared_ptr<DScene>>(m, "DScene")
.def(py::init<const DCamera &,
const std::vector<DShape*> &,
const std::vector<DMaterial*> &,
const std::vector<DAreaLight*> &,
const std::shared_ptr<DEnvironmentMap> &,
bool>());
py::class_<Shape>(m, "Shape")
.def(py::init<ptr<float>,
ptr<int>,
ptr<float>,
ptr<float>,
int,
int,
int,
int>())
.def_readonly("num_vertices", &Shape::num_vertices)
.def("has_uvs", &Shape::has_uvs)
.def("has_normals", &Shape::has_normals);
py::class_<DShape>(m, "DShape")
.def(py::init<ptr<float>,
ptr<float>,
ptr<float>>());
py::class_<Texture1>(m, "Texture1")
.def(py::init<ptr<float>,
int,
int,
int,
ptr<float>>());
py::class_<Texture3>(m, "Texture3")
.def(py::init<ptr<float>,
int,
int,
int,
ptr<float>>());
py::class_<Material>(m, "Material")
.def(py::init<Texture3,
Texture3,
Texture1,
bool>())
.def("get_diffuse_size", &Material::get_diffuse_size)
.def("get_specular_size", &Material::get_specular_size)
.def("get_roughness_size", &Material::get_roughness_size);
py::class_<DMaterial>(m, "DMaterial")
.def(py::init<Texture3,
Texture3,
Texture1>());
py::class_<AreaLight>(m, "AreaLight")
.def(py::init<int,
ptr<float>,
bool>());
py::class_<DAreaLight>(m, "DAreaLight")
.def(py::init<ptr<float>>());
py::class_<EnvironmentMap, std::shared_ptr<EnvironmentMap>>(m, "EnvironmentMap")
.def(py::init<Texture3, // values
ptr<float>, // env_to_world
ptr<float>, // world_to_env
ptr<float>, // sample_cdf_ys
ptr<float>, // sample_cdf_xs
Real>())
.def("get_size", &EnvironmentMap::get_size);
py::class_<DEnvironmentMap, std::shared_ptr<DEnvironmentMap>>(m, "DEnvironmentMap")
.def(py::init<Texture3, // values
ptr<float>>()); // world_to_env
py::class_<RenderOptions>(m, "RenderOptions")
.def(py::init<uint64_t,
int,
int,
bool>())
.def_readwrite("seed", &RenderOptions::seed);
py::class_<Vector2f>(m, "Vector2f")
.def_readwrite("x", &Vector2f::x)
.def_readwrite("y", &Vector2f::y);
py::class_<Vector3f>(m, "Vector3f")
.def_readwrite("x", &Vector3f::x)
.def_readwrite("y", &Vector3f::y)
.def_readwrite("z", &Vector3f::z);
py::class_<MitsubaTriMesh>(m, "MitsubaTriMesh")
.def_readwrite("vertices", &MitsubaTriMesh::vertices)
.def_readwrite("indices", &MitsubaTriMesh::indices)
.def_readwrite("uvs", &MitsubaTriMesh::uvs)
.def_readwrite("normals", &MitsubaTriMesh::normals);
m.def("load_serialized", &load_serialized, "");
m.def("render", &render, "");
/// Tests
m.def("test_sample_primary_rays", &test_sample_primary_rays, "");
m.def("test_scene_intersect", &test_scene_intersect, "");
m.def("test_sample_point_on_light", &test_sample_point_on_light, "");
m.def("test_active_pixels", &test_active_pixels, "");
m.def("test_camera_derivatives", &test_camera_derivatives, "");
m.def("test_d_bsdf", &test_d_bsdf, "");
m.def("test_d_bsdf_sample", &test_d_bsdf_sample, "");
m.def("test_d_bsdf_pdf", &test_d_bsdf_pdf, "");
m.def("test_d_intersect", &test_d_intersect, "");
m.def("test_d_sample_shape", &test_d_sample_shape, "");
}