diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2021-05-12 23:39:42 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2021-05-12 23:41:54 +0200 |
| commit | a7707f730cd28853dc750b72ec882f07dba85406 (patch) | |
| tree | 4e219102ae9145bbbd42715e713f5f72a791d80f /src | |
| parent | 085d4c6dd995a4da396ddf3d51b619fafb77af7b (diff) | |
Add light sources, use russian roulette for opti and infinite
accumulation
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 10 | ||||
| -rw-r--r-- | src/utils.cpp | 15 | ||||
| -rw-r--r-- | src/vk-api.cpp | 3 |
3 files changed, 18 insertions, 10 deletions
diff --git a/src/main.cpp b/src/main.cpp index 0e2911c..071903a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ int main() { uint64_t frame_count = 0; auto start = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now(); - auto inputs = create_inputs(width, height, samples_per_pixel); + auto inputs = create_inputs(width, height); auto can_render = true; vkrenderer renderer { wnd, inputs }; @@ -179,10 +179,7 @@ int main() { ImGui::Text("frame per second %u\n", static_cast<uint32_t>(1000.f / delta_time)); ImGui::Text("frame time %f ms\n", delta_time); - - if (ImGui::SliderInt("samples per pixel", (int32_t*)&((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->samples_per_pixel, 1, 1000)) { - reset_accumulation = true; - } + ImGui::Text("frame count %u\n", ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->sample_index); ImGui::SliderInt("bounces", (int32_t*)&((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->max_bounce, 2, 250); @@ -200,12 +197,13 @@ int main() { renderer.begin_frame(); if (reset_accumulation) { + ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->sample_index = 0; renderer.reset_accumulation(); } renderer.compute(width, height); - ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->sample_index = frame_count % 1000; + ((input_data*) renderer.compute_shader_buffer.alloc_info.pMappedData)->sample_index++; renderer.ui(); diff --git a/src/utils.cpp b/src/utils.cpp index d4419b0..6467563 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -104,10 +104,17 @@ uint32_t random_scene(sphere *world) { material3.type = MATERIAL_TYPE::METAL; world[world_sphere_index + 2] = { { 4, 1, 0 }, material3, 1.0 }; - return world_sphere_index + 2; + material material4 = {}; + material4.albedo = color{ 0.0, 0.0, 0.0 }; + material4.emissive = color{ 1.0, 1.0, 1.0 } * 100.0; + material4.fuzz = 0.0; + material4.type = MATERIAL_TYPE::EMISSIVE; + world[world_sphere_index + 3] = { { 2, 1.5, 2 }, material4, 0.5 }; + + return world_sphere_index + 3; } -struct input_data create_inputs(uint32_t width, uint32_t height, uint32_t samples_per_pixel) { +struct input_data create_inputs(uint32_t width, uint32_t height) { // Image dimensions const float aspect_ratio = (float)width / (float) height; @@ -129,7 +136,7 @@ struct input_data create_inputs(uint32_t width, uint32_t height, uint32_t sample .nodes = {}, .max_bounce = max_depth, - .samples_per_pixel = samples_per_pixel, + .width = width, .height = height, @@ -139,6 +146,8 @@ struct input_data create_inputs(uint32_t width, uint32_t height, uint32_t sample // World hittable objects uint32_t spheres_count = random_scene(inputs.spheres); + inputs.spheres_count = spheres_count; + inputs.nodes[0] = { inputs.spheres, 0, spheres_count, inputs.nodes, 1 }; return inputs; diff --git a/src/vk-api.cpp b/src/vk-api.cpp index dc30520..1d0c8a5 100644 --- a/src/vk-api.cpp +++ b/src/vk-api.cpp @@ -736,7 +736,8 @@ Swapchain vkapi::create_swapchain(VkSurfaceKHR surface, size_t min_image_count, create_info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; create_info.preTransform = caps.currentTransform; create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR; - create_info.presentMode = VK_PRESENT_MODE_FIFO_KHR; + // create_info.presentMode = VK_PRESENT_MODE_FIFO_KHR; + create_info.presentMode = VK_PRESENT_MODE_MAILBOX_KHR; create_info.clipped = VK_TRUE; create_info.oldSwapchain = old_swapchain; |
