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