aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/accelerate/bvh.cpp6
-rw-r--r--src/accelerate/kdtree.cpp6
-rw-r--r--src/accelerate/myqtconcurrent.cpp2
-rw-r--r--src/illuminate/shadow.cpp3
-rw-r--r--src/intersect/intersect.cpp30
-rw-r--r--src/raytracer/raytracer.h5
6 files changed, 37 insertions, 15 deletions
diff --git a/src/accelerate/bvh.cpp b/src/accelerate/bvh.cpp
index 19f9390..2949cbe 100644
--- a/src/accelerate/bvh.cpp
+++ b/src/accelerate/bvh.cpp
@@ -114,8 +114,8 @@ float RayTracer::traverseBVH(
for (const auto &shape: current.shapes) {
glm::vec4 pObject = shape.shape.inverseCTM * p;
glm::vec4 dObject = glm::normalize(shape.shape.inverseCTM * d);
-
- glm::vec4 intersection = findIntersection(pObject, dObject, shape.shape);
+ bool isHit = false;
+ glm::vec4 intersection = findIntersection(pObject, dObject, shape.shape, isHit);
if (intersection.w == 0.f) {
continue;
}
@@ -148,4 +148,4 @@ float RayTracer::traverseBVH(
}
return minT;
-} \ No newline at end of file
+}
diff --git a/src/accelerate/kdtree.cpp b/src/accelerate/kdtree.cpp
index 4156c98..f025b0a 100644
--- a/src/accelerate/kdtree.cpp
+++ b/src/accelerate/kdtree.cpp
@@ -218,8 +218,8 @@ float RayTracer::traverse(
for (const auto &shape: tree->shapesWithinBounds) {
glm::vec4 pObject = shape.shape.inverseCTM * p;
glm::vec4 dObject = glm::normalize(shape.shape.inverseCTM * d);
-
- glm::vec4 intersection = findIntersection(pObject, dObject, shape.shape);
+ bool isHit = false;
+ glm::vec4 intersection = findIntersection(pObject, dObject, shape.shape, isHit);
if (intersection.w == 0.f) {
continue;
}
@@ -270,4 +270,4 @@ float RayTracer::traverse(
}
return traverse(p, d, t, tEnd, testShape, tree->rightChild);
}
-} \ No newline at end of file
+}
diff --git a/src/accelerate/myqtconcurrent.cpp b/src/accelerate/myqtconcurrent.cpp
index 1e95436..7bfc879 100644
--- a/src/accelerate/myqtconcurrent.cpp
+++ b/src/accelerate/myqtconcurrent.cpp
@@ -50,7 +50,7 @@ void RayTracer::renderParallel(RGBA *imageData, const RayTraceScene &scene)
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 dWorld = Vec4Ops::transformDir4(glm::vec4(x, y, z, cameraDepth), camera.getViewMatrix());
// get the pixel color
glm::vec4 pixelColor = getPixelFromRay(pWorld, dWorld, scene, 0);
diff --git a/src/illuminate/shadow.cpp b/src/illuminate/shadow.cpp
index efb52a7..6057637 100644
--- a/src/illuminate/shadow.cpp
+++ b/src/illuminate/shadow.cpp
@@ -26,7 +26,8 @@ bool RayTracer::isShadowed(
glm::vec4 pObject = s.inverseCTM * intersectionWorld;
// see if there is an intersection
- glm::vec4 newIntersectionObj = findIntersection(pObject, dObject, s);
+ bool isHit = false;
+ glm::vec4 newIntersectionObj = findIntersection(pObject, dObject, s, isHit);
if (newIntersectionObj.w == 1.f) // hit!
{
diff --git a/src/intersect/intersect.cpp b/src/intersect/intersect.cpp
index 2addca4..353508e 100644
--- a/src/intersect/intersect.cpp
+++ b/src/intersect/intersect.cpp
@@ -51,8 +51,10 @@ glm::vec4 intersectCircle(
glm::vec4 intersectCone(
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape)
+ const RenderShapeData& shape,
+ bool &isHit)
{
+ isHit = false;
float t = FINF;
// updated to 4d
// x^2 + y^2 - z^2 - w^2= 0, conic top
@@ -110,14 +112,22 @@ glm::vec4 intersectCone(
t = std::min(t, tyBase);
}
- return t == FINF ? glm::vec4(0.f) : p + t*d;
+ if (t == FINF)
+ {
+ return glm::vec4(0.f);
+ } else {
+ isHit = true;
+ return p + t*d;
+ }
}
glm::vec4 intersectCylinder(
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape)
+ const RenderShapeData& shape,
+ bool &isHit)
{
+ isHit = false;
float t = FINF;
// implicit: x^2 + z^2 = r^2, y + w between -.5, .5 rectuangular side
@@ -179,14 +189,22 @@ glm::vec4 intersectCylinder(
t = std::min(t, tBase);
}
- return t == FINF ? glm::vec4(0.f) : p + t*d;
+ if (t == FINF)
+ {
+ return glm::vec4(0.f);
+ } else {
+ isHit = true;
+ return p + t*d;
+ }
}
glm::vec4 intersectCube (
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape)
+ const RenderShapeData& shape,
+ bool &isHit)
{
+ isHit = false;
// float t = FINF;
float apothem = .5f;
@@ -274,9 +292,11 @@ glm::vec4 intersectCube (
return glm::vec4(0.f);
} else if (tmin > 0) // tmin in front of camera
{
+ isHit = true;
return p + tmin*d;
} else if (tmin <= 0) // tmax in front of camera
{
+ isHit = true;
return p + tmax*d;
}
diff --git a/src/raytracer/raytracer.h b/src/raytracer/raytracer.h
index 0943e0d..9b5bfbe 100644
--- a/src/raytracer/raytracer.h
+++ b/src/raytracer/raytracer.h
@@ -75,7 +75,8 @@ public:
glm::vec4 findIntersection(
glm::vec4 p,
glm::vec4 d,
- const RenderShapeData& shape);
+ const RenderShapeData& shape,
+ bool& isHit);
// utils
static RGBA toRGBA(const glm::vec4 &illumination);
@@ -148,7 +149,7 @@ public:
bool m_enableReflection = true;
bool m_enableRefraction = false;
bool m_enableTextureMap = false;
- bool m_enableAcceleration = true;
+ bool m_enableAcceleration = false;
bool m_enableParallelism = true;
int m_maxRecursiveDepth = 4;
bool m_enableAntiAliasing = false;