-
Notifications
You must be signed in to change notification settings - Fork 4
/
redner.cpp
251 lines (222 loc) · 9.96 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
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
#include "redner.h"
#include "active_pixels.h"
#include "area_light.h"
#include "automatic_uv_map.h"
#include "camera.h"
#include "envmap.h"
#include "load_serialized.h"
#include "material.h"
#include "pathtracer.h"
#include "ptr.h"
#include "py_utils.h"
#include "scene.h"
#include "shape.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::enum_<CameraType>(m, "CameraType")
.value("perspective", CameraType::Perspective)
.value("orthographic", CameraType::Orthographic)
.value("fisheye", CameraType::Fisheye)
.value("panorama", CameraType::Panorama);
py::class_<Camera>(m, "Camera")
.def(py::init<int,
int,
ptr<float>, // position
ptr<float>, // look
ptr<float>, // up
ptr<float>, // cam_to_world
ptr<float>, // world_to_cam
ptr<float>, // ndc_to_cam
ptr<float>, // cam_to_ndc
float, // clip_near
CameraType>())
.def_readonly("use_look_at", &Camera::use_look_at);
py::class_<DCamera>(m, "DCamera")
.def(py::init<ptr<float>, // position
ptr<float>, // look
ptr<float>, // up
ptr<float>, // cam_to_world
ptr<float>, // world_to_cam
ptr<float>, // ndc_to_cam
ptr<float>>()); // cam_to_ndc
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,
int,
bool,
bool>())
.def_readonly("max_generic_texture_dimension",
&Scene::max_generic_texture_dimension);
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,
int>());
py::class_<Shape>(m, "Shape")
.def(py::init<ptr<float>, // vertices
ptr<int>, // indices
ptr<float>, // uvs
ptr<float>, // normals
ptr<int>, // uv_indices
ptr<int>, // normal_indices
ptr<float>, // colors
int, // num_vertices
int, // num_uv_vertices
int, // num_normal_vertices
int, // num_triangles
int, // material_id
int // light_id
>())
.def_readonly("num_vertices", &Shape::num_vertices)
.def_readonly("num_uv_vertices", &Shape::num_uv_vertices)
.def_readonly("num_normal_vertices", &Shape::num_normal_vertices)
.def("has_uvs", &Shape::has_uvs)
.def("has_normals", &Shape::has_normals)
.def("has_colors", &Shape::has_colors);
py::class_<DShape>(m, "DShape")
.def(py::init<ptr<float>,
ptr<float>,
ptr<float>,
ptr<float>>());
py::class_<Texture1>(m, "Texture1")
.def(py::init<ptr<float>,
int, // width
int, // height
int, // channels
int, // num_levels
int, // mesh_colors_resolution
ptr<float>>());
py::class_<Texture3>(m, "Texture3")
.def(py::init<ptr<float>,
int, // width
int, // height
int, // channels
int, // num_levels
int, // mesh_colors_resolution
ptr<float>>());
py::class_<TextureN>(m, "TextureN")
.def(py::init<ptr<float>,
int, // width
int, // height
int, // channels
int, // num_levels
int, // mesh_colors_resolution
ptr<float>>());
py::class_<Material>(m, "Material")
.def(py::init<Texture3, // diffuse
Texture3, // specular
Texture1, // roughness
TextureN, // generic_texture
Texture3, // normal_map
bool, // compute_specular_lighting
bool, // two_sided
bool>()) // use_vertex_color
.def("get_diffuse_size", &Material::get_diffuse_size)
.def("get_specular_size", &Material::get_specular_size)
.def("get_roughness_size", &Material::get_roughness_size)
.def("get_generic_size", &Material::get_generic_size)
.def("get_normal_map_size", &Material::get_normal_map_size);
py::class_<DMaterial>(m, "DMaterial")
.def(py::init<Texture3, // diffuse
Texture3, // specular
Texture1, // roughness
TextureN, // generic_texture
Texture3>()); // normal_map
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::enum_<Channels>(m, "channels")
.value("radiance", Channels::radiance)
.value("alpha", Channels::alpha)
.value("depth", Channels::depth)
.value("position", Channels::position)
.value("geometry_normal", Channels::geometry_normal)
.value("shading_normal", Channels::shading_normal)
.value("uv", Channels::uv)
.value("diffuse_reflectance", Channels::diffuse_reflectance)
.value("specular_reflectance", Channels::specular_reflectance)
.value("roughness", Channels::roughness)
.value("generic_texture", Channels::generic_texture)
.value("vertex_color", Channels::vertex_color)
.value("shape_id", Channels::shape_id)
.value("material_id", Channels::material_id);
m.def("compute_num_channels", compute_num_channels, "");
py::enum_<SamplerType>(m, "SamplerType")
.value("independent", SamplerType::independent)
.value("sobol", SamplerType::sobol);
py::class_<RenderOptions>(m, "RenderOptions")
.def(py::init<uint64_t,
int,
int,
std::vector<Channels>,
SamplerType>())
.def_readwrite("seed", &RenderOptions::seed)
.def_readwrite("num_samples", &RenderOptions::num_samples);
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, "");
// For auto uv unwrapping
py::class_<UVTriMesh>(m, "UVTriMesh")
.def(py::init<ptr<float>, // vertices
ptr<int>, // indices
ptr<float>, // uvs
ptr<int>, // uv_indices
int, // num_vertices
int, // num_uv_vertices
int>()) // num_triangles
.def_readwrite("uvs", &UVTriMesh::uvs)
.def_readwrite("uv_indices", &UVTriMesh::uv_indices)
.def_readwrite("num_uv_vertices", &UVTriMesh::num_uv_vertices);
py::class_<TextureAtlas>(m, "TextureAtlas")
.def(py::init<>());
m.def("automatic_uv_map", &automatic_uv_map, "");
m.def("copy_texture_atlas", ©_texture_atlas, "");
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, "");
}