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

Background is now skysphere, sinus correction of distribution in cornstructor implemented

parent 70b9cd3f
No related branches found
No related tags found
No related merge requests found
#include "Background.h"
#include "SkySphere.h"
#define _USE_MATH_DEFINES
#include <limits>
......@@ -6,9 +6,23 @@
#include "math.h"
namespace shapes {
Background::Background(const std::shared_ptr<util::Sampler>& sampler)
SkySphere::SkySphere(const std::shared_ptr<util::Sampler>& sampler)
: Sphere(100, std::make_shared<material::BackgroundMaterial>(sampler)) {
}
SkySphere::SkySphere(const std::shared_ptr<util::Sampler>& sampler,
util::Image& distribution)
: Sphere(100, std::make_shared<material::BackgroundMaterial>(sampler)) {
for (int x = 0; x < distribution.width; x++) {
for (int y = 0; y < distribution.height; y++) {
auto color = distribution[{x, y}];
auto sinn = sin(M_PI * ((float)y / distribution.height));
color = color * sinn;
distribution.setPixel(x, y, color);
}
}
material =
std::make_shared<material::BackgroundMaterial>(sampler, distribution);
}
// Thit intersect method rightly flips the normal.But the normal is never used
// for non scatter materials, so we do not flip the normal
/*
......@@ -21,7 +35,17 @@ std::optional<cam::Hit> Background::intersect(const cam::Ray& r) const {
return hit;
}*/
util::AxisAlignedBoundingBox Background::bounds() const {
float SkySphere::lightPdf(const util::SurfacePoint& p,
const util::Vec3& dl_out) const {
auto uv = p.texel();
auto phi = uv.second * M_PI;
float pdf = material->emission_pdf(uv.first, uv.second).value_or(1);
pdf = pdf / (2 * M_PI * M_PI * sin(phi));
return pdf;
}
util::AxisAlignedBoundingBox SkySphere::bounds() const {
return util::AxisAlignedBoundingBox();
}
} // namespace shapes
\ No newline at end of file
#pragma once
#include "../sampling/Image.h"
#include "../sampling/Sampler.h"
#include "Shape.h"
#include "Sphere.h"
namespace shapes {
class Background : public Sphere {
class SkySphere : public Sphere {
public:
Background(const std::shared_ptr<util::Sampler>& sampler);
SkySphere(const std::shared_ptr<util::Sampler>& sampler);
SkySphere(const std::shared_ptr<util::Sampler>& sampler,
util::Image& distribution);
float lightPdf(const util::SurfacePoint& p,
const util::Vec3& dl_out) const override;
// We should have to flip the normal, but it does not matter
// std::optional<cam::Hit> intersect(const cam::Ray& r) const override;
util::AxisAlignedBoundingBox bounds() const override;
......
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