From 95f76249e57dd24c967d2637ecad30a04507e706 Mon Sep 17 00:00:00 2001 From: Yoel <s73017@beuth-hochschule.de> Date: Tue, 16 Mar 2021 14:40:32 +0100 Subject: [PATCH] Point Light implemented --- RayTracer/shape/PointLight.cpp | 26 ++++++++++++++++++++++++++ RayTracer/shape/PointLight.h | 17 +++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 RayTracer/shape/PointLight.cpp create mode 100644 RayTracer/shape/PointLight.h diff --git a/RayTracer/shape/PointLight.cpp b/RayTracer/shape/PointLight.cpp new file mode 100644 index 0000000..2c8c56c --- /dev/null +++ b/RayTracer/shape/PointLight.cpp @@ -0,0 +1,26 @@ +#define _USE_MATH_DEFINES + +#include "PointLight.h" + +#include "../material/BackgroundMaterial.h" +#include "math.h" + +namespace shapes { +PointLight::PointLight(const util::Vec3& emission) + : material(std::make_shared<material::BackgroundMaterial>(emission)) { +} +util::SurfacePoint PointLight::sampleLight(const cam::Hit& h) const { + return util::SurfacePoint(util::Vec3(0), h.point().normalize(), {}, + material); +} +util::Vec3 PointLight::calculateLightEmission(const util::SurfacePoint& p, + const util::Vec3& d) const { + // Basically this is just the emission at a surface point. And the pdf dimms + // the light in regard to the angle. + auto emission = p.emission(); + // Illegally do not divide by area + // auto area = M_PI * std::pow(radius, 2); + auto pdf = std::pow(d.length(), 2); + return emission / pdf; +} +} // namespace shapes diff --git a/RayTracer/shape/PointLight.h b/RayTracer/shape/PointLight.h new file mode 100644 index 0000000..82a3653 --- /dev/null +++ b/RayTracer/shape/PointLight.h @@ -0,0 +1,17 @@ +#pragma once + +#include "Light.h" + +namespace shapes { +class PointLight : public Light { + public: + PointLight(const util::Vec3& emission); + + util::SurfacePoint sampleLight(const cam::Hit& h) const override; + util::Vec3 calculateLightEmission(const util::SurfacePoint& p, + const util::Vec3& d) const override; + + private: + std::shared_ptr<material::Material> material; +}; +} // namespace shapes -- GitLab