diff --git a/prog6.cxx b/prog6.cxx index c84fde5..bfbb4e1 100644 --- a/prog6.cxx +++ b/prog6.cxx @@ -866,6 +866,27 @@ class ball_distribution { std::uniform_real_distribution inner; }; +class sphere_distribution { +public: + sphere_distribution(float _radius = 1.0f) : radius(_radius), inner(-1.0f, 1.0f) {} + + template + glm::vec3 operator()(Generator &gen) { + for (;;) { + glm::vec3 v{inner(gen), inner(gen), inner(gen)}; + float len = glm::length(v); + if (len <= 1.0f && len >= 1e-3) { + return (radius / len) * v; + } + } + } + + float radius; + +private: + std::uniform_real_distribution inner; +}; + glm::vec3 sample(glm::vec3 dir) { return skybox.sample(dir); }