diff options
author | David Doan <daviddoan@Davids-MacBook-Pro-100.local> | 2023-12-12 22:14:26 -0500 |
---|---|---|
committer | David Doan <daviddoan@Davids-MacBook-Pro-100.local> | 2023-12-12 22:14:26 -0500 |
commit | d3e5518638cbdc4ea5c7dcfcdc6b6d71157d7edf (patch) | |
tree | bfa852244c8e8b9e561b5a3281128b2810f3ee3e /src/accelerate/myqtconcurrent.cpp | |
parent | ba17c6e047e817078b433838a2aedbe5d3ce1d21 (diff) |
fixing
Diffstat (limited to 'src/accelerate/myqtconcurrent.cpp')
-rw-r--r-- | src/accelerate/myqtconcurrent.cpp | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/src/accelerate/myqtconcurrent.cpp b/src/accelerate/myqtconcurrent.cpp index aeb160b..1e95436 100644 --- a/src/accelerate/myqtconcurrent.cpp +++ b/src/accelerate/myqtconcurrent.cpp @@ -2,6 +2,7 @@ #include <QList> #include <QtConcurrent> #include "../raytracer/raytracer.h" +#include "../vec4ops/vec4ops.h" struct pixelRoutineArgs { glm::vec4 pCamera; @@ -19,23 +20,50 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene) float viewplaneWidth = cameraDepth*viewplaneHeight*((float)scene.width()/(float)scene.height()); QList<pixelRoutineArgs> l{}; + // for (int imageRow = 0; imageRow < scene.height(); imageRow++) { + // for (int imageCol = 0; imageCol < scene.width(); imageCol++) { + // float xCameraSpace = viewplaneWidth * + // (-.5f + (imageCol + .5f) / scene.width()); + // float yCameraSpace = viewplaneHeight * + // (-.5f + (imageRow + .5f) / scene.height()); + + // glm::vec4 pixelDirCamera{xCameraSpace, -yCameraSpace, -cameraDepth, 0.f}; //w=0 for dir + // glm::vec4 eyeCamera{0.f, 0.f, 0.f, 1.f}; // w=1.f for point + // pixelRoutineArgs args{ + // eyeCamera, + // pixelDirCamera, + // scene, + // this + // }; + // l.append(args); + + // } + // } for (int imageRow = 0; imageRow < scene.height(); imageRow++) { for (int imageCol = 0; imageCol < scene.width(); imageCol++) { - float xCameraSpace = viewplaneWidth * - (-.5f + (imageCol + .5f) / scene.width()); - float yCameraSpace = viewplaneHeight * - (-.5f + (imageRow + .5f) / scene.height()); + // FIXME: for now, use height as depth + for (int imageDepth = 0; imageDepth < scene.height(); 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.height()/2.f) * viewplaneHeight / scene.height(); + float camera4dDepth = 1; + + glm::vec4 pWorld = Vec4Ops::transformPoint4(glm::vec4(0.f), camera.getViewMatrix(), camera.getTranslationVector()); + glm::vec4 dWorld = Vec4Ops::transformVector4(glm::vec4(x, y, z, cameraDepth), camera.getViewMatrix()); - glm::vec4 pixelDirCamera{xCameraSpace, -yCameraSpace, -cameraDepth, 0.f}; //w=0 for dir - glm::vec4 eyeCamera{0.f, 0.f, 0.f, 1.f}; // w=1.f for point - pixelRoutineArgs args{ - eyeCamera, - pixelDirCamera, - scene, - this - }; - l.append(args); + // get the pixel color + glm::vec4 pixelColor = getPixelFromRay(pWorld, dWorld, scene, 0); + // 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); |