From 5db502d77af4fe436926f8cc4e8004677ffa2390 Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Tue, 24 Jan 2023 22:03:33 +0100 Subject: [PATCH] Adds concept of distance to illumination --- light/ambientlight.cpp | 2 +- light/light.h | 1 + light/pointlight.cpp | 1 + light/spotlight.cpp | 1 + light/sunlight.cpp | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/light/ambientlight.cpp b/light/ambientlight.cpp index 0bde3bb..bac614d 100644 --- a/light/ambientlight.cpp +++ b/light/ambientlight.cpp @@ -1,5 +1,5 @@ #include "light/ambientlight.h" Light::Illumination AmbientLight::illuminate(Scene const &scene, Ray const &ray) const { - return {this->color * this->intensity, -ray.normal}; + return {this->color * this->intensity, -ray.normal, 0}; } diff --git a/light/light.h b/light/light.h index 08f5732..6abc093 100644 --- a/light/light.h +++ b/light/light.h @@ -13,6 +13,7 @@ public: struct Illumination { Color color; Vector3d direction; + float distance; }; // Constructor / Destructor diff --git a/light/pointlight.cpp b/light/pointlight.cpp index 359352a..fa02b84 100644 --- a/light/pointlight.cpp +++ b/light/pointlight.cpp @@ -12,6 +12,7 @@ Light::Illumination PointLight::illuminate(Scene const &scene, Ray const &ray) c // Precompute the distance from the light source float const distance = length(target - this->position); + illum.distance = distance; // Define a secondary ray from the surface point to the light source. Ray lightRay; diff --git a/light/spotlight.cpp b/light/spotlight.cpp index 3376249..5ef3427 100644 --- a/light/spotlight.cpp +++ b/light/spotlight.cpp @@ -13,6 +13,7 @@ Light::Illumination SpotLight::illuminate(Scene const &scene, Ray const &ray) co // Precompute the distance from the light source float const distance = length(target - this->position); + illum.distance = distance; // Define a secondary ray from the surface point to the light source Ray lightRay; diff --git a/light/sunlight.cpp b/light/sunlight.cpp index c34bdf1..6c6b569 100644 --- a/light/sunlight.cpp +++ b/light/sunlight.cpp @@ -12,6 +12,7 @@ Light::Illumination SunLight::illuminate(Scene const &scene, Ray const &ray) con // Illumination object Illumination illum; illum.direction = this->direction; + illum.distance = INFINITY; // Define a secondary ray from the surface point to the light source. Ray lightRay;