aboutsummaryrefslogtreecommitdiff
path: root/src/raytracer/raytracer.cpp
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2023-12-12 22:23:02 -0500
committersotech117 <michael_foiani@brown.edu>2023-12-12 22:23:07 -0500
commit018c2504879f3a585a3f6f0921c9aba22f6a9b76 (patch)
treed7da93e050bfd752524a002f271a9a2b0c742df5 /src/raytracer/raytracer.cpp
parentd3e5518638cbdc4ea5c7dcfcdc6b6d71157d7edf (diff)
skeleton for new isIntersect obj
Diffstat (limited to 'src/raytracer/raytracer.cpp')
-rw-r--r--src/raytracer/raytracer.cpp64
1 files changed, 26 insertions, 38 deletions
diff --git a/src/raytracer/raytracer.cpp b/src/raytracer/raytracer.cpp
index fa949eb..0746225 100644
--- a/src/raytracer/raytracer.cpp
+++ b/src/raytracer/raytracer.cpp
@@ -83,51 +83,39 @@ glm::vec4 RayTracer::getPixelFromRay(
glm::vec4 closestIntersectionWorld;
RenderShapeData intersectedShape;
- if (m_enableAcceleration)
- {
- float tWorld = traverseBVH(pWorld, dWorld, intersectedShape, scene.m_bvh);
- if (tWorld == FINF)
+ 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;
+ bool isHit = false;
+ glm::vec4 newIntersectionObj = findIntersection(pObject, dObject, shape, isHit);
+ if (!isHit) // no hit
{
- return glm::vec4(0.f);
- }
- closestIntersectionWorld = pWorld + tWorld * dWorld;
- closestIntersectionObj = intersectedShape.inverseCTM * closestIntersectionWorld;
- }
- else
- {
- float minDist = FINF;
- // shoot a ray at each shape
- for (const RenderShapeData &shape : scene.getShapes()) {
- glm::vec4 pObject = shape.inverseCTM * pWorld;
- glm::vec4 dObject = glm::normalize(shape.inverseCTM * dWorld);
- std::cout << "pObject: " << pObject.w << std::endl;
- glm::vec4 newIntersectionObj = findIntersection(pObject, dObject, shape);
- if (newIntersectionObj.w == 0) // no hit
- {
- continue;
- }
-
- auto newIntersectionWorld = shape.ctm * newIntersectionObj;
- float newDist = glm::distance(newIntersectionWorld, pWorld);
- if (
- newDist < minDist // closer intersection
- && !floatEquals(newDist, 0) // and not a self intersection
- )
- {
- minDist = newDist;
-
- intersectedShape = shape;
- closestIntersectionObj = newIntersectionObj;
- closestIntersectionWorld = newIntersectionWorld;
- }
+ continue;
}
- if (minDist == FINF) // no hit
+ auto newIntersectionWorld = shape.ctm * newIntersectionObj;
+ float newDist = glm::distance(newIntersectionWorld, pWorld);
+ if (
+ newDist < minDist // closer intersection
+ && !floatEquals(newDist, 0) // and not a self intersection
+ )
{
- return glm::vec4(0.f);
+ minDist = newDist;
+
+ intersectedShape = shape;
+ closestIntersectionObj = newIntersectionObj;
+ closestIntersectionWorld = newIntersectionWorld;
}
}
+ if (minDist == FINF) // no hit
+ {
+ return glm::vec4(0.f);
+ }
+
glm::vec4 normalObject = glm::normalize(getNormal(closestIntersectionObj, intersectedShape, scene));
// update
glm::vec4 normalWorld = glm::inverse(glm::transpose(intersectedShape.ctm)) * glm::vec4(normalObject);