Skip to content

Geometry System

Geometry primitives and acceleration structures.

Sphere

cpp
struct Sphere {
    vec3 center;       // Center position
    float radius;      // Sphere radius
    int material_id;   // Material index

    __device__ bool hit(const ray& r, float t_min, float t_max, HitRecord& rec) const;
};

Intersection Test:

Solve quadratic equation: $|origin + t \cdot direction - center|^2 = radius^2$

AABB

Axis-Aligned Bounding Box for BVH.

cpp
struct AABB {
    vec3 min, max;     // Corner points

    __device__ bool hit(const ray& r, float t_min, float t_max) const;
    __device__ float surface_area() const;

    // Create surrounding box
    __host__ __device__ static AABB surrounding_box(const AABB& a, const AABB& b);
};

Slab Method:

For each axis, compute intersection intervals and find overlap.

HitRecord

Intersection result structure.

cpp
struct HitRecord {
    vec3 p;             // Hit point
    vec3 normal;        // Surface normal
    float t;            // Ray parameter
    int material_id;    // Material index
    int object_id;      // Object ID (for ray sorting)
    bool front_face;    // Hit from outside?

    __device__ void set_face_normal(const ray& r, const vec3& outward_normal);
};

BVHNode

BVH tree node.

cpp
struct BVHNode {
    AABB bounds;        // Node bounding box
    int left;           // Left child (-1 if leaf)
    int right;          // Right child
    int start;          // Leaf: primitive start index
    int count;          // Leaf: primitive count
};

Plane

Infinite plane primitive.

cpp
struct Plane {
    vec3 point;         // Point on plane
    vec3 normal;        // Plane normal
    int material_id;

    __device__ bool hit(const ray& r, float t_min, float t_max, HitRecord& rec) const;
};

Note

Planes are NOT included in BVH - they are tested separately via brute force.

Technical Whitepaper · Built with VitePress