Added: - Updated `.gitignore` to ignore the `[Bb]uild/` directory. - Additional tasks added to the roadmap in `README.md` for light unit standardization and GPU backend support. Changed: - Removed line in `settings.json` that disabled error squiggles for C/C++ code. - Modified `Triangle.h` to include `material_id` in `triangle_t` and reorganized properties. - Reordered parameters in `triangle_collection_init` for clarity. - Updated `shading_context_t` in `Material.h` and added size parameter to `material_create`. - Streamlined initialization in `scene_init` and updated `scene_free` for proper resource management. - Updated `window_create` in `Window.h` to accept a `render_job_t` parameter. - Introduced `renderer_start` in `Renderer.c` to handle rendering jobs and optimized pixel rendering logic.
66 lines
1.6 KiB
C
66 lines
1.6 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)
|
|
{
|
|
vec4s result = glms_vec4_zero();
|
|
|
|
if (scene == NULL)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
switch (flag & 0xFF)
|
|
{
|
|
case DEBUG_BVH:
|
|
uint32_t count = 0;
|
|
ray_intersect_bvh_count(ray, scene->bvh_tree, 0, &count);
|
|
|
|
for (uint32_t i = 0; i < count; i++)
|
|
{
|
|
result = glms_vec4_add(result, DEBUG_COLOR_BVH);
|
|
}
|
|
|
|
break;
|
|
case DEBUG_SOBOL:
|
|
uint16_t i = sample_index ^ (sample_index >> 1);
|
|
float sobol_sample_value = sobol_sample(i, 1); // Assuming dimension 0 for simplicity
|
|
result = glms_vec4_add(result, (vec4s){sobol_sample_value, sobol_sample_value, sobol_sample_value, 1.0f});
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return result;
|
|
}
|