summaryrefslogtreecommitdiff
path: root/main_final_render.cpp
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-05-03 16:00:54 +0800
committerKeuin <[email protected]>2022-05-03 16:00:54 +0800
commit51fba0b6e75071e7ee63f9b53b6e972ccdb3bfce (patch)
tree64952b48462bc1eaa426a3aa201b8a16d2ce1ff6 /main_final_render.cpp
parent12ec4e8284afb30ed894d9926362141cdfb24b96 (diff)
Create only one instance for multiple usages of the same dielectric material.
Diffstat (limited to 'main_final_render.cpp')
-rw-r--r--main_final_render.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/main_final_render.cpp b/main_final_render.cpp
index 1bab44a..3c789af 100644
--- a/main_final_render.cpp
+++ b/main_final_render.cpp
@@ -55,6 +55,10 @@ final_scene<T_Color, T_Coord>::final_scene(uint64_t seed) : world{} {
std::uniform_real_distribution<double> uni{0, 1};
material *m_ball;
+ // shared materials
+ const auto m_glass = new material_dielectric{1.5};
+ materials.push_back(m_glass);
+
// earth
m_ball = new material_diffuse_lambertian{{0.5, 0.5, 0.5}};
world.add_object(std::make_shared<sphere>(vec3d{0, -1000, 0}, 1000.0, *m_ball));
@@ -77,6 +81,7 @@ final_scene<T_Color, T_Coord>::final_scene(uint64_t seed) : world{} {
};
m_ball = new material_diffuse_lambertian{albedo};
world.add_object(std::make_shared<sphere>(center, 0.2, *m_ball));
+ materials.push_back(m_ball);
} else if (rv < 0.95) {
// metal
auto albedo = vec3d{
@@ -87,12 +92,11 @@ final_scene<T_Color, T_Coord>::final_scene(uint64_t seed) : world{} {
auto fuzz = 0.5 * uni(rand);
m_ball = new material_fuzzy_reflective{albedo, fuzz};
world.add_object(std::make_shared<sphere>(center, 0.2, *m_ball));
+ materials.push_back(m_ball);
} else {
// glass
- m_ball = new material_dielectric{1.5};
- world.add_object(std::make_shared<sphere>(center, 0.2, *m_ball));
+ world.add_object(std::make_shared<sphere>(center, 0.2, *m_glass));
}
- materials.push_back(m_ball);
}
}
}