From 51fba0b6e75071e7ee63f9b53b6e972ccdb3bfce Mon Sep 17 00:00:00 2001 From: Keuin Date: Tue, 3 May 2022 16:00:54 +0800 Subject: Create only one instance for multiple usages of the same dielectric material. --- main_final_render.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'main_final_render.cpp') 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::final_scene(uint64_t seed) : world{} { std::uniform_real_distribution 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(vec3d{0, -1000, 0}, 1000.0, *m_ball)); @@ -77,6 +81,7 @@ final_scene::final_scene(uint64_t seed) : world{} { }; m_ball = new material_diffuse_lambertian{albedo}; world.add_object(std::make_shared(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::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(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(center, 0.2, *m_ball)); + world.add_object(std::make_shared(center, 0.2, *m_glass)); } - materials.push_back(m_ball); } } } -- cgit v1.2.3