2025-01-24 00:19:11 +01:00
|
|
|
#include "Scene.h"
|
|
|
|
|
|
2025-01-24 21:54:38 +01:00
|
|
|
Scene::Scene() {}
|
2025-01-24 21:01:01 +01:00
|
|
|
|
|
|
|
|
Scene::~Scene() {}
|
|
|
|
|
|
2025-01-24 21:54:38 +01:00
|
|
|
void Scene::render(Camera cam, RenderParameter params)
|
2025-01-24 18:21:34 +01:00
|
|
|
{
|
2025-01-24 21:54:38 +01:00
|
|
|
pendingCancel = true;
|
|
|
|
|
worker.join();
|
|
|
|
|
pendingCancel = false;
|
2025-01-24 21:20:06 +01:00
|
|
|
worker = std::thread(
|
|
|
|
|
[&]()
|
2025-01-24 21:01:01 +01:00
|
|
|
{
|
2025-01-24 21:20:06 +01:00
|
|
|
image.clear();
|
|
|
|
|
accumulator.clear();
|
2025-01-24 21:54:38 +01:00
|
|
|
image.resize(params.width * params.height * 3);
|
|
|
|
|
accumulator.resize(params.width * params.height * 3);
|
|
|
|
|
for (int samp = 0; samp < params.numSamples; ++samp)
|
2025-01-24 21:01:01 +01:00
|
|
|
{
|
2025-01-24 21:54:38 +01:00
|
|
|
if (pendingCancel)
|
|
|
|
|
return;
|
|
|
|
|
Batch batch;
|
|
|
|
|
for (int w = 0; w < params.width; ++w)
|
2025-01-24 21:20:06 +01:00
|
|
|
{
|
2025-01-24 21:54:38 +01:00
|
|
|
for (int h = 0; h < params.height; ++h)
|
2025-01-24 21:20:06 +01:00
|
|
|
{
|
2025-01-24 21:54:38 +01:00
|
|
|
batch.jobs.push_back(
|
|
|
|
|
[&]()
|
|
|
|
|
{
|
|
|
|
|
Ray r = Ray();
|
|
|
|
|
bvh.traceRay(r);
|
|
|
|
|
});
|
2025-01-24 21:20:06 +01:00
|
|
|
}
|
2025-01-24 21:54:38 +01:00
|
|
|
}
|
|
|
|
|
threadPool.runBatch(std::move(batch));
|
|
|
|
|
std::memcpy(image.data(), accumulator.data(), accumulator.size());
|
2025-01-24 21:01:01 +01:00
|
|
|
}
|
2025-01-24 21:20:06 +01:00
|
|
|
});
|
2025-01-24 18:21:34 +01:00
|
|
|
}
|