Untitled
Loading...
Searching...
No Matches
acceleration.h File Reference

Acceleration structure generation and how we traverse them. More...

#include "engine_types.h"

Go to the source code of this file.

Functions

bool ray_intersects_aabb (AABB aabb, vec3 origin, vec3 dir, vec3 inv_dir)
 Checks if a ray intersects an aabb.
bool ray_intersects_aabb_with_point (AABB aabb, vec3 origin, vec3 dir, vec3 inv_dir, vec3 *intersection_point)
 Checks if a ray intersects an aabb and outputs an intersection point.
bool ray_intersects_obb_with_point (OBB obb, vec3 origin, vec3 dir, vec3 *intersection_point)
 Checks if a ray intersects an obb and outputs an intersection point.
RayHit raycast_scene (vec3 start, vec3 dir, float initial_t, bool check_normal)
 Raycasts through the scene and finds closest intersection to meshes.
bool traverse_collision_bvh (Mesh *m, MeshNode *mn, BVHNode *nodes, BVHNode *node, vec3 proposed, vec3 inv_p, CollisionPoints *p)
 Traverses the mesh bvh to find collisions based on point vs aabb within a certain epsilon for player collisions.
void init_scene_bvh ()
 Initializes or updates the pre-existing scene bvh based on all mesh nodes with valid meshes.
void init_mesh_tri_bvh (Mesh *mesh)
 Initializes the bvh for a mesh's triangles.
void build_light_bvh ()
 Initializes a bvh for all current lights and emissive triangles in the scene, and sets the flux up for importance sampling.

Detailed Description

Acceleration structure generation and how we traverse them.

Definition in file acceleration.h.

Function Documentation

◆ ray_intersects_aabb()

bool ray_intersects_aabb ( AABB aabb,
vec3 origin,
vec3 dir,
vec3 inv_dir )

Checks if a ray intersects an aabb.

Parameters
aabbThe aabb to check.
originThe origin of the ray.
dirThe dir of the ray.
inv_dir1.0f/dir of the ray.
Returns
If we intersected the aabb.

Definition at line 157 of file acceleration.c.

References AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, ray_intersects_aabb(), vec3::x, vec3::y, and vec3::z.

Referenced by ray_intersects_aabb().

◆ ray_intersects_aabb_with_point()

bool ray_intersects_aabb_with_point ( AABB aabb,
vec3 origin,
vec3 dir,
vec3 inv_dir,
vec3 * intersection_point )

Checks if a ray intersects an aabb and outputs an intersection point.

Parameters
aabbThe aabb to check.
originThe origin of the ray.
dirThe dir of the ray.
inv_dir1.0f/dir of the ray.
intersection_pointA pointer to where we will place the intersection point.
Precondition
intersection_point must not be NULL.
Returns
If we intersected the aabb.

Definition at line 182 of file acceleration.c.

References AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, ray_intersects_aabb_with_point(), vec3_add(), vec3_scale(), vec3::x, vec3::y, and vec3::z.

Referenced by process_sdl_event(), ray_intersects_aabb_with_point(), and ray_traverse_scene_bvh().

◆ ray_intersects_obb_with_point()

bool ray_intersects_obb_with_point ( OBB obb,
vec3 origin,
vec3 dir,
vec3 * intersection_point )

Checks if a ray intersects an obb and outputs an intersection point.

Parameters
obbThe obb to check.
originThe origin of the ray.
dirThe dir of the ray.
intersection_pointA pointer to where we will place the intersection point.
Precondition
intersection_point must not be NULL.
Returns
If we intersected the obb.

Definition at line 220 of file acceleration.c.

References mat3::a0, mat3::a1, mat3::a2, mat3::b0, mat3::b1, mat3::b2, mat3::c0, mat3::c1, mat3::c2, OBB::center, OBB::extents, RAY_EPS, ray_intersects_obb_with_point(), OBB::rot, vec3_add(), vec3_dot(), vec3_normalize(), vec3_scale(), vec3_sub(), vec3::x, vec3::y, and vec3::z.

Referenced by check_lighting_pv(), process_sdl_event(), and ray_intersects_obb_with_point().

◆ raycast_scene()

RayHit raycast_scene ( vec3 start,
vec3 dir,
float initial_t,
bool check_normal )

