Skip to content

Commit

Permalink
Split the distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
numberZero committed Dec 7, 2023
1 parent 45265ad commit 4953ea6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions prog6.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,27 @@ class ball_distribution {
std::uniform_real_distribution<float> inner;
};

class sphere_distribution {
public:
sphere_distribution(float _radius = 1.0f) : radius(_radius), inner(-1.0f, 1.0f) {}

template <typename Generator>
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<float> inner;
};

glm::vec3 sample(glm::vec3 dir) {
return skybox.sample(dir);
}
Expand Down

0 comments on commit 4953ea6

Please sign in to comment.