Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
.aws-sam/
.DS_Store
.DS_Store_codeql_detected_source_root
5 changes: 0 additions & 5 deletions path-tracer-core/src/cloud/batch_sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ void batch_sender::flush_loop()
std::unique_lock<std::mutex> lock(m_mutex);
m_cv.wait_for(lock, m_flush_interval, [this]() { return m_terminate.load(); });

if (m_terminate)
{
break;
}

std::vector<std::pair<std::string, std::vector<models::cloud_ray>>> batches_to_send;
for (auto &pair : m_pending_rays)
{
Expand Down
5 changes: 4 additions & 1 deletion path-tracer-core/src/models/work_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion path-tracer-core/src/processors/master/master.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion path-tracer-core/src/processors/master/master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class master : public application
private:
models::worker_info m_worker_info;
std::vector<std::vector<pixel>> pixels;
math::uvec2 resolution = math::fvec2(640, 480);
math::uvec2 resolution = math::uvec2(640, 480);
bool transparent_background = false;
uint32_t sample_count = 50;

Expand Down
10 changes: 9 additions & 1 deletion path-tracer-core/src/processors/worker/intersection_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions path-tracer-core/src/processors/worker/shading_worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions path-tracer-core/src/processors/worker/worker.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "worker.hpp"

#include <cstdint>
#include <limits>
#include <path_tracer/core/pbr.hpp>
#include <path_tracer/core/renderer.hpp>
#include <path_tracer/core/utils.hpp>
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<float>(resolution.x) / resolution.y;
float ratio = static_cast<float>(global_resolution.x) / global_resolution.y;

geometry::ray ray = m_scene.m_camera->get_component<scene::camera>()->get_ray(ndc, ratio);

Expand All @@ -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<float>::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);
}
Expand Down
3 changes: 2 additions & 1 deletion path-tracer-core/src/processors/worker/worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions path-tracer-preprocessor/preprocessor-function/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down