18 using unique_vector = std::vector<std::unique_ptr<T>>;
21 std::unique_ptr<Camera> camera;
25 unique_vector<Bsdf> bsdfs;
26 unique_vector<Light> lights;
27 unique_vector<Texture> textures;
28 std::vector<Material> materials;
34 std::vector<float3> vertices;
35 std::vector<float2> texcoords;
36 std::vector<float3> normals;
37 std::vector<uint32_t> indices;
39 std::vector<float3> face_normals;
59 return materials[indices[hit.
tri * 4 + 3]];
65 auto i0 = indices[hit.
tri * 4 + 0];
66 auto i1 = indices[hit.
tri * 4 + 1];
67 auto i2 = indices[hit.
tri * 4 + 2];
69 auto& fn = face_normals[hit.
tri];
70 auto n = normalize(lerp(normals[i0], normals[i1], normals[i2], hit.
u, hit.
v));
71 auto uv = lerp(texcoords[i0], texcoords[i1], texcoords[i2], hit.
u, hit.
v);
78 surf.
coords = gen_local_coords(dot(ray.
dir, n) <= 0 ? n : -n);
85 bool load_scene(
const std::string& config,
Scene& scene);
bool occluded(const Ray &ray) const
Returns true if the given ray hits the scene.
Definition: scene.h:50
float3 org
Origin of the ray.
Definition: intersect.h:12
SurfaceParams surface_params(const Ray &ray, const Hit &hit) const
Returns the surface parameters for a hit point.
Definition: scene.h:63
float3 dir
Direction of the ray.
Definition: intersect.h:14
LocalCoords coords
Local coordinates at the hit point, w.r.t shading normal.
Definition: materials.h:31
bool entering
True if entering the surface.
Definition: materials.h:27
float3 face_normal
Geometric normal.
Definition: materials.h:30
Bounding Volume Hierarchy.
Definition: bvh.h:12
A material is a combination of a BSDF and an optional light emitter.
Definition: materials.h:38
int32_t tri
Triangle index, or -1 if no intersection was found.
Definition: intersect.h:29
float3 point
Hit point in world coordinates.
Definition: materials.h:28
float t
Time of intersection.
Definition: intersect.h:30
float u
First barycentric coordinate.
Definition: intersect.h:31
float2 uv
Texture coordinates.
Definition: materials.h:29
Ray-triangle hit information.
Definition: intersect.h:28
void traverse(const Ray &ray, Hit &hit, bool any=false) const
Traverses the BVH in order to find the closest intersection, or any intersection if 'any' is set...
float v
Second barycentric coordinate.
Definition: intersect.h:32
Ray defined as org + t * dir, with t in [tmin, tmax].
Definition: intersect.h:11
Surface parameters for a given point.
Definition: materials.h:26
Hit intersect(const Ray &ray) const
Definition: scene.h:43
const Material & material(const Hit &hit) const
Returns the material associated with a hit point.
Definition: scene.h:57