Basic scene loop
This commit is contained in:
+22
-16
@@ -1,34 +1,40 @@
|
||||
#include "Scene.h"
|
||||
|
||||
Scene::Scene(glm::vec3 cameraPos, glm::vec3 cameraDirection) : cameraPos(cameraPos), cameraDirection(cameraDirection) {}
|
||||
Scene::Scene() {}
|
||||
|
||||
Scene::~Scene() {}
|
||||
|
||||
void Scene::render(int width, int height, int numSamples)
|
||||
void Scene::render(Camera cam, RenderParameter params)
|
||||
{
|
||||
pendingCancel = true;
|
||||
worker.join();
|
||||
pendingCancel = false;
|
||||
worker = std::thread(
|
||||
[&]()
|
||||
{
|
||||
image.clear();
|
||||
accumulator.clear();
|
||||
image.resize(width * height * 3);
|
||||
for (int samp = 0; samp < numSamples; ++samp)
|
||||
image.resize(params.width * params.height * 3);
|
||||
accumulator.resize(params.width * params.height * 3);
|
||||
for (int samp = 0; samp < params.numSamples; ++samp)
|
||||
{
|
||||
std::function<void()> job = [&]()
|
||||
if (pendingCancel)
|
||||
return;
|
||||
Batch batch;
|
||||
for (int w = 0; w < params.width; ++w)
|
||||
{
|
||||
std::vector<unsigned char> localAccumulator(width * height * 3);
|
||||
for (int w = 0; w < width; ++w)
|
||||
for (int h = 0; h < params.height; ++h)
|
||||
{
|
||||
for (int h = 0; h < height; ++h)
|
||||
{
|
||||
if (cancel)
|
||||
return;
|
||||
bvh.traceRay();
|
||||
}
|
||||
batch.jobs.push_back(
|
||||
[&]()
|
||||
{
|
||||
Ray r = Ray();
|
||||
bvh.traceRay(r);
|
||||
});
|
||||
}
|
||||
// lock image
|
||||
// add result to image
|
||||
};
|
||||
}
|
||||
threadPool.runBatch(std::move(batch));
|
||||
std::memcpy(image.data(), accumulator.data(), accumulator.size());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+12
-12
@@ -2,26 +2,26 @@
|
||||
#include "BVH.h"
|
||||
#include "window/Window.h"
|
||||
#include "util/Camera.h"
|
||||
#include "ThreadPool.h"
|
||||
|
||||
struct RenderParameter
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int numSamples;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Ray1
|
||||
/// Ray2
|
||||
/// Ray3
|
||||
/// Ray4
|
||||
/// Ray5
|
||||
/// GammaResolve
|
||||
/// Ray1
|
||||
/// Ray2
|
||||
/// Ray3
|
||||
/// </summary>
|
||||
class Scene
|
||||
{
|
||||
public:
|
||||
Scene();
|
||||
~Scene();
|
||||
void render(Camera cam, int width, int height, int numSamples);
|
||||
void render(Camera cam, RenderParameter params);
|
||||
constexpr const std::vector<unsigned char>& getImage() const { return image; }
|
||||
private:
|
||||
std::atomic_bool pendingCancel = false;
|
||||
ThreadPool threadPool;
|
||||
std::thread worker;
|
||||
// the thing being displayed
|
||||
std::vector<unsigned char> image;
|
||||
// radiance accumulator
|
||||
|
||||
Reference in New Issue
Block a user