Raycasts through the scene and finds closest intersection to meshes.

Parameters
startThe ray's starting position.
dirThe dir of the ray.
initial_tThe starting T to begin evaluating, usually set at INFINITY.
check_normalTo check backfaces or not.
Returns
A RayHit with hit information.

Definition at line 448 of file acceleration.c.

References SceneData::bvh_nodes, CAST_VEC, Vector::count, MeshNode::global_matrix, GLOBALS, hit, RayHit::hit, mat4_mul_point(), RayHit::mesh_node_idx, Globals::mesh_nodes, RayHit::pos, ray_traverse_scene_bvh(), raycast_scene(), Globals::scene_data, RayHit::t, vec3::x, vec3::y, and vec3::z.

Referenced by find_closest_visible_aportal(), interpolate_nearest_aprobes(), pathfind_audio_occlusion(), process_sdl_event(), raycast_scene(), recalculate_audio_portal_paths(), resolve_collisions(), update_audio_occlusion(), update_body_from_legs(), and update_leg().

◆ traverse_collision_bvh()

bool traverse_collision_bvh ( Mesh * m,
MeshNode * mn,
BVHNode * nodes,
BVHNode * node,
vec3 proposed,
vec3 inv_p,
CollisionPoints * p )

Traverses the mesh bvh to find collisions based on point vs aabb within a certain epsilon for player collisions.

Parameters
mThe mesh we are traversing.
mnThe mesh node we are traversing.
nodesThe bvh nodes we are traversing.
nodeThe current node.
proposedThe position we are checking.
inv_posThe position transformed into mesh node local space using inv matrix.
pThe array of collision points to append to.
Returns
If it collides with a mesh.

Definition at line 514 of file acceleration.c.

References BVHNode::aabb, BVHNode::left, AABB::max_x, AABB::max_y, AABB::max_z, AABB::min_x, AABB::min_y, AABB::min_z, point_in_aabb(), process_collision_node(), BVHNode::right, and traverse_collision_bvh().

Referenced by player_find_collision(), and traverse_collision_bvh().

◆ init_scene_bvh()

◆ init_mesh_tri_bvh()

◆ build_light_bvh()

void build_light_bvh ( )

Initializes a bvh for all current lights and emissive triangles in the scene, and sets the flux up for importance sampling.

Definition at line 1600 of file acceleration.c.

References Light::A, BVHNode::aabb, Light::area, AREA_LIGHT, assign_next_nodes(), Light::B, Vector::buffer, build_light_bvh(), Mesh::bvh_indices, SceneData::bvh_indices, SceneData::bvh_indices_count, Light::C, calculate_aabb_bounds(), calculate_aabb_extents(), CAST_VEC, AABB::center, BVHNode::count, Vector::count, DIRECTIONAL_LIGHT, BVHNode::emissive_flux, Material::emissive_strength, AABB::extents, BVHNode::first_index, BVHNode::flux, MeshNode::free, MeshNode::global_matrix, GLOBALS, BVHNode::index, LightBVH::indices, MeshFace::indices, LightBVH::indices_count, init_vector(), Light::intensity, Material::ke, BVHNode::left, SceneData::light_bvh, Light::light_type, Globals::lights, LightBVH::lights, Light::lum, M_PI, mat3_from_mat4(), mat3_inverse_transpose(), mat3_mul_vec3(), mat4_mul_point(), MeshFace::material_id, Globals::materials, AABB::max_x, AABB::max_y, AABB::max_z, Light::mesh, MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, AABB::min_x, AABB::min_y, AABB::min_z, BVHNode::next, LightBVH::nodes, Light::normal, MeshFace::normal, Light::outer_angle, BVHNode::parent, POINT_LIGHT, Light::pos, Point::pos, Light::power, Light::radius, Light::rgb, BVHNode::right, rot(), Globals::scene_data, SPOT_LIGHT, MeshNode::static_mesh, subdivide_light_bvh(), Light::surface_area, Light::threshold, Light::tri, triangle_area(), triangle_centroid(), Mesh::tris, vec3_normalize(), vec3_scale(), vec4_length(), vec4_to_vec3(), vector_expand(), Mesh::vertices, vec3::x, vec3::y, and vec3::z.

Referenced by build_light_bvh(), and render_light_menu().