Skip to content

Commit

Permalink
[bvh]: every Object now has an bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
cszach committed Feb 5, 2024
1 parent 4d5f097 commit 9417544
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/3d/Camera.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions include/3d/Object.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class Material;

#include "AABB.cuh"
#include "Ray.cuh"
#include "Vec3.cuh"

Expand All @@ -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
2 changes: 2 additions & 0 deletions include/3d/Scene.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions include/3d/Sphere.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/3d/Camera.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
2 changes: 2 additions & 0 deletions src/3d/Scene.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
9 changes: 7 additions & 2 deletions src/3d/Sphere.cu
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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);
}

0 comments on commit 9417544

Please sign in to comment.