From df7dc0f1069e6ed8ea24c152eb4c3a5a97e80b91 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Sat, 19 Jun 2021 17:54:16 +0200 Subject: Split on the largest axis on BVH generation --- src/utils.cpp | 56 ++++++++++++++++++++++++++++---------------------------- src/vec3.cpp | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/utils.cpp b/src/utils.cpp index 6db101c..a754b1d 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -59,34 +59,34 @@ uint32_t random_scene(sphere *world) { uint32_t world_sphere_index = 1; int32_t spheres_count = 11; - // for (int a = -spheres_count; a < spheres_count; a++) { - // for (int b = -spheres_count; b < spheres_count; b++) { - // auto choose_mat = randd(); - // point3 center(a + 0.9 * randd(), 0.2, b + 0.9 * randd()); - - // if ((center - point3{ 4, 0.2, 0 }).length() > 0.9) { - // material sphere_material = {}; - - // if (choose_mat < 0.8) { - // // diffuse - // sphere_material.albedo = color::random() * color::random(); - // sphere_material.type = MATERIAL_TYPE::LAMBERTIAN; - // } else if (choose_mat < 0.95) { - // // metal - // sphere_material.albedo = color::random(0.5, 1); - // sphere_material.fuzz = randd(0, 0.5); - // sphere_material.type = MATERIAL_TYPE::METAL; - // } else { - // // glass - // sphere_material.ior = 1.5; - // sphere_material.type = MATERIAL_TYPE::DIELECTRIC; - // } - - // world[world_sphere_index] = { center, sphere_material, 0.2 }; - // world_sphere_index++; - // } - // } - // } + for (int a = -spheres_count; a < spheres_count; a++) { + for (int b = -spheres_count; b < spheres_count; b++) { + auto choose_mat = randd(); + point3 center(a + 0.9 * randd(), 0.2, b + 0.9 * randd()); + + if ((center - point3{ 4, 0.2, 0 }).length() > 0.9) { + material sphere_material = {}; + + if (choose_mat < 0.8) { + // diffuse + sphere_material.albedo = color::random() * color::random(); + sphere_material.type = MATERIAL_TYPE::LAMBERTIAN; + } else if (choose_mat < 0.95) { + // metal + sphere_material.albedo = color::random(0.5, 1); + sphere_material.fuzz = randd(0, 0.5); + sphere_material.type = MATERIAL_TYPE::METAL; + } else { + // glass + sphere_material.ior = 1.5; + sphere_material.type = MATERIAL_TYPE::DIELECTRIC; + } + + world[world_sphere_index] = { center, sphere_material, 0.2 }; + world_sphere_index++; + } + } + } material material1 = {}; material1.ior = 1.5; diff --git a/src/vec3.cpp b/src/vec3.cpp index 8e27a98..8f7a720 100644 --- a/src/vec3.cpp +++ b/src/vec3.cpp @@ -1,4 +1,5 @@ #include +#include #include "vec3.hpp" #include "utils.hpp" @@ -40,6 +41,19 @@ vec3& vec3::operator/=(float numerator) { return *this; } +float vec3::operator[](int axis) { + switch (axis) { + case 0: + return x; + case 1: + return y; + case 2: + return z; + default: + return std::numeric_limits::infinity(); + } +} + float vec3::length() const { return sqrt(length_sq()); } -- cgit v1.3