diff options
author | David Doan <daviddoan@Davids-MacBook-Pro-193.local> | 2023-12-13 01:37:28 -0500 |
---|---|---|
committer | David Doan <daviddoan@Davids-MacBook-Pro-193.local> | 2023-12-13 01:37:28 -0500 |
commit | 8afef246ac0d7adf03eae794fc1ba5ba25f64dd8 (patch) | |
tree | 05582f1d5a50ca9d21c9c12d06dd258d40b113a3 /src | |
parent | a31f51672fe92d8d5cb2c9319a0ba35a52d3b51b (diff) | |
parent | 8337f9b0b63e2e63b714acd5d24b622d7330cbc2 (diff) |
Merge branch 'main' of https://github.com/NicholasBottone/the-all-americans-in-cs1230
render button
Diffstat (limited to 'src')
-rw-r--r-- | src/accelerate/myqtconcurrent.cpp | 49 | ||||
-rw-r--r-- | src/raytracer/raytracer.cpp | 17 | ||||
-rw-r--r-- | src/raytracer/raytracer.h | 1 | ||||
-rw-r--r-- | src/settings.h | 3 |
4 files changed, 42 insertions, 28 deletions
diff --git a/src/accelerate/myqtconcurrent.cpp b/src/accelerate/myqtconcurrent.cpp index 12e9138..1615bca 100644 --- a/src/accelerate/myqtconcurrent.cpp +++ b/src/accelerate/myqtconcurrent.cpp @@ -45,34 +45,29 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene) for (int imageRow = 0; imageRow < scene.height(); imageRow++) { for (int imageCol = 0; imageCol < scene.width(); imageCol++) { // FIXME: for now, use height as depth - for (int imageDepth = 0; imageDepth < scene.depth(); imageDepth++) { - // compute the ray - float x = (imageCol - scene.width()/2.f) * viewplaneWidth / scene.width(); - float y = (imageRow - scene.height()/2.f) * viewplaneHeight / scene.height(); - float z = (imageDepth - scene.depth()/2.f) * viewplaneDepth / scene.depth(); - - glm::vec4 pWorld = Vec4Ops::transformPoint4(glm::vec4(0.f), camera.getViewMatrix(), camera.getTranslationVector()); - glm::vec4 dWorld = Vec4Ops::transformDir4(glm::vec4(x, y, z, -1.0), camera.getViewMatrix()); - // get the pixel color - glm::vec4 pixelColor = getPixelFromRay(pWorld, dWorld, scene, 0); - - if (pixelColor.r > 0) { - std::cout << "pixelColor.r: " << pixelColor.r << ", x" << imageCol << ", y" << imageRow << ", z" << imageDepth << std::endl; - } - - // set the pixel color - if (imageDepth == 250) - { - int index = imageRow * scene.width() + imageCol; - imageData[index] = RGBA{ - (std::uint8_t) (pixelColor.r * 255.f), - (std::uint8_t) (pixelColor.g * 255.f), - (std::uint8_t) (pixelColor.b * 255.f), - (std::uint8_t) (pixelColor.a * 255.f) - }; - } - + int imageDepth = (int) ((settings.w + 100.f) * (5.f / 2.f)); + // compute the ray + float x = (imageCol - scene.width()/2.f) * viewplaneWidth / scene.width(); + float y = (imageRow - scene.height()/2.f) * viewplaneHeight / scene.height(); + float z = (imageDepth - scene.depth()/2.f) * viewplaneDepth / scene.depth(); + + glm::vec4 pWorld = Vec4Ops::transformPoint4(glm::vec4(0.f), camera.getViewMatrix(), camera.getTranslationVector()); + glm::vec4 dWorld = Vec4Ops::transformDir4(glm::vec4(x, y, z, -1.0), camera.getViewMatrix()); + // get the pixel color + glm::vec4 pixelColor = getPixelFromRay(pWorld, dWorld, scene, 0); + + if (pixelColor.r > 0) { + std::cout << "pixelColor.r: " << pixelColor.r << ", x" << imageCol << ", y" << imageRow << ", z" << imageDepth << std::endl; } + + // set the pixel color + int index = imageRow * scene.width() + imageCol; + imageData[index] = RGBA{ + (std::uint8_t) (pixelColor.r * 255.f), + (std::uint8_t) (pixelColor.g * 255.f), + (std::uint8_t) (pixelColor.b * 255.f), + (std::uint8_t) (pixelColor.a * 255.f) + }; } } QList<RGBA> pixels = QtConcurrent::blockingMapped(l, pixelRoutine); diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp index 449a04a..f831f82 100644 --- a/src/raytracer/raytracer.cpp +++ b/src/raytracer/raytracer.cpp @@ -68,7 +68,17 @@ void RayTracer::render(RGBA *imageData, const RayTraceScene &scene) { } } } - settings.rotation += 0.5f; + + if (settings.bulkOutputFilePath.size() > 0) { // means we are doing bulk rendering + // save the image to the bulk directory + std::string filePath = settings.bulkOutputFilePath + QDir::separator().toLatin1() + std::to_string(settings.currentTime) + ".png"; + saveViewportImage(filePath); + if (settings.currentTime < settings.maxTime) { // still more to render + // render the next frame + settings.currentTime++; + emit settingsChanged(m_imageLabel); // emit to allow the UI to update then render the next frame + } + } } @@ -197,6 +207,7 @@ void RayTracer::settingsChanged(QLabel* imageLabel) { QImage image = QImage(576, 432, QImage::Format_RGBX8888); image.fill(Qt::black); RGBA *data = reinterpret_cast<RGBA *>(image.bits()); + m_imageData = data; imageLabel->setPixmap(QPixmap::fromImage(image)); return; } @@ -288,3 +299,7 @@ void RayTracer::keyReleaseEvent(QKeyEvent *event) { m_keyMap[Qt::Key(event->key())] = false; } +void RayTracer::saveViewportImage(std::string filePath) { + QImage image = QImage((uchar *) m_imageData, 576, 432, QImage::Format_RGBX8888); + image.save(QString::fromStdString(filePath)); +} diff --git a/src/raytracer/raytracer.h b/src/raytracer/raytracer.h index cf32a99..da4ec2d 100644 --- a/src/raytracer/raytracer.h +++ b/src/raytracer/raytracer.h @@ -177,6 +177,7 @@ public: int m_depth; QImage m_image; + void saveViewportImage(std::string filename); signals: void xyRotationChanged(float value); void xzRotationChanged(float value); diff --git a/src/settings.h b/src/settings.h index 1d9e358..0865e44 100644 --- a/src/settings.h +++ b/src/settings.h @@ -15,6 +15,9 @@ struct Settings { float rotation = 0.f; bool negative = false; float w = 0.f; + int currentTime = 0; + int maxTime = 0; + std::string bulkOutputFilePath; }; |