diff --git a/.gitignore b/.gitignore index b7a882f..aa6ecba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .aws-sam/ -.DS_Store \ No newline at end of file +.DS_Store_codeql_detected_source_root diff --git a/path-tracer-core/src/cloud/batch_sender.cpp b/path-tracer-core/src/cloud/batch_sender.cpp index 8d39026..48ff19c 100644 --- a/path-tracer-core/src/cloud/batch_sender.cpp +++ b/path-tracer-core/src/cloud/batch_sender.cpp @@ -25,11 +25,6 @@ void batch_sender::flush_loop() std::unique_lock lock(m_mutex); m_cv.wait_for(lock, m_flush_interval, [this]() { return m_terminate.load(); }); - if (m_terminate) - { - break; - } - std::vector>> batches_to_send; for (auto &pair : m_pending_rays) { diff --git a/path-tracer-core/src/models/work_info.hpp b/path-tracer-core/src/models/work_info.hpp index e3fb024..9ac7e0b 100644 --- a/path-tracer-core/src/models/work_info.hpp +++ b/path-tracer-core/src/models/work_info.hpp @@ -32,8 +32,11 @@ struct worker_info float min_y; float max_x; float max_y; + int image_width; + int image_height; NLOHMANN_DEFINE_TYPE_INTRUSIVE(worker_info, scene_info, scene_bucket, scene_root, worker_id, sqs_queue_url, - sns_topic_arn, num_workers, samples, bounces, min_x, min_y, max_x, max_y) + sns_topic_arn, num_workers, samples, bounces, min_x, min_y, max_x, max_y, + image_width, image_height) }; } // namespace models \ No newline at end of file diff --git a/path-tracer-core/src/processors/master/master.cpp b/path-tracer-core/src/processors/master/master.cpp index 673cc1b..c7c47e0 100644 --- a/path-tracer-core/src/processors/master/master.cpp +++ b/path-tracer-core/src/processors/master/master.cpp @@ -20,7 +20,7 @@ master::~master() void master::run() { this->resolution = - math::uvec2((m_worker_info.max_x - m_worker_info.min_x), (m_worker_info.max_y - m_worker_info.min_y)); + math::uvec2((m_worker_info.max_x - m_worker_info.min_x) + 1, (m_worker_info.max_y - m_worker_info.min_y) + 1); this->sample_count = m_worker_info.samples; this->m_should_terminate = false; this->m_completed_rays = 0; diff --git a/path-tracer-core/src/processors/master/master.hpp b/path-tracer-core/src/processors/master/master.hpp index 2a00eb9..c32544e 100644 --- a/path-tracer-core/src/processors/master/master.hpp +++ b/path-tracer-core/src/processors/master/master.hpp @@ -32,7 +32,7 @@ class master : public application private: models::worker_info m_worker_info; std::vector> pixels; - math::uvec2 resolution = math::fvec2(640, 480); + math::uvec2 resolution = math::uvec2(640, 480); bool transparent_background = false; uint32_t sample_count = 50; diff --git a/path-tracer-core/src/processors/worker/intersection_worker.cpp b/path-tracer-core/src/processors/worker/intersection_worker.cpp index a31de37..365b369 100644 --- a/path-tracer-core/src/processors/worker/intersection_worker.cpp +++ b/path-tracer-core/src/processors/worker/intersection_worker.cpp @@ -219,7 +219,15 @@ void worker::process_direct_lighting_intersection_results() auto best_ray = results.second; best_ray.stage = models::ray_stage::SHADING; - map_ray_stage_to_queue(best_ray); + if (best_ray.worker_id == m_worker_info.worker_id) + { + map_ray_stage_to_queue(best_ray); + } + else + { + best_ray.type = models::ray_type::OWN; + m_batch_sender.enqueue_ray(best_ray, best_ray.worker_id); + } } } } diff --git a/path-tracer-core/src/processors/worker/shading_worker.cpp b/path-tracer-core/src/processors/worker/shading_worker.cpp index 03bf026..0229539 100644 --- a/path-tracer-core/src/processors/worker/shading_worker.cpp +++ b/path-tracer-core/src/processors/worker/shading_worker.cpp @@ -48,7 +48,7 @@ void worker::process_shading() alpha = transparent_background ? 0.0f : 1.0f; ray.stage = models::ray_stage::ACCUMULATE; - map_ray_stage_to_queue(ray); + m_batch_sender.enqueue_ray(ray, models::MASTER_ID); continue; } @@ -78,7 +78,7 @@ void worker::process_shading() if (math::dot(normal, outcoming) <= 0) { ray.stage = models::ray_stage::ACCUMULATE; - map_ray_stage_to_queue(ray); + m_batch_sender.enqueue_ray(ray, models::MASTER_ID); continue; } @@ -105,7 +105,7 @@ void worker::process_shading() ray.color = fvec3::zero; ray.alpha = 1; ray.stage = models::ray_stage::ACCUMULATE; - map_ray_stage_to_queue(ray); + m_batch_sender.enqueue_ray(ray, models::MASTER_ID); continue; } else @@ -199,7 +199,7 @@ void worker::process_shading() if (core::rand() > p) { ray.stage = models::ray_stage::ACCUMULATE; - map_ray_stage_to_queue(ray); + m_batch_sender.enqueue_ray(ray, models::MASTER_ID); continue; } throughput /= p; // Compensate for termination diff --git a/path-tracer-core/src/processors/worker/worker.cpp b/path-tracer-core/src/processors/worker/worker.cpp index 0d87de1..3700768 100644 --- a/path-tracer-core/src/processors/worker/worker.cpp +++ b/path-tracer-core/src/processors/worker/worker.cpp @@ -1,6 +1,7 @@ #include "worker.hpp" #include +#include #include #include #include @@ -39,6 +40,7 @@ void worker::run() m_should_terminate = false; this->resolution = fvec2((info.max_x - info.min_x) + 1, (info.max_y - info.min_y) + 1); + this->global_resolution = fvec2(info.image_width, info.image_height); this->sample_count = info.samples; this->bounce_count = info.bounces; @@ -131,9 +133,9 @@ void worker::generate_rays() aa_offset = fvec2(core::rand(), core::rand()); } - fvec2 ndc = ((fvec2(pixel) + aa_offset) / resolution) * 2 - fvec2::one; + fvec2 ndc = ((fvec2(pixel) + aa_offset) / fvec2(global_resolution)) * 2 - fvec2::one; ndc.y = -ndc.y; - float ratio = static_cast(resolution.x) / resolution.y; + float ratio = static_cast(global_resolution.x) / global_resolution.y; geometry::ray ray = m_scene.m_camera->get_component()->get_ray(ndc, ratio); @@ -145,6 +147,10 @@ void worker::generate_rays() cloud_ray.bounce = bounce_count; cloud_ray.stage = models::ray_stage::INTERSECT; cloud_ray.worker_id = m_worker_info.worker_id; + cloud_ray.object_intersect_distance = std::numeric_limits::max(); + cloud_ray.direct_light_intersect_result = false; + cloud_ray.alpha = 0.0f; + cloud_ray.type = models::ray_type::CALCULATE; map_ray_stage_to_queue(cloud_ray); } diff --git a/path-tracer-core/src/processors/worker/worker.hpp b/path-tracer-core/src/processors/worker/worker.hpp index 5a243de..8f696ee 100644 --- a/path-tracer-core/src/processors/worker/worker.hpp +++ b/path-tracer-core/src/processors/worker/worker.hpp @@ -24,7 +24,8 @@ class worker : public application ~worker() override; public: - math::uvec2 resolution = math::fvec2(640, 480); + math::uvec2 resolution = math::uvec2(640, 480); + math::uvec2 global_resolution = math::uvec2(640, 480); uint32_t sample_count = 50; math::fvec3 environment_factor = math::fvec3::one; bool transparent_background = false; diff --git a/path-tracer-preprocessor/preprocessor-function/app.py b/path-tracer-preprocessor/preprocessor-function/app.py index 465f4d4..3717d3c 100644 --- a/path-tracer-preprocessor/preprocessor-function/app.py +++ b/path-tracer-preprocessor/preprocessor-function/app.py @@ -218,7 +218,9 @@ def lambda_handler(event, context): "min_x": sub_grid[worker_id]["minX"], "max_x": sub_grid[worker_id]["maxX"], "min_y": sub_grid[worker_id]["minY"], - "max_y": sub_grid[worker_id]["maxY"] + "max_y": sub_grid[worker_id]["maxY"], + "image_width": X, + "image_height": Y } worker_infos[worker_id] = worker_info @@ -237,9 +239,11 @@ def lambda_handler(event, context): "samples": samples, "bounces": bounces, "min_x": 0, - "max_x": X, + "max_x": X - 1, "min_y": 0, - "max_y": Y + "max_y": Y - 1, + "image_width": X, + "image_height": Y } for worker_id, worker_info in worker_infos.items():