sphere and disk area lights mostly ready (I think :S).

This commit is contained in:
2017-02-09 23:37:40 -04:00
parent 944ae05db7
commit 0cdc7c46ca
30 changed files with 512 additions and 83 deletions

View File

@@ -1,4 +1,8 @@
#include <iostream>
#include <glm/gtc/constants.hpp>
#include "sphere.hpp"
#include "sampling.hpp"
using namespace glm;
@@ -38,3 +42,23 @@ vec3 Sphere::normal_at_int(Ray & r, float & t) const {
vec3 i = vec3(r.m_origin + (t * r.m_direction));
return normalize(vec3((i - m_center) / m_radius));
}
vec3 Sphere::sample_at_surface() const {
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 = m_radius * sqrt1muu * cos(theta);
y = m_radius * sqrt1muu * sin(theta);
z = m_radius * u;
return vec3(x, y, z) + m_center;
}
void Sphere::calculate_inv_area() {
m_inv_area = 1.0f / (4.0 * pi<float>() * (m_radius * m_radius));
}