-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_scene.h
More file actions
123 lines (101 loc) · 3.16 KB
/
parse_scene.h
File metadata and controls
123 lines (101 loc) · 3.16 KB
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
#pragma once
#include "torrey.cuh"
#include "cutil_math.h"
#include <filesystem>
#include <variant>
#include <vector>
struct ParsedCamera {
float3 lookfrom;
float3 lookat;
float3 up;
float vfov;
int width, height;
};
struct ParsedImageTexture {
fs::path filename;
float uscale = 1, vscale = 1;
float uoffset = 0, voffset = 0;
};
using ParsedColor = std::variant<float3 /* RGB */, ParsedImageTexture>;
struct ParsedDiffuse {
ParsedColor reflectance;
};
struct ParsedMirror {
ParsedColor reflectance;
};
struct ParsedPlastic {
float eta; // index of refraction
ParsedColor reflectance;
};
struct ParsedPhong {
ParsedColor reflectance; // Ks
float exponent; // alpha
};
struct ParsedBlinnPhong {
ParsedColor reflectance; // Ks
float exponent; // alpha
};
struct ParsedBlinnPhongMicrofacet {
ParsedColor reflectance; // Ks
float exponent; // alpha
};
using ParsedMaterial = std::variant<ParsedDiffuse,
ParsedMirror,
ParsedPlastic,
ParsedPhong,
ParsedBlinnPhong,
ParsedBlinnPhongMicrofacet>;
struct ParsedPointLight {
float3 position;
float3 intensity;
};
struct ParsedDiffuseAreaLight {
int shape_id;
float3 radiance;
};
using ParsedLight = std::variant<ParsedPointLight, ParsedDiffuseAreaLight>;
/// A Shape is a geometric entity that describes a surface. E.g., a sphere, a triangle mesh, a NURBS, etc.
/// For each shape, we also store an integer "material ID" that points to a material, and an integer
/// "area light ID" that points to a light source if the shape is an area light. area_lightID is set to -1
/// if the shape is not an area light.
struct ParsedShapeBase {
int material_id = -1;
int area_light_id = -1;
};
struct ParsedSphere : public ParsedShapeBase{
//int material_id = -1;
//int area_light_id = -1;
float3 position;
float radius;
};
struct ParsedTriangleMesh : public ParsedShapeBase {
std::vector<float3> positions;
std::vector<int3> indices;
std::vector<float3> normals;
std::vector<float2> uvs;
};
using ParsedShape = std::variant<ParsedSphere, ParsedTriangleMesh>;
inline void set_material_id(ParsedShape &shape, int material_id) {
std::visit([&](auto &s) { s.material_id = material_id; }, shape);
}
inline void set_area_light_id(ParsedShape &shape, int area_light_id) {
std::visit([&](auto &s) { s.area_light_id = area_light_id; }, shape);
}
inline int get_material_id(const ParsedShape &shape) {
return std::visit([&](const auto &s) { return s.material_id; }, shape);
}
inline int get_area_light_id(const ParsedShape &shape) {
return std::visit([&](const auto &s) { return s.area_light_id; }, shape);
}
inline bool is_light(const ParsedShape &shape) {
return get_area_light_id(shape) >= 0;
}
struct ParsedScene {
ParsedCamera camera;
std::vector<ParsedMaterial> materials;
std::vector<ParsedLight> lights;
std::vector<ParsedShape> shapes;
float3 background_color;
int samples_per_pixel;
};
ParsedScene parse_scene(const fs::path &filename);