Files
SimpleRayTracing/source/Rendering/Debug.c
Misaki f940569ca3 Update AOV support, ray intersection logic, and README
Added:
- AOV support for normals, albedo, and depth marked as completed.
- New function `normal_unpack` in `BSDF.h`.
- New field `esp` in `ray_t` structure in `RayIntersection.h`.

Changed:
- Updated `normal_ts_to_ws` to accept an additional parameter.
- Refactored `weight_nee_light` for clarity.
- Modified `RAY_EPSILON` for improved precision.
- Updated `path_output` structure to include a `normal` field.
- Normalized unpacked normal vector in `normal_unpack` function.
- Updated `path_trace` to use closest hit ray intersection.
- Updated `render_aov` to utilize closest hit logic.
- Modified `ray_create` to initialize `esp` based on ray origin.
- Improved accuracy in `offset_ray_origin` calculations.
- Updated ray intersection logic in `ray_intersect_triangle` and `ray_intersect_aabb` to include epsilon checks.
- Updated `evaluate_bsdf_directional` and `evaluate_bsdf_const_sky` for shadow rays.
- Adjusted `sample_bsdf_simple_lit` for incoming light direction calculations.
- Enhanced `render_pixel` to manage AOV flags effectively.
- Changed camera rotation and light intensity in `scene_setup`.
- Simplified texture loading by removing unnecessary sRGB conversion.

Modified:
- Several binary image files have been updated.
2025-05-05 02:00:21 +09:00

66 lines
1.8 KiB
C

#include "Rendering/Debug.h"
#include "Algorithm/RayIntersection.h"
static void ray_intersect_bvh_count(ray_t ray, bvh_tree_t bvh_tree, uint64_t node_index, uint32_t* count_out)
{
const float _MAX_DIST = 1e6f;
if (bvh_tree.nodes == NULL || bvh_tree.primitive_indices == NULL || count_out == NULL)
{
return;
}
const bvh_node_t* node = &bvh_tree.nodes[node_index];
float enter, exit;
if (!ray_intersect_aabb(&ray, node->bounds, &enter, &exit))
{
return;
}
if (enter > _MAX_DIST || exit < 0.0f)
{
return;
}
(*count_out)++;
if (node->primitive_count == 0)
{
// Internal node
ray_intersect_bvh_count(ray, bvh_tree, node->left_child_offset, count_out);
ray_intersect_bvh_count(ray, bvh_tree, node->right_child_offset, count_out);
}
}
vec4s render_debug(scene_t* scene, ray_t ray, uint16_t sample_index, int flag)
{
if (scene == NULL)
{
return glms_vec4_zero();
}
switch (flag & 0xFF)
{
case DEBUG_BVH:
uint32_t count = 0;
ray_intersect_bvh_count(ray, scene->bvh_tree, 0, &count);
vec4s result = glms_vec4_zero();
for (uint32_t i = 0; i < count; i++)
{
result = glms_vec4_add(result, DEBUG_COLOR_BVH);
}
return result;
case DEBUG_SOBOL:
float sobol_sample_value = sobol_sample(sample_index, 1); // Assuming dimension 0 for simplicity
return (vec4s){sobol_sample_value, sobol_sample_value, sobol_sample_value, 1.0f};
case DEBUG_UV:
hit_result_t hit_result = ray_intersect_scene_closest(&ray, scene);
return (vec4s){fmodf(fabsf(hit_result.uv.x), 1.0f), fmodf(fabsf(hit_result.uv.y), 1.0f), 0.0f, 1.0f};
default:
return glms_vec4_zero();
}
}