diff --git a/RayTracer/shape/PointLight.cpp b/RayTracer/shape/PointLight.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2c8c56c26ad01b3c1408c4964db85f0d97b08fcf --- /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 0000000000000000000000000000000000000000..82a36538f10865f369ba358e611df35dedc309ca --- /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