-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.h
82 lines (68 loc) · 2.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
#pragma once
#include <vector>
#include <memory>
#include <Eigen/Dense>
#include <Eigen/StdVector>
#include "intersectable.h"
#include "rtree_util.h"
#include "random_texture.h"
struct Material {
Eigen::Vector3f diffuse_color = Eigen::Vector3f(0.5, 0.5, 0.5);
std::shared_ptr<RandomTexture> random_diffuse_texture;
Eigen::Vector3f specular_coeff = Eigen::Vector3f(0.5, 0.5, 0.5);
float alpha_phong = 2.0;
bool transparent = false;
bool mirror = false;
bool specular = false;
bool is_fog = false;
// fog_sigma*ds is the probability of a photon being absorbed by the fog travalling
// a infinidesimal ds
float fog_sigma = 0.0;
Eigen::Vector3f fog_color = Eigen::Vector3f(1.0, 1.0, 1.0);
float relative_refractive_index = 1.33;
};
struct Sunshine {
Eigen::Vector3f direction;
Eigen::Vector3f color;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
struct PointLight {
Eigen::Vector3f pos;
Eigen::Vector3f color;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
struct Lights {
std::vector<Sunshine> sunshines;
std::vector<PointLight> pointLights;
Eigen::Vector3f ambientColor;
};
struct IntervalIntersectReport {
std::vector<DisjointIntervals> objs_intervals;
std::vector<Material *> materials;
};
class Scene {
typedef unsigned int objectID;
typedef unsigned int materialID;
std::vector<std::shared_ptr<Intersectable>> objects;
std::vector<std::shared_ptr<Material>> materials;
std::vector<materialID> objects_material;
MyTree tree;
Lights lights;
Eigen::Vector3f background_color = Eigen::Vector3f(0.f, 0.f, 0.f);
public:
Scene();
const MyTree &getTree() const { return tree; }
void addMeshFromPlyFile(const char *file, const std::shared_ptr<Material> &material);
void addObject(std::shared_ptr<Intersectable> obj, const std::shared_ptr<Material> &material);
void addSunshine(Sunshine s);
std::vector<Sunshine> getSunshines() const { return lights.sunshines; }
bool ray_intersect_query(const Eigen::Vector3f &rayO, const Eigen::Vector3f &rayD,
IntersectReport &report, Material **material,
IntervalIntersectReport *interval_report = nullptr) const;
void setAmbientColor(const Eigen::Vector3f &color);
Eigen::Vector3f getAmbientColor() const;
Lights getAllLights() const;
void setBackground(const Eigen::Vector3f &color) { background_color = color; }
Eigen::Vector3f getBackground() const { return background_color; }
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};