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

Experimental implementation of the sampleLight-function

parent fc22643c
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
#include "Sphere.h"
#include "../tools/Random.h"
#include "math.h"
namespace shapes {
......@@ -46,4 +47,14 @@ util::AxisAlignedBoundingBox Sphere::bounds() const {
return util::AxisAlignedBoundingBox(util::Vec3(-radius),
util::Vec3(radius));
}
// TODO: Rework this function to be yours. THIS IS COPIED!!!! HIT IS A WRONG
// RETURN VALUE hit's n is wrong and bad
util::SurfacePoint Sphere::sampleLight() const {
float u[2] = {(float)util::dis(util::gen), (float)util::dis(util::gen)};
float z = u[0];
float r = std::sqrt(std::max((float)0, (float)1. - z * z));
float phi = 2 * M_PI * u[1];
util::Vec3 point(r * std::cos(phi), r * std::sin(phi), z);
return util::SurfacePoint(point, point, 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