aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-13 01:31:00 -0500
committerDavid Doan <daviddoan@Davids-MacBook-Pro-193.local>2023-12-13 01:31:00 -0500
commit086dff023dc8a13d5e3a8867a845d6244409c8ef (patch)
tree38fb8b60f69dc307e7c61f06817d3821f5a6a9a7 /src
parente5e01a62cd12a338b66c0a33775e91854a305ec4 (diff)
parent07776876eb4638a224fd332944ce9ddca1f5a592 (diff)
Merge branch 'main' of https://github.com/NicholasBottone/the-all-americans-in-cs1230
grinds and merge:
Diffstat (limited to 'src')
-rw-r--r--src/accelerate/myqtconcurrent.cpp34
-rw-r--r--src/illuminate/illuminate.cpp1
-rw-r--r--src/intersect/intersect.cpp2
-rw-r--r--src/raytracer/raytracer.cpp7
-rw-r--r--src/utils/scenefilereader.cpp4
-rw-r--r--src/vec4ops/transform4d.cpp2
-rw-r--r--src/vec4ops/vec4ops.cpp7
7 files changed, 33 insertions, 24 deletions
diff --git a/src/accelerate/myqtconcurrent.cpp b/src/accelerate/myqtconcurrent.cpp
index 9f51cdd..12e9138 100644
--- a/src/accelerate/myqtconcurrent.cpp
+++ b/src/accelerate/myqtconcurrent.cpp
@@ -1,6 +1,7 @@
#include <QList>
#include <QtConcurrent>
+#include <iostream>
#include "../raytracer/raytracer.h"
#include "../vec4ops/vec4ops.h"
#include "settings.h"
@@ -48,21 +49,29 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene)
// 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.width()/2.f) * viewplaneDepth / scene.width();
+ 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::inverseTransformDir4(glm::vec4(x, y, z, -1.0), camera.getViewMatrix());
+ 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)
- };
+ 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)
+ };
+ }
+
}
}
}
@@ -72,11 +81,8 @@ 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 currentSlice = 0;
- int ptr = currentSlice * scene.width() * scene.height();
- for (int i = 0; i < scene.width() * scene.height(); i++) {
- imageData[i] = pixels[ptr + i];
- }
+
+ std::cout << " here " << std::endl;
if (m_enableAntiAliasing)
{
diff --git a/src/illuminate/illuminate.cpp b/src/illuminate/illuminate.cpp
index a093fd1..39ecccb 100644
--- a/src/illuminate/illuminate.cpp
+++ b/src/illuminate/illuminate.cpp
@@ -1,3 +1,4 @@
+#include <iostream>
#include "raytracer/raytracer.h"
glm::vec4 RayTracer::illuminationFromPointLight(
diff --git a/src/intersect/intersect.cpp b/src/intersect/intersect.cpp
index 353508e..69512e3 100644
--- a/src/intersect/intersect.cpp
+++ b/src/intersect/intersect.cpp
@@ -1,3 +1,4 @@
+#include <iostream>
#include "raytracer/raytracer.h"
/**
@@ -28,6 +29,7 @@ glm::vec4 intersectCircle(
return glm::vec4(0.f);
}
+
float t1 = (-b - std::sqrt(discriminant)) / (2.f*a);
float t2 = (-b + std::sqrt(discriminant)) / (2.f*a);
if (t1 <= 0 && t2 <= 0) // both behind camera
diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp
index 181b995..d9d467d 100644
--- a/src/raytracer/raytracer.cpp
+++ b/src/raytracer/raytracer.cpp
@@ -91,9 +91,10 @@ glm::vec4 RayTracer::getPixelFromRay(
float minDist = FINF;
// shoot a ray at each shape
for (const RenderShapeData &shape : scene.getShapes()) {
- glm::vec4 pObject = Vec4Ops::inverseTransformPoint4(pWorld, shape.inverseCTM, shape.translation4d);
- glm::vec4 dObject = glm::normalize(Vec4Ops::transformDir4(dWorld, shape.inverseCTM));
- std::cout << "pObject: " << pObject.w << std::endl;
+ glm::vec4 pObject = Vec4Ops::inverseTransformPoint4(pWorld, shape.inverseCTM, shape.inverseTranslation4d);
+ glm::vec4 dObject = glm::normalize(Vec4Ops::inverseTransformDir4(dWorld, shape.inverseCTM));
+// std::cout << "pObject: " << pObject.x << ", " << pObject.y << ", " << pObject.z << ", " << pObject.w << std::endl;
+// std::cout << "dObject: " << dObject.x << ", " << dObject.y << ", " << dObject.z << ", " << dObject.w << std::endl;
bool isHit = false;
glm::vec4 newIntersectionObj = findIntersection(pObject, dObject, shape, isHit);
if (!isHit) // no hit
diff --git a/src/utils/scenefilereader.cpp b/src/utils/scenefilereader.cpp
index dc36346..928c118 100644
--- a/src/utils/scenefilereader.cpp
+++ b/src/utils/scenefilereader.cpp
@@ -292,7 +292,7 @@ bool ScenefileReader::parseLightData(const QJsonObject &lightData, SceneNode *no
return false;
}
QJsonArray directionArray = lightData["direction"].toArray();
- if (directionArray.size() != 3) {
+ if (directionArray.size() != 3 && directionArray.size() != 4) {
std::cout << "directional light direction must be of size 3" << std::endl;
return false;
}
@@ -952,7 +952,7 @@ bool ScenefileReader::parsePrimitive(const QJsonObject &prim, SceneNode *node) {
QStringList requiredFields = {"type"};
QStringList optionalFields = {
"meshFile", "ambient", "diffuse", "specular", "reflective", "transparent", "shininess", "ior",
- "blend", "textureFile", "textureU", "textureV", "bumpMapFile", "bumpMapU", "bumpMapV"};
+ "blend", "textureFile", "textureU", "textureV", "bumpMapFile", "bumpMapU", "bumpMapV", "velocity"};
QStringList allFields = requiredFields + optionalFields;
for (auto field : prim.keys()) {
diff --git a/src/vec4ops/transform4d.cpp b/src/vec4ops/transform4d.cpp
index 66ca8e3..48957f4 100644
--- a/src/vec4ops/transform4d.cpp
+++ b/src/vec4ops/transform4d.cpp
@@ -13,7 +13,7 @@ glm::vec4 Vec4Ops::transformPoint4(glm::vec4 point4, glm::mat4 transformDirecti
glm::vec4 Vec4Ops::inverseTransformPoint4(glm::vec4 point4, glm::mat4 inverseTransformDirectionMatrix, glm::vec4 inverseTranslationPointVector) {
// do the direction then translation
point4 += inverseTranslationPointVector;
- point4 = inverseTranslationPointVector * point4;
+ point4 = inverseTransformDirectionMatrix * point4;
return point4;
}
diff --git a/src/vec4ops/vec4ops.cpp b/src/vec4ops/vec4ops.cpp
index 9bd29e8..3ef939a 100644
--- a/src/vec4ops/vec4ops.cpp
+++ b/src/vec4ops/vec4ops.cpp
@@ -23,7 +23,6 @@ glm::vec4 Vec4Ops::cross4(
result[1] = -(u[0] * f) + (u[2] * c) - (u[3] * b);
result[2] = (u[0] * e) - (u[1] * c) + (u[3] * a);
result[3] = -(u[0] * d) + (u[1] * b) - (u[2] * a);
-
return result;
}
@@ -34,8 +33,8 @@ glm::vec4 Vec4Ops::dot4(
}
glm::mat4 Vec4Ops::getViewMatrix4(
- glm::vec4 upVector,
glm::vec4 lookVector,
+ glm::vec4 upVector,
glm::vec4 overVector) {
// start with the e3 basis vector, the normalized look vector
glm::vec4 e3 = glm::normalize(lookVector);
@@ -43,14 +42,14 @@ glm::mat4 Vec4Ops::getViewMatrix4(
// calculate e0 basis vector, from the combinatory cross of up and over with e3
glm::vec4 e0 = cross4(upVector, overVector, e3);
e0 = glm::normalize(e0);
- if (glm::distance(e0, glm::vec4{0, 0, 0, 0}) < 0.0001f) {
+ if (glm::isnan(e0[0]) || glm::isnan(e0[1]) || glm::isnan(e0[2]) || glm::isnan(e0[3])) {
throw std::runtime_error("invalid up vector");
}
// calculate e1 basis vector, from the cross of only the over vector
glm::vec4 e1 = cross4(overVector, e3, e0);
e1 = glm::normalize(e1);
- if (glm::distance(e1, glm::vec4{0, 0, 0, 0}) < 0.0001f) {
+ if (glm::isnan(e1[0]) || glm::isnan(e1[1]) || glm::isnan(e1[2]) || glm::isnan(e1[3])) {
throw std::runtime_error("invalid over vector");
}