diff --git a/data/chapter_10.png b/data/chapter_10.png index 1b7517f..d9fb696 100644 Binary files a/data/chapter_10.png and b/data/chapter_10.png differ diff --git a/raytracing/src/core/intersection-data.cpp b/raytracing/src/core/intersection-data.cpp index fb3f958..a647019 100644 --- a/raytracing/src/core/intersection-data.cpp +++ b/raytracing/src/core/intersection-data.cpp @@ -258,7 +258,7 @@ const double IntersectionData::n2(void) const /* ------------------------------------------------------------------------- */ -double IntersectionData::schlick(void) +double IntersectionData::schlick(void) const { double the_cos, the_r0; diff --git a/raytracing/src/core/intersection-data.h b/raytracing/src/core/intersection-data.h index ca18735..5e0e802 100644 --- a/raytracing/src/core/intersection-data.h +++ b/raytracing/src/core/intersection-data.h @@ -78,7 +78,7 @@ namespace Raytracer void set_n2(double an_n2); const double n2(void) const; - double schlick(void); + double schlick(void) const; private: bool m_is_inside; diff --git a/raytracing/src/renderer/world.cpp b/raytracing/src/renderer/world.cpp index 625328a..6f8451d 100644 --- a/raytracing/src/renderer/world.cpp +++ b/raytracing/src/renderer/world.cpp @@ -167,8 +167,17 @@ Color World::shade_hit(const IntersectionData &an_intersection_data, uint32_t a_ Shape *the_object = an_intersection_data.object(); Color the_surface = the_object->material().lighting(the_object, m_light, an_intersection_data.over_point(), an_intersection_data.eyev(), an_intersection_data.normalv(), the_shadowed); + Color the_reflected = reflected_color(an_intersection_data, a_remaining); Color the_refracted = refracted_color(an_intersection_data, a_remaining); + + Material &the_material = an_intersection_data.object()->material(); + if ((the_material.reflective() > 0) && (the_material.transparency() > 0)) + { + double the_reflectance = an_intersection_data.schlick(); + return the_surface + (the_reflected * the_reflectance) + the_refracted * (1 - the_reflectance); + } + return the_surface + the_reflected + the_refracted; }