-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScene.cpp
More file actions
56 lines (43 loc) · 1.45 KB
/
Scene.cpp
File metadata and controls
56 lines (43 loc) · 1.45 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
#include "Scene.hpp"
#include "Medium.hpp"
bool Scene::IntersectPred(const Ray& ray, float max) const{
return scene_bvh->IntersectPred(ray, max);
}
bool Scene::IntersectTr(Ray ray, SurfaceInteraction& interaction, glm::vec3& Tr, float max) const{
Tr = { 1,1,1 };
while(max > 0){
bool hit = Intersect(ray, interaction, max);
if(!hit){
if(ray.medium)
Tr *= ray.medium->Tr(ray, max);
return false;
}
if(ray.medium)
Tr *= ray.medium->Tr(ray, interaction.t);
if(interaction.mat != nullptr)
return true;
ray = Ray(ray.at(interaction.t), ray.dir, ray.time, interaction.getMedium(ray.dir));
max -= interaction.t;
}
return false;
}
bool Scene::Intersect(const Ray& ray, SurfaceInteraction& interaction, float max) const{
return scene_bvh->Intersect(ray, interaction, max);
}
void Scene::Add(const std::shared_ptr<Primitive>& ptr){
primitives.push_back(ptr);
}
std::vector<std::shared_ptr<Light>> Scene::GetLights() const{
std::vector<std::shared_ptr<Light>> lights = scene_bvh->GetLights();
lights.insert(lights.end(), infiniteLights.begin(), infiniteLights.end());
return lights;
}
AABB Scene::BoundingBox() const{
return scene_bvh->BoundingBox();
}
std::shared_ptr<Medium> Scene::GetMedium() const{
return sceneMedium;
}
void Scene::SetMedium(const std::shared_ptr<Medium>& medium){
sceneMedium = medium;
}