Remove hardcoded PI constant, remove const in declarations
This commit is contained in:
parent
58fbe465f9
commit
3ae3ae7e6d
2 changed files with 12 additions and 14 deletions
|
@ -26,8 +26,8 @@ struct TriangleBox {
|
||||||
|
|
||||||
struct Object;
|
struct Object;
|
||||||
|
|
||||||
glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex);
|
glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, int32_t index, int32_t vertex);
|
||||||
glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex);
|
glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, int32_t index, int32_t vertex);
|
||||||
|
|
||||||
struct Object {
|
struct Object {
|
||||||
glm::vec3 position = glm::vec3(0);
|
glm::vec3 position = glm::vec3(0);
|
||||||
|
@ -48,7 +48,7 @@ struct Object {
|
||||||
const glm::vec3 v1 = fetch_position(*this, shape.mesh, i, 1);
|
const glm::vec3 v1 = fetch_position(*this, shape.mesh, i, 1);
|
||||||
const glm::vec3 v2 = fetch_position(*this, shape.mesh, i, 2);
|
const glm::vec3 v2 = fetch_position(*this, shape.mesh, i, 2);
|
||||||
|
|
||||||
AABB extent;
|
AABB extent{};
|
||||||
extent.min = glm::min(v0, v1);
|
extent.min = glm::min(v0, v1);
|
||||||
extent.min = glm::min(extent.min, v2);
|
extent.min = glm::min(extent.min, v2);
|
||||||
|
|
||||||
|
@ -101,13 +101,13 @@ struct HitResult {
|
||||||
const Object* object = nullptr;
|
const Object* object = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<HitResult> test_mesh(const Ray ray, const Object& object, const tinyobj::mesh_t& mesh, float& tClosest);
|
std::optional<HitResult> test_mesh(Ray ray, const Object& object, const tinyobj::mesh_t& mesh, float& tClosest);
|
||||||
std::optional<HitResult> test_scene(const Ray ray, const Scene& scene);
|
std::optional<HitResult> test_scene(Ray ray, const Scene& scene);
|
||||||
std::optional<HitResult> test_scene_octree(const Ray ray, const Scene& scene);
|
std::optional<HitResult> test_scene_octree(Ray ray, const Scene& scene);
|
||||||
|
|
||||||
struct SceneResult {
|
struct SceneResult {
|
||||||
HitResult hit;
|
HitResult hit;
|
||||||
glm::vec3 direct, indirect, reflect, combined;
|
glm::vec3 direct, indirect, reflect, combined;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::optional<SceneResult> cast_scene(const Ray ray, Scene& scene, const bool use_bvh, const int depth = 0);
|
std::optional<SceneResult> cast_scene(Ray ray, Scene& scene, bool use_bvh, int depth = 0);
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <glm/gtx/perpendicular.hpp>
|
#include <numbers>
|
||||||
|
|
||||||
constexpr double pi = 3.14159265358979323846l;
|
|
||||||
|
|
||||||
glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex) {
|
glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex) {
|
||||||
const tinyobj::index_t idx = mesh.indices[(index * 3) + vertex];
|
const tinyobj::index_t idx = mesh.indices[(index * 3) + vertex];
|
||||||
|
@ -12,7 +10,7 @@ glm::vec3 fetch_position(const Object& object, const tinyobj::mesh_t& mesh, cons
|
||||||
const auto vy = object.attrib.vertices[3 * idx.vertex_index + 1];
|
const auto vy = object.attrib.vertices[3 * idx.vertex_index + 1];
|
||||||
const auto vz = object.attrib.vertices[3 * idx.vertex_index + 2];
|
const auto vz = object.attrib.vertices[3 * idx.vertex_index + 2];
|
||||||
|
|
||||||
return glm::vec3(vx, vy, vz);
|
return {vx, vy, vz};
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex) {
|
glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const int32_t index, const int32_t vertex) {
|
||||||
|
@ -22,7 +20,7 @@ glm::vec3 fetch_normal(const Object& object, const tinyobj::mesh_t& mesh, const
|
||||||
const auto ny = object.attrib.normals[3 * idx.normal_index + 1];
|
const auto ny = object.attrib.normals[3 * idx.normal_index + 1];
|
||||||
const auto nz = object.attrib.normals[3 * idx.normal_index + 2];
|
const auto nz = object.attrib.normals[3 * idx.normal_index + 2];
|
||||||
|
|
||||||
return glm::vec3(nx, ny, nz);
|
return {nx, ny, nz};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_triangle(
|
bool test_triangle(
|
||||||
|
@ -178,7 +176,7 @@ std::pair<glm::vec3, glm::vec3> orthogonal_system(const glm::vec3& v1) {
|
||||||
|
|
||||||
glm::vec3 hemisphere(const double u1, const double u2) {
|
glm::vec3 hemisphere(const double u1, const double u2) {
|
||||||
const double r = sqrt(1.0 - u1 * u1);
|
const double r = sqrt(1.0 - u1 * u1);
|
||||||
const double phi = 2 * pi * u2;
|
const double phi = 2 * std::numbers::pi * u2;
|
||||||
|
|
||||||
return {cos(phi) * r, sin(phi) * r, u1};
|
return {cos(phi) * r, sin(phi) * r, u1};
|
||||||
}
|
}
|
||||||
|
@ -218,7 +216,7 @@ std::optional<SceneResult> cast_scene(const Ray ray, Scene& scene, const bool us
|
||||||
// and naive monte carlo without PDF
|
// and naive monte carlo without PDF
|
||||||
if (num_indirect_samples > 0) {
|
if (num_indirect_samples > 0) {
|
||||||
for (int i = 0; i < num_indirect_samples; i++) {
|
for (int i = 0; i < num_indirect_samples; i++) {
|
||||||
const float theta = scene.distribution() * pi;
|
const float theta = scene.distribution() * std::numbers::pi;
|
||||||
const float cos_theta = cos(theta);
|
const float cos_theta = cos(theta);
|
||||||
const float sin_theta = sin(theta);
|
const float sin_theta = sin(theta);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue