minor fix
This commit is contained in:
+10
-7
@@ -20,15 +20,18 @@ Renderer::~Renderer() {}
|
||||
|
||||
void Renderer::startRender(Camera cam, RenderParameter params)
|
||||
{
|
||||
threadPool.cancel();
|
||||
pendingCancel = true;
|
||||
if (worker.joinable())
|
||||
//threadPool.cancel();
|
||||
if (running)
|
||||
{
|
||||
running = false;
|
||||
worker.join();
|
||||
pendingCancel = false;
|
||||
}
|
||||
sampleTimes.clear();
|
||||
image.clear();
|
||||
accumulator.clear();
|
||||
image.resize(params.width * params.height);
|
||||
accumulator.resize(params.width * params.height);
|
||||
running = true;
|
||||
worker = std::thread(&Renderer::render, this, cam, params);
|
||||
}
|
||||
|
||||
@@ -43,7 +46,7 @@ void Renderer::render(Camera camera, RenderParameter params)
|
||||
{
|
||||
for (int samp = 0; samp < params.numSamples; ++samp)
|
||||
{
|
||||
if (pendingCancel)
|
||||
if (!running)
|
||||
return;
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
Batch batch;
|
||||
@@ -89,7 +92,7 @@ void Renderer::render(Camera camera, RenderParameter params)
|
||||
glm::vec3 focalPoint = cam.origin + (camera.S_O + S_I) * cam.direction;
|
||||
float t = glm::dot(focalPoint - r.origin, lensN) / glm::dot(r.direction, lensN);
|
||||
glm::vec3 focus = r.origin + t * r.direction;
|
||||
r = Ray(lensSample, normalize(focus - lensSample)); // TODO: Fix lens
|
||||
// r = Ray(lensSample, normalize(focus - lensSample)); // TODO: Fix lens
|
||||
|
||||
bvh.traceRay(r, payload, 1e-4, 1e20);
|
||||
|
||||
@@ -101,7 +104,7 @@ void Renderer::render(Camera camera, RenderParameter params)
|
||||
threadPool.runBatch(std::move(batch));
|
||||
auto end = std::chrono::high_resolution_clock::now();
|
||||
sampleTimes.push_back(std::chrono::duration_cast<std::chrono::microseconds>(end - start).count() / 1000.0f);
|
||||
float resolver = float(params.numSamples) / float(samp);
|
||||
float resolver = float(params.numSamples) / float(samp+1);
|
||||
for (uint32_t i = 0; i < accumulator.size(); ++i)
|
||||
{
|
||||
image[i] = glm::pow(glm::max(accumulator[i] * resolver, 0.0f), glm::vec3(0.45f));
|
||||
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
virtual void render(Camera cam, RenderParameter params);
|
||||
ThreadPool threadPool;
|
||||
std::thread worker;
|
||||
std::atomic_bool pendingCancel = false;
|
||||
std::atomic_bool running = false;
|
||||
std::vector<float> sampleTimes;
|
||||
float lastSampleTime;
|
||||
float averageSampleTime;
|
||||
|
||||
+3
-5
@@ -154,12 +154,11 @@ bool Scene::testIntersection(const PNode& currentNode, const Ray ray, const floa
|
||||
return leftResults || rightResults;
|
||||
}
|
||||
|
||||
IntersectionInfo Scene::generateIntersections(const PNode& currentNode, const Ray ray, const float tmin,
|
||||
float tmax) const noexcept
|
||||
IntersectionInfo Scene::generateIntersections(const PNode& currentNode, const Ray ray, const float tmin, float tmax) const noexcept
|
||||
{
|
||||
if (!currentNode->aabb.intersects(ray, tmin, tmax))
|
||||
{
|
||||
// return {};
|
||||
return {};
|
||||
}
|
||||
if (currentNode->model.numIndices > 0)
|
||||
{
|
||||
@@ -219,8 +218,7 @@ bool Scene::testModel(const ModelReference& reference, const Ray ray, const floa
|
||||
|
||||
return false;
|
||||
}
|
||||
IntersectionInfo Scene::intersectModel(const ModelReference& reference, const Ray ray, const float tmin,
|
||||
float tmax) const noexcept
|
||||
IntersectionInfo Scene::intersectModel(const ModelReference& reference, const Ray ray, const float tmin, float tmax) const noexcept
|
||||
{
|
||||
IntersectionInfo intersection = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user