diff options
author | sotech117 <michael_foiani@brown.edu> | 2023-12-13 02:27:47 -0500 |
---|---|---|
committer | sotech117 <michael_foiani@brown.edu> | 2023-12-13 02:27:52 -0500 |
commit | 62c7e79578bd53b567760969e6d85ded510702e1 (patch) | |
tree | 15ba5768c0e2f630b8513f47a1ef8bf2f3b5c125 /src | |
parent | 7de05373a0423a24f9719b0158bc9a78e3238aef (diff) |
use parallel
Diffstat (limited to 'src')
-rw-r--r-- | src/accelerate/myqtconcurrent.cpp | 49 | ||||
-rw-r--r-- | src/camera/camera.cpp | 5 | ||||
-rw-r--r-- | src/camera/camera.h | 12 |
3 files changed, 28 insertions, 38 deletions
diff --git a/src/accelerate/myqtconcurrent.cpp b/src/accelerate/myqtconcurrent.cpp index bf99070..08248f4 100644 --- a/src/accelerate/myqtconcurrent.cpp +++ b/src/accelerate/myqtconcurrent.cpp @@ -7,8 +7,8 @@ #include "settings.h" struct pixelRoutineArgs { - glm::vec4 pCamera; - glm::vec4 dCamera; + glm::vec4 pWorld; + glm::vec4 dWorld; const RayTraceScene &scene; RayTracer *rt; }; @@ -44,7 +44,7 @@ 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 + // FIXME: for now, use W slider ad depth int imageDepth = (int) ((settings.w + 100.f) * (5.f / 2.f)); // compute the ray float x = (imageCol - scene.width()/2.f) * viewplaneWidth / scene.width(); @@ -53,17 +53,14 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene) 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); - // 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) - }; + pixelRoutineArgs args{ + pWorld, + dWorld, + scene, + this + }; + l.append(args); } } QList<RGBA> pixels = QtConcurrent::blockingMapped(l, pixelRoutine); @@ -72,8 +69,12 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene) // get the slice relating to z == 0 and set it into int the iamge data array // int currentSlice = settings.w + 100.f * (5.f / 2.f); + int index = 0; + for (RGBA p : pixels) { + imageData[index++] = p; + } - std::cout << " here " << std::endl; + std::cout << "done rendering" << std::endl; if (m_enableAntiAliasing) { @@ -84,27 +85,11 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene) RGBA pixelRoutine(pixelRoutineArgs args) { - auto eyeCamera = args.pCamera; - auto pixelDirCamera = args.dCamera; + auto pWorld = args.pWorld; + auto dWorld = args.dWorld; auto scene = args.scene; auto rt = args.rt; - // convert camera space to world space - auto inv = scene.getCamera().getInverseViewMatrix(); - glm::vec4 pWorld = inv * eyeCamera; - glm::vec4 dWorld = glm::normalize(inv * pixelDirCamera); - - if (rt->m_enableDepthOfField) - { - // if we're doing depth of field, we need to shoot multiple rays, see camera.cpp - return RayTracer::toRGBA(rt->secondaryRays(pWorld, dWorld, scene)); - } - if (rt->m_enableSuperSample) - { - // if we're doing super sampling, we need to shoot multiple rays, see raytracer.cpp - return rt->superSample(eyeCamera, pixelDirCamera, scene); - } - // shoot ray! RGBA pixel = RayTracer::toRGBA(rt->getPixelFromRay(pWorld, dWorld, scene, 0)); return pixel; diff --git a/src/camera/camera.cpp b/src/camera/camera.cpp index 5097b6c..78ae483 100644 --- a/src/camera/camera.cpp +++ b/src/camera/camera.cpp @@ -32,6 +32,11 @@ glm::mat4 Camera::getInverseViewMatrix() const { return m_inverseViewMatrix; } +glm::vec4 Camera::getPos() const { + // Optional TODO: implement the getter or make your own design + return m_pos; +} + glm::vec4 Camera::getTranslationVector() const { return m_translationVector; } diff --git a/src/camera/camera.h b/src/camera/camera.h index a6e8c0a..08750fb 100644 --- a/src/camera/camera.h +++ b/src/camera/camera.h @@ -35,21 +35,21 @@ public: // You can ignore if you are not attempting to implement depth of field. float getAperture() const; - glm::vec3 getPos() const; + glm::vec4 getPos() const; float cameraDepth = -1.f; std::vector<glm::vec3> m_controlPoints; private: - glm::mat4 m_viewMatrix; - glm::mat4 m_inverseViewMatrix; + glm::mat4 m_viewMatrix{}; + glm::mat4 m_inverseViewMatrix{}; float m_heightAngle; - glm::vec3 m_pos; + glm::vec4 m_pos; float m_focalLength; float m_aperture; - glm::vec4 m_translationVector; - glm::vec4 m_inverseTranslationVector; + glm::vec4 m_translationVector{}; + glm::vec4 m_inverseTranslationVector{}; }; |