very basic working version
This commit is contained in:
+25
-15
@@ -1,21 +1,28 @@
|
||||
#include "Scene.h"
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
|
||||
Scene::Scene() {}
|
||||
|
||||
Scene::~Scene() {}
|
||||
|
||||
static bool firstTime = true;
|
||||
void Scene::render(Camera cam, RenderParameter params)
|
||||
{
|
||||
pendingCancel = true;
|
||||
worker.join();
|
||||
if (!firstTime)
|
||||
{
|
||||
pendingCancel = true;
|
||||
worker.join();
|
||||
firstTime = false;
|
||||
}
|
||||
pendingCancel = false;
|
||||
image.clear();
|
||||
accumulator.clear();
|
||||
image.resize(params.width * params.height);
|
||||
accumulator.resize(params.width * params.height);
|
||||
worker = std::thread(
|
||||
[&]()
|
||||
{
|
||||
image.clear();
|
||||
accumulator.clear();
|
||||
image.resize(params.width * params.height * 3);
|
||||
accumulator.resize(params.width * params.height * 3);
|
||||
for (int samp = 0; samp < params.numSamples; ++samp)
|
||||
{
|
||||
if (pendingCancel)
|
||||
@@ -23,18 +30,21 @@ void Scene::render(Camera cam, RenderParameter params)
|
||||
Batch batch;
|
||||
for (int w = 0; w < params.width; ++w)
|
||||
{
|
||||
for (int h = 0; h < params.height; ++h)
|
||||
{
|
||||
batch.jobs.push_back(
|
||||
[&]()
|
||||
batch.jobs.push_back(
|
||||
[&, w]()
|
||||
{
|
||||
for (int h = 0; h < params.height; ++h)
|
||||
{
|
||||
Ray r = Ray();
|
||||
bvh.traceRay(r);
|
||||
});
|
||||
}
|
||||
// Ray r = Ray();
|
||||
// bvh.traceRay(r);
|
||||
accumulator[w + h * params.width] +=
|
||||
glm::vec3(w / float(params.width * params.numSamples), h / float(params.height * params.numSamples), 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
threadPool.runBatch(std::move(batch));
|
||||
std::memcpy(image.data(), accumulator.data(), accumulator.size());
|
||||
std::memcpy(image.data(), accumulator.data(), accumulator.size() * sizeof(glm::vec3));
|
||||
std::cout << samp << std::endl;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user