From bd07a516e8ee473a0a854707b90a96be8ab85565 Mon Sep 17 00:00:00 2001
From: Yoel <s73017@beuth-hochschule.de>
Date: Mon, 14 Feb 2022 14:40:45 +0100
Subject: [PATCH] Fixing the break, continue issues

---
 RayTracer/sampling/Scene.cpp | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/RayTracer/sampling/Scene.cpp b/RayTracer/sampling/Scene.cpp
index 792c57f..02a7b34 100644
--- a/RayTracer/sampling/Scene.cpp
+++ b/RayTracer/sampling/Scene.cpp
@@ -70,23 +70,26 @@ util::Vec3 Scene::directLighting(const cam::Hit& h, cam::Ray r) const {
 			    cam::Ray(sample_point.point(), h.point() - sample_point.point(),
 			             cam::epsilon, 1 - cam::epsilon, false);
 			// When the surface normal and the shadowray dont point in the same
-			// hemisphere, the ray hits the surface, so we can break
-			if (util::dot(shadow_ray.d, sample_point.normal()) <= 0) break;
+			// hemisphere, the ray hits the surface, so we can continue
+			if (util::dot(shadow_ray.d, sample_point.normal()) <= 0) continue;
 
 			auto shadow_hit = group.intersect(shadow_ray);
-			// If the shadowray his something we can break
-			if (shadow_hit) break;
+			// If the shadowray his something we can continue
+			if (shadow_hit) continue;
 			auto light_pdf = light->lightPdf(sample_point, shadow_ray.d);
 			// This happens when the shaodow ray is beyond the surfaces normal.
-			// This means, that the shadow ray hits the surface and we can break
-			if (light_pdf <= 0) break;
+			// This means, that the shadow ray hits the surface and we can
+			// continue
+			if (light_pdf <= 0) continue;
 			auto brdf = h.calculateLightMultiplier(shadow_ray.d.normalize(),
 			                                       -r.d, h.normal());
 			auto L = light->lightEmission(sample_point);
-			// Dot product could be negative, in that case break
+			// Dot product could be negative, in that case continue
 			auto cosine_term = std::max<float>(
 			    util::dot(-shadow_ray.d.normalize(), h.normal()), 0);
-			if (cosine_term <= 0) break;
+			if (cosine_term <= 0) {
+				continue;
+			}
 
 			auto scatterFunction = (brdf * L * cosine_term) / light_pdf;
 			// Add the values from this light to the others
-- 
GitLab