Files
SimpleRayTracing/source/Rendering/Scene.c
Misaki 3de6b83d32 Set C standard to C11 and add new assets
Changed CMakeLists.txt to set the C standard to C11.
Added multiple binary image files for new visual assets.
Added several new image files to enhance rendering capabilities.
Changed stb_image.h to improve support for various image formats.
Changed ray tracing engine to enhance ray creation and intersection.
Changed triangle structure to use a vertex array for better attribute handling.
Changed scene initialization to accommodate new texture management.
2025-04-29 01:43:52 +09:00

79 lines
1.7 KiB
C

#include "Rendering/Scene.h"
bool scene_init(scene_t* scene, uint64_t triangle_count, uint16_t texture_count, uint8_t material_count, uint32_t punctual_light_count)
{
scene_t temp = {0};
if (!triangle_collection_init(triangle_count, &temp.triangles))
{
goto triangle_failed;
}
if (!texture_collection_init(texture_count, &temp.textures))
{
goto texture_failed;
}
if (!material_collection_init(material_count, &temp.materials))
{
goto material_failed;
}
if (!light_collection_create(punctual_light_count, 16, &temp.lights)) // NOTE: We just fixed the max directional light count to 16.
{
goto light_failed;
}
temp.camera = camera_create(
(vec3s){0.0f, 0.0f, 5.0f},
glms_quat_identity(),
0.025f,
0.036f,
16.0f / 9.0f
);
*scene = temp;
return true;
light_failed:
material_collection_free(&temp.materials);
material_failed:
texture_collection_free(&temp.textures);
texture_failed:
triangle_collection_free(&temp.triangles);
triangle_failed:
return false;
}
bool scene_build_bvh(scene_t* scene)
{
if (scene == NULL || scene->triangles.count == 0)
{
return false;
}
bvh_tree_t bvh_tree = {0};
if (!bvh_tree_init(&bvh_tree, &scene->triangles))
{
return false;
}
bvh_tree_build(&bvh_tree);
scene->bvh_tree = bvh_tree;
return true;
}
void scene_free(scene_t* scene)
{
if (scene == NULL)
{
return;
}
bvh_tree_free(&scene->bvh_tree);
triangle_collection_free(&scene->triangles);
texture_collection_free(&scene->textures);
material_collection_free(&scene->materials);
light_collection_free(&scene->lights);
}