forked from BachiLi/redner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.h
124 lines (109 loc) · 3.52 KB
/
scene.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
#pragma once
#include "redner.h"
#include "vector.h"
#include "buffer.h"
#include "ray.h"
#include "intersection.h"
#include "camera.h"
#include "area_light.h"
#include "shape.h"
#include "material.h"
#include "envmap.h"
#include "edge.h"
#include <vector>
#include <memory>
#include <mutex>
#include <embree3/rtcore.h>
#ifdef COMPILE_WITH_CUDA
#include <optix_prime/optix_primepp.h>
#endif
struct Scene {
/// XXX should use py::list to avoid copy?
Scene(const Camera &camera,
const std::vector<const Shape*> &shapes,
const std::vector<const Material*> &materials,
const std::vector<const AreaLight*> &area_lights,
const std::shared_ptr<const EnvironmentMap> &envmap,
bool use_gpu);
~Scene();
// Flatten arrays of scene content
Camera camera;
Buffer<Shape> shapes;
Buffer<Material> materials;
Buffer<AreaLight> area_lights;
EnvironmentMap *envmap;
// Is the scene stored in GPU or CPU
bool use_gpu;
#ifdef COMPILE_WITH_CUDA
// Optix handles
optix::prime::Context optix_context;
std::vector<optix::prime::Model> optix_models;
std::vector<RTPmodel> optix_instances;
std::vector<Matrix4x4f> transforms;
optix::prime::Model optix_scene;
#endif
// Embree handles
RTCDevice embree_device;
RTCScene embree_scene;
// Light sampling
Buffer<Real> light_pmf;
Buffer<Real> light_cdf;
Buffer<Real> light_areas;
Buffer<Real*> area_cdfs;
Buffer<Real> area_cdf_pool;
// For material derivatives
std::vector<std::mutex> material_mutexes;
// For envmap derivatives
std::mutex envmap_mutex;
// For edge sampling
EdgeSampler edge_sampler;
};
struct FlattenScene {
Shape *shapes;
Material *materials;
AreaLight *area_lights;
int num_lights;
Real *light_pmf;
Real *light_cdf;
Real *light_areas;
Real **area_cdfs;
EnvironmentMap *envmap;
};
// XXX: Again, some unnecessary copy from Python
struct DScene {
DScene() {}
DScene(const DCamera &camera,
const std::vector<DShape*> &shapes,
const std::vector<DMaterial*> &materials,
const std::vector<DAreaLight*> &lights,
const std::shared_ptr<DEnvironmentMap> &envmap,
bool use_gpu);
~DScene();
DCamera camera;
Buffer<DShape> shapes;
Buffer<DMaterial> materials;
Buffer<DAreaLight> area_lights;
DEnvironmentMap *envmap;
bool use_gpu;
};
FlattenScene get_flatten_scene(const Scene &scene);
void intersect(const Scene &scene,
const BufferView<int> &active_pixels,
const BufferView<Ray> &rays,
const BufferView<RayDifferential> &ray_differentials,
BufferView<Intersection> intersections,
BufferView<SurfacePoint> surface_points,
BufferView<RayDifferential> new_ray_differentials);
// Set ray.tmax to negative if occluded
void occluded(const Scene &scene,
const BufferView<int> &active_pixels,
BufferView<Ray> rays);
void sample_point_on_light(const Scene &scene,
const BufferView<int> &active_pixels,
const BufferView<SurfacePoint> &shading_points,
const BufferView<LightSample> &samples,
BufferView<Intersection> light_isects,
BufferView<SurfacePoint> light_points,
BufferView<Ray> shadow_ray);
void test_scene_intersect(bool use_gpu);
void test_sample_point_on_light(bool use_gpu);