|
Untitled
|
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. | |
Acceleration structure generation and how we traverse them.
Definition in file acceleration.h.
Checks if a ray intersects an aabb.
| aabb | The aabb to check. |
| origin | The origin of the ray. |
| dir | The dir of the ray. |
| inv_dir | 1.0f/dir of the ray. |
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().
| 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.
| aabb | The aabb to check. |
| origin | The origin of the ray. |
| dir | The dir of the ray. |
| inv_dir | 1.0f/dir of the ray. |
| intersection_point | A pointer to where we will place the intersection point. |
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().
Checks if a ray intersects an obb and outputs an intersection point.
| obb | The obb to check. |
| origin | The origin of the ray. |
| dir | The dir of the ray. |
| intersection_point | A pointer to where we will place the intersection point. |
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().
Raycasts through the scene and finds closest intersection to meshes.
| start | The ray's starting position. |
| dir | The dir of the ray. |
| initial_t | The starting T to begin evaluating, usually set at INFINITY. |
| check_normal | To check backfaces or not. |
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().
| 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.
| m | The mesh we are traversing. |
| mn | The mesh node we are traversing. |
| nodes | The bvh nodes we are traversing. |
| node | The current node. |
| proposed | The position we are checking. |
| inv_pos | The position transformed into mesh node local space using inv matrix. |
| p | The array of collision points to append to. |
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().
| void init_scene_bvh | ( | ) |
Initializes or updates the pre-existing scene bvh based on all mesh nodes with valid meshes.
Definition at line 850 of file acceleration.c.
References BVHNode::aabb, Mesh::aabb, SceneData::aabb, assign_next_nodes(), Vector::buffer, SceneData::bvh_indices, SceneData::bvh_indices_count, SceneData::bvh_nodes, CAST_VEC, AABB::center, BVHNode::count, Vector::count, AABB::extents, BVHNode::first_index, MeshNode::free, MeshNode::global_matrix, GLOBALS, BVHNode::index, init_scene_bvh(), init_vector(), BVHNode::left, AABB::max_x, AABB::max_y, AABB::max_z, MeshNode::mesh, Globals::mesh_nodes, Globals::meshes, AABB::min_x, AABB::min_y, AABB::min_z, BVHNode::next, BVHNode::parent, BVHNode::right, Globals::scene_data, subdivide_scene_bvh(), transform_aabb_by_model_matrix(), and vector_expand().
Referenced by init_scene_bvh(), main(), and render_main_menu().
| void init_mesh_tri_bvh | ( | Mesh * | mesh | ) |
Initializes the bvh for a mesh's triangles.
Only performed on static meshes.
Definition at line 1231 of file acceleration.c.
References BVHNode::aabb, Mesh::aabb, assign_next_nodes(), Mesh::bvh_indices, CAST_VEC, compute_aabb_from_points(), BVHNode::count, Vector::count, BVHNode::first_index, BVHNode::index, MeshFace::indices, init_mesh_tri_bvh(), init_vector(), BVHNode::left, BVHNode::next, Mesh::nodes, BVHNode::parent, Point::pos, BVHNode::right, subdivide_mesh_tri_bvh(), Mesh::tri_aabbs, Mesh::tris, vector_expand(), and Mesh::vertices.
Referenced by init_mesh(), and init_mesh_tri_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().