aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2021-01-17 20:54:11 +0100
committerladevieq <ladevie.quentin@gmail.com>2021-01-17 20:54:11 +0100
commit25125b2e23c02199bdefb3a638584465229fd833 (patch)
treef52891f855f3cf78f3f97cd5c38fe23e55a0424d /src/main.cpp
parentdfc9a9b37d544d3a357b560829d2a9a48e5e5f5b (diff)
Handle window resize
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp108
1 files changed, 4 insertions, 104 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0176fdf..03db2ab 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4,13 +4,9 @@
#include <cstdio>
#include <cassert>
-#include "vk-renderer.hpp"
#include "thirdparty/renderdoc.h"
-#include "vec3.hpp"
-#include "material.hpp"
-#include "sphere.hpp"
-#include "camera.hpp"
+#include "vk-renderer.hpp"
#include "utils.hpp"
#include "defines.hpp"
@@ -22,62 +18,6 @@
#endif
-color ground_color { 1.0, 1.0, 1.0 };
-color sky_color { 0.5, 0.7, 1.0 };
-
-void random_scene(sphere *world) {
- material ground_material = { { 0.5, 0.5, 0.5 } };
- ground_material.type = MATERIAL_TYPE::LAMBERTIAN;
- world[0] = sphere{ { 0,-1000,0 }, ground_material, 1000 };
-
- uint32_t world_sphere_index = 1;
-
- for (int a = -11; a < 11; a++) {
- for (int b = -11; b < 11; 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;
- material1.type = MATERIAL_TYPE::DIELECTRIC;
- world[world_sphere_index] = { { 0, 1, 0 }, material1, 1.0 };
-
- material material2 = {};
- material2.albedo = color{ 0.4, 0.2, 0.1 };
- material2.type = MATERIAL_TYPE::LAMBERTIAN;
- world[world_sphere_index + 1] = { { -4, 1, 0 }, material2, 1.0 };
-
- material material3 = {};
- material3.albedo = color{ 0.7, 0.6, 0.5 };
- material3.fuzz = 0.0;
- material3.type = MATERIAL_TYPE::METAL;
- world[world_sphere_index + 2] = { { 4, 1, 0 }, material3, 1.0 };
-}
-
int main() {
RENDERDOC_API_1_1_2 *rdoc_api = NULL;
@@ -107,49 +47,9 @@ int main() {
const uint32_t width = 400;
const uint32_t height = width / aspect_ratio;
- const uint32_t samples_per_pixel = 1;
- const uint32_t max_depth = 50;
-
- const vec3 camera_position{ 13.0, 2.0, 3.0 };
- const vec3 camera_target{ 0.0, 0.0, 0.0 };
- const float aperture = 0.1;
- const float distance_to_focus = 10;
- camera camera { camera_position, camera_target, 20.0, aspect_ratio, aperture, distance_to_focus };
-
- struct input_data inputs = {
- .sky_color = sky_color,
- .ground_color = ground_color,
-
- .cam = camera,
-
- .spheres = {},
-
- .max_bounce = max_depth,
- .samples_per_pixel = samples_per_pixel,
- .width = width,
- .height = height
- };
-
- // Random numbers pools
- for (size_t rand_number_index = 0; rand_number_index < 1000; rand_number_index += 2) {
- inputs.random_offset[rand_number_index] = randd();
- inputs.random_offset[rand_number_index + 1] = randd();
- }
-
- for (size_t rand_number_index = 0; rand_number_index < 1000; rand_number_index += 2) {
- vec3 random_unit_disk = random_in_unit_disk();
- inputs.random_disk[rand_number_index] = random_unit_disk.x;
- inputs.random_disk[rand_number_index + 1] = random_unit_disk.y;
- }
-
- for (size_t rand_number_index = 0; rand_number_index < 1000; rand_number_index++) {
- inputs.random_in_sphere[rand_number_index] = random_in_unit_sphere();
- }
-
- // World hittable objects
- random_scene(inputs.spheres);
-
window wnd { width , height };
+
+ auto inputs = create_inputs(width, height);
vkrenderer renderer { wnd, inputs };
while(wnd.isOpen) {
@@ -162,7 +62,7 @@ int main() {
if(rdoc_api) rdoc_api->StartFrameCapture(NULL, NULL);
auto start = std::chrono::high_resolution_clock::now();
- renderer.compute(width, height);
+ renderer.compute();
auto end = std::chrono::high_resolution_clock::now();
std::cerr << "Image generation took " << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << std::endl;