Adds concept of distance to illumination

This commit is contained in:
Maximilian Giller 2023-01-24 22:03:33 +01:00
parent 17fd35fe76
commit 5db502d77a
5 changed files with 5 additions and 1 deletions

View file

@ -1,5 +1,5 @@
#include "light/ambientlight.h" #include "light/ambientlight.h"
Light::Illumination AmbientLight::illuminate(Scene const &scene, Ray const &ray) const { 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};
} }

View file

@ -13,6 +13,7 @@ public:
struct Illumination { struct Illumination {
Color color; Color color;
Vector3d direction; Vector3d direction;
float distance;
}; };
// Constructor / Destructor // Constructor / Destructor

View file

@ -12,6 +12,7 @@ Light::Illumination PointLight::illuminate(Scene const &scene, Ray const &ray) c
// Precompute the distance from the light source // Precompute the distance from the light source
float const distance = length(target - this->position); float const distance = length(target - this->position);
illum.distance = distance;
// Define a secondary ray from the surface point to the light source. // Define a secondary ray from the surface point to the light source.
Ray lightRay; Ray lightRay;

View file

@ -13,6 +13,7 @@ Light::Illumination SpotLight::illuminate(Scene const &scene, Ray const &ray) co
// Precompute the distance from the light source // Precompute the distance from the light source
float const distance = length(target - this->position); float const distance = length(target - this->position);
illum.distance = distance;
// Define a secondary ray from the surface point to the light source // Define a secondary ray from the surface point to the light source
Ray lightRay; Ray lightRay;

View file

@ -12,6 +12,7 @@ Light::Illumination SunLight::illuminate(Scene const &scene, Ray const &ray) con
// Illumination object // Illumination object
Illumination illum; Illumination illum;
illum.direction = this->direction; illum.direction = this->direction;
illum.distance = INFINITY;
// Define a secondary ray from the surface point to the light source. // Define a secondary ray from the surface point to the light source.
Ray lightRay; Ray lightRay;