几何系统
几何图元和加速结构。
Sphere
球体图元。
cpp
struct Sphere {
vec3 center;
float radius;
int material_id;
__device__ bool hit(const ray& r, float t_min, float t_max, HitRecord& rec) const;
};AABB
轴对齐包围盒。
cpp
struct AABB {
vec3 min, max;
__device__ bool hit(const ray& r, float t_min, float t_max) const;
__device__ float surface_area() const;
__device__ static AABB surrounding_box(const AABB& a, const AABB& b);
};HitRecord
相交记录结构。
cpp
struct HitRecord {
vec3 p; // 相交点
vec3 normal; // 法线
float t; // 参数 t
int material_id; // 材质 ID
__device__ void set_face_normal(const ray& r, const vec3& outward_normal);
};BVHNode
BVH 节点结构。
cpp
struct BVHNode {
AABB bounds;
int left; // 左子节点索引
int right; // 右子节点索引
int start; // 图元起始索引(叶子节点)
int count; // 图元数量(叶子节点)
};