#ifndef RAY_INTERSECTION_H #define RAY_INTERSECTION_H #include "Common.h" #include "Geometry/Triangle.h" #include "Rendering/Scene.h" #define SIGN_BIT(sign, axis) (((sign) >> (axis)) & 1) typedef struct { vec3s origin; vec3s direction; vec3s inverse_direction; float esp; uint8_t sign; } ray_t; typedef struct { vec3s point; vec3s normal; // Should we remove normal, tangent, and uv from here and output u, v, w instead? vec3s tangent; vec2s uv; uint64_t triangle_id; float distance; bool hit; } hit_result_t; ray_t ray_create(vec3s origin, vec3s direction); vec3s offset_ray_origin(vec3s point, vec3s normal, vec3s w); hit_result_t ray_intersect_triangle(const ray_t* ray, const triangle_t* triangle); bool ray_intersect_aabb(const ray_t* ray, aabb_t aabb, float* enter_out, float* exit_out); void ray_intersect_bvh_closest(const ray_t* ray, const bvh_node_t* bvh_nodes, const uint64_t* primitive_indices, const triangle_collection_t* all_triangles, uint64_t node_index, float* closest_out, hit_result_t* best_hit_out); void ray_intersect_bvh_any(const ray_t* ray, const bvh_node_t* bvh_nodes, const uint64_t* primitive_indices, const triangle_collection_t* all_triangles, uint64_t node_index, hit_result_t* any_hit_out); hit_result_t ray_intersect_scene_closest(const ray_t* ray, const scene_t* scene); hit_result_t ray_intersect_scene_any(const ray_t* ray, const scene_t* scene); #endif // RAY_INTERSECTION_H