Skip to content
Snippets Groups Projects
Commit 95f76249 authored by Yoel's avatar Yoel
Browse files

Point Light implemented

parent 0bf64bfa
No related branches found
No related tags found
No related merge requests found
#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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment