Better disk surface sampling.

This commit is contained in:
2017-02-12 04:28:21 -04:00
parent 85ff1de130
commit 501e2afc14
6 changed files with 49 additions and 24 deletions

View File

@@ -1,12 +1,16 @@
#include <glm/gtc/constants.hpp>
#include <iostream>
#include <cassert>
#include "disk.hpp"
#include "sampling.hpp"
using glm::vec2;
using glm::cos;
using glm::sin;
using glm::dot;
using glm::pi;
using glm::distance;
using glm::cross;
using glm::abs;
bool Disk::intersect(Ray & r, float & t) const {
float _t;
@@ -23,14 +27,15 @@ bool Disk::intersect(Ray & r, float & t) const {
}
vec3 Disk::sample_at_surface() const {
float theta = random01() * (2.0f * pi<float>());
float r = glm::sqrt(random01() * m_radius);
float x = r * cos(theta);
float y = r * sin(theta);
float z = 0.0f;
vec3 sample = vec3(x, y, z);
rotate_sample(sample, m_normal);
return sample;
float theta = random01() * pi2;
float r = random01() * m_radius;
vec3 nt, nb;
create_coords_system(m_normal, nt, nb);
float x = m_point.x + (r * cos(theta) * nt.x) + (r * sin(theta) * nb.x);
float y = m_point.y + (r * cos(theta) * nt.y) + (r * sin(theta) * nb.y);
float z = m_point.z + (r * cos(theta) * nt.z) + (r * sin(theta) * nb.z);
return vec3(x, y, z);
}
void Disk::calculate_inv_area() {