Many changes to jensen.

This commit is contained in:
2017-03-15 10:40:34 -04:00
parent 1faaaf0d63
commit c29d64583f
9 changed files with 167 additions and 63 deletions

View File

@@ -70,3 +70,19 @@ void rotate_sample(vec3 & sample, const vec3 & n) {
sample.x * nb.y + sample.y * n.y + sample.z * nt.y,
sample.x * nb.z + sample.y * n.z + sample.z * nt.z);
}
vec3 sample_sphere(const vec3 center, const float radius) {
float theta;
float u, sqrt1muu, x, y, z;
// Sampling formula from Wolfram Mathworld:
// http://mathworld.wolfram.com/SpherePointPicking.html
theta = random01()* (2.0f * pi<float>());
u = (random01() * 2.0f) - 1.0f;
sqrt1muu = glm::sqrt(1.0f - (u * u));
x = radius * sqrt1muu * cos(theta);
y = radius * sqrt1muu * sin(theta);
z = radius * u;
return vec3(vec3(x, y, z) + center);
}