From b29e6d1613ee3a0d9ccb4a3e2a979e5028826f58 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 20 Mar 2020 20:36:32 +0100 Subject: [PATCH] library: render: scene: fix reflection handling The reflection will be calculated even if it ends up not contributing to the final color of an object. This allows for a more systematic use of coefficients without applying them twice, like it was done for the refraction transparency handling... --- src/render/scene.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/render/scene.rs b/src/render/scene.rs index d1a755f..d3a4894 100644 --- a/src/render/scene.rs +++ b/src/render/scene.rs @@ -180,14 +180,13 @@ impl Scene { // Calculate the refracted ray, if it was refracted refracted(incident_ray, normal, diffraction_index, index).map_or_else( // Total reflection - || self.reflection(point, 1., reflected, reflection_limit, diffraction_index), + || self.reflection(point, reflected, reflection_limit, diffraction_index), // Refraction (refracted ray, amount of *reflection*) |(r, refl_t)| { let refr_light = self.refraction(point, coef, r, reflection_limit, index) * (1. - refl_t) + self.reflection( point, - refl_t, reflected, reflection_limit, diffraction_index, @@ -197,7 +196,7 @@ impl Scene { ) } Some(ReflTransEnum::Reflectivity { coef }) => { - self.reflection(point, coef, reflected, reflection_limit, diffraction_index) + self.reflection(point, reflected, reflection_limit, diffraction_index) * coef + lighting * (1. - coef) } } @@ -231,12 +230,11 @@ impl Scene { fn reflection( &self, point: Point, - reflectivity: f32, reflected: Vector, reflection_limit: u32, diffraction_index: f32, ) -> LinearColor { - if reflectivity > 1e-5 && reflection_limit > 0 { + if reflection_limit > 0 { let reflection_start = point + reflected * 0.001; if let Some((t, obj)) = self.cast_ray(Ray::new(reflection_start, reflected)) { let resulting_position = reflection_start + reflected * t; @@ -247,7 +245,7 @@ impl Scene { reflection_limit - 1, diffraction_index, ); - return color * reflectivity; + return color; } }; LinearColor::black()