From 941754472beac79205f0f2fe5058de672e467c37 Mon Sep 17 00:00:00 2001 From: Zach Date: Mon, 5 Feb 2024 14:25:19 -0500 Subject: [PATCH] [bvh]: every Object now has an bounding box --- include/3d/Camera.cuh | 2 ++ include/3d/Object.cuh | 4 ++++ include/3d/Scene.cuh | 2 ++ include/3d/Sphere.cuh | 2 ++ src/3d/Camera.cu | 2 ++ src/3d/Scene.cu | 2 ++ src/3d/Sphere.cu | 9 +++++++-- 7 files changed, 21 insertions(+), 2 deletions(-) diff --git a/include/3d/Camera.cuh b/include/3d/Camera.cuh index fb3c6f9..e8d8f80 100644 --- a/include/3d/Camera.cuh +++ b/include/3d/Camera.cuh @@ -20,6 +20,8 @@ public: __device__ bool hit(const Ray &ray, float tMin, float tMax, HitRecord &rec) const override; + + __device__ virtual void computeBoundingBox() override; }; #endif // CAMERA_H diff --git a/include/3d/Object.cuh b/include/3d/Object.cuh index e172a21..54f10b0 100644 --- a/include/3d/Object.cuh +++ b/include/3d/Object.cuh @@ -3,6 +3,7 @@ class Material; +#include "AABB.cuh" #include "Ray.cuh" #include "Vec3.cuh" @@ -24,12 +25,15 @@ class Object { public: Point3 position; Material *material; + AABB boundingBox; __device__ Object(); virtual ~Object() = default; __device__ virtual bool hit(const Ray &ray, float t_min, float t_max, HitRecord &rec) const = 0; + + __device__ virtual void computeBoundingBox() = 0; }; #endif // OBJECT_H diff --git a/include/3d/Scene.cuh b/include/3d/Scene.cuh index 8de2025..f7727c1 100644 --- a/include/3d/Scene.cuh +++ b/include/3d/Scene.cuh @@ -17,6 +17,8 @@ public: __device__ bool hit(const Ray &ray, float t_min, float t_max, HitRecord &rec) const override; + + __device__ virtual void computeBoundingBox() override; }; #endif // SCENE_H diff --git a/include/3d/Sphere.cuh b/include/3d/Sphere.cuh index 05a6123..bdc818c 100644 --- a/include/3d/Sphere.cuh +++ b/include/3d/Sphere.cuh @@ -13,6 +13,8 @@ public: __device__ bool hit(const Ray &ray, float t_min, float t_max, HitRecord &rec) const override; + + __device__ virtual void computeBoundingBox() override; }; #endif // SPHERE_H diff --git a/src/3d/Camera.cu b/src/3d/Camera.cu index add684d..d198e52 100644 --- a/src/3d/Camera.cu +++ b/src/3d/Camera.cu @@ -9,3 +9,5 @@ __device__ bool Camera::hit(const Ray &ray, float tMin, float tMax, HitRecord &rec) const { return false; } + +__device__ void Camera::computeBoundingBox() { return; } \ No newline at end of file diff --git a/src/3d/Scene.cu b/src/3d/Scene.cu index 614d059..d6d3f50 100644 --- a/src/3d/Scene.cu +++ b/src/3d/Scene.cu @@ -26,3 +26,5 @@ __device__ bool Scene::hit(const Ray &ray, float t_min, float t_max, return hit_anything; } + +__device__ void Scene::computeBoundingBox() { return; } diff --git a/src/3d/Sphere.cu b/src/3d/Sphere.cu index 59c3894..9a796f0 100644 --- a/src/3d/Sphere.cu +++ b/src/3d/Sphere.cu @@ -1,6 +1,6 @@ -#include "Sphere.cuh" - +#include "Object.cuh" #include "Ray.cuh" +#include "Sphere.cuh" #include "Vec3.cuh" __device__ Sphere::Sphere(float _radius, Material *_material) @@ -37,3 +37,8 @@ __device__ bool Sphere::hit(const Ray &ray, float t_min, float t_max, return true; } + +__device__ void Sphere::computeBoundingBox() { + Vec3 halfExtents = Vec3(radius, radius, radius); + boundingBox = AABB(position - halfExtents, position + halfExtents); +}