Merge issue cleanup

This commit is contained in:
arvid schröder 2022-12-12 14:56:14 +01:00
parent 21d82ec5e2
commit 63a0ec8f28
2 changed files with 49 additions and 71 deletions

View file

@ -38,25 +38,5 @@ Texture KDTreeRenderer::renderKDTree(FastScene const &scene, Camera const &camer
image.setPixelAt(x, y, (1.0f - factor) * g + factor * r);
}
}
int max = 0;
float const aspectRatio = static_cast<float>(height) / static_cast<float>(width);
for (int x = 0; x < image.width(); ++x) {
std::vector<int> ints;
ints.reserve(height);
for (int y = 0; y < image.height(); ++y) {
Ray ray = camera.createRay((static_cast<float>(x) / image.width() * 2.0f - 1),
-(static_cast<float>(y) / image.height() * 2 - 1) * aspectRatio);
ints.push_back(scene.countNodeIntersections(ray));
max = std::max(ints[y], max);
}
intersections.push_back(std::move(ints));
}
for (int x = 0; x < image.width(); ++x) {
for (int y = 0; y < image.height(); ++y) {
image.setPixelAt(x, y, clamped(static_cast<float>(max - intersections[x][y]) / max * GREEN +
static_cast<float>(intersections[x][y]) / max * RED));
}
}
return image;
}

View file

@ -5,7 +5,6 @@
#include <thread>
#include <chrono>
#include <iomanip>
#include <thread>
void SimpleRenderer::renderThread(const Scene *scene, Camera const *camera, Texture *image, int width, int widthStep, int widthOffset, int height, int heightStep, int heightOffset, std::atomic<int> *k, int const stepSize) {
float const aspectRatio = static_cast<float>(height) / width;
@ -34,15 +33,14 @@ Texture SimpleRenderer::renderImage(Scene const &scene, Camera const &camera, in
// Super-hacky progress bar!
std::cout << "(SimpleRenderer): Begin rendering..." << std::endl;
std::cout << "| 0%";
int const barSizeGoal = 100;
int const stepSize = width / barSizeGoal;
for (int i = 0; i < width / stepSize - 3 - 5; ++i)
int const barSize = 50;
int const stepSize = (width * height) / barSize;
for (int i = 0; i < barSize - 3 - 5; ++i)
std::cout << " ";
std::cout << "100% |" << std::endl << "|";
std::atomic<int> k(0);
// Start timer
start = std::chrono::steady_clock::now();
/* Start timer */ start = std::chrono::steady_clock::now();
// Spawn a thread for every logical processor -1, calling the renderThread function
int const nThreads = std::thread::hardware_concurrency();