Files
SimpleRayTracing/header/Algorithm/RayIntersection.h
Misaki e1693764f7 Add mipmap support and refactor texture handling
Note: Currently version still have lots of fireflies after applying normal map. And those fireflies are mostly coming from the nee sky. Need to double check the sky cdf and ray intersection.

Changed the `hit_result_t` structure to rename a parameter in `RayIntersection.h`.
Removed the `normal` field from the `path_output` structure in `Common.h`.
Added new fields `screen_size`, `camera_position`, and `camera_direction` in `Material.h`.
Changed the `mipmap_t` structure in `Texture.h` to include a `max_mip` field and modify the `data` field.
Changed the `texture_load` function in `Texture.c` to include a `mipmap` parameter and improve texture data handling.
Changed the `path_trace` function in `PathTracing.c` to update the `shading_context_t` structure and ray creation.
Changed the `evaluate_bsdf_directional` function in `LightEvaluation.c` to modify angular radius calculation.
Changed the `sky_create_hdr_sky` and `evaluate_bsdf_hdr_sky` functions in `SkyLight.c` to enhance texture sampling.
Changed the `get_surface_data` function in `SimpleLit.c` to incorporate camera distance and view direction in calculations.
Changed the `texture_get_pixel` function in `Texture.c` to improve pixel data retrieval.
Changed the `warp_uv` function to use a `vec2s` structure for UV coordinates.
Changed the `texture_sample` function to include additional parameters for improved sampling accuracy.
Changed the `scene_setup` function in `main.c` to adjust sun light intensity and HDRI texture loading.
2025-05-06 17:46:42 +09:00

44 lines
1.5 KiB
C

#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