diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-10-05 12:52:04 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-10-05 12:52:04 +1000 |
commit | fa934b45f4d17495952303c2981dc1e21cb978f1 (patch) | |
tree | bdc2671e6c95ae757b549a832f60894a753e460a | |
parent | dfb6adbcbcc7d50b770b6d5ea82efdd8f8c32e25 (diff) |
Remove more examples
-rw-r--r-- | examples/README.md | 11 | ||||
-rw-r--r-- | examples/cube.c | 0 | ||||
-rw-r--r-- | examples/example_scene.h | 31 | ||||
-rw-r--r-- | examples/obj_loading/backpack_screenshot.png | bin | 2404274 -> 0 bytes | |||
-rw-r--r-- | examples/obj_loading/ex_obj_loading.c | 74 | ||||
-rw-r--r-- | examples/pbr_params/ex_pbr_params.c | 163 | ||||
-rw-r--r-- | examples/pbr_textured/ex_pbr_textured.c | 142 | ||||
-rw-r--r-- | examples/primitives/ex_primitives.c | 68 | ||||
-rw-r--r-- | examples/shadow_maps/ex_shadow_maps.c | 259 | ||||
-rw-r--r-- | examples/skinned_animation/ex_skinned_animation.c | 100 | ||||
-rw-r--r-- | examples/transforms/ex_transforms.c | 88 | ||||
-rw-r--r-- | examples/triangle/ex_triangle.c | 115 | ||||
-rw-r--r-- | include/celeritas.h | 12 | ||||
-rw-r--r-- | new_src/platform_osx.c | 0 | ||||
-rw-r--r-- | new_src/platform_unix.c | 0 | ||||
-rw-r--r-- | new_src/platform_win32.c | 0 |
16 files changed, 11 insertions, 1052 deletions
diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index f289e80..0000000 --- a/examples/README.md +++ /dev/null @@ -1,11 +0,0 @@ - -### RAL examples - -These examples show off how the lowest register of rendering, the Rendering Abstraction Layer (RAL), is used to draw things to the screen. - -- triangle -- cube - -### Renderer - -The 'renderer' is the default renderer provided by Celeritas. diff --git a/examples/cube.c b/examples/cube.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/examples/cube.c diff --git a/examples/example_scene.h b/examples/example_scene.h deleted file mode 100644 index eb0be18..0000000 --- a/examples/example_scene.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "render_types.h" - -const vec3 pointlight_positions[4] = { - { 0.7, 0.2, 2.0 }, - { 2.3, -3.3, -4.0 }, - { -4.0, 2.0, -12.0 }, - { 0.0, 0.0, -3.0 }, -}; -static point_light point_lights[4]; - -static scene make_default_scene() { - directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 }, - .ambient = (vec3){ 0.2, 0.2, 0.2 }, - .diffuse = (vec3){ 0.5, 0.5, 0.5 }, - .specular = (vec3){ 1.0, 1.0, 1.0 } }; - - for (int i = 0; i < 4; i++) { - point_lights[i].position = pointlight_positions[i]; - point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 }; - point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 }; - point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 }; - point_lights[i].constant = 1.0; - point_lights[i].linear = 0.09; - point_lights[i].quadratic = 0.032; - } - - scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 }; - memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4])); - return our_scene; -}
\ No newline at end of file diff --git a/examples/obj_loading/backpack_screenshot.png b/examples/obj_loading/backpack_screenshot.png Binary files differdeleted file mode 100644 index a16b1f2..0000000 --- a/examples/obj_loading/backpack_screenshot.png +++ /dev/null diff --git a/examples/obj_loading/ex_obj_loading.c b/examples/obj_loading/ex_obj_loading.c deleted file mode 100644 index 906816b..0000000 --- a/examples/obj_loading/ex_obj_loading.c +++ /dev/null @@ -1,74 +0,0 @@ -#include <assert.h> -#include <glfw3.h> -#include <string.h> - -#include "camera.h" -#include "core.h" -#include "maths.h" -#include "maths_types.h" -#include "render.h" -#include "render_types.h" - -const vec3 pointlight_positions[4] = { - { 0.7, 0.2, 2.0 }, - { 2.3, -3.3, -4.0 }, - { -4.0, 2.0, -12.0 }, - { 0.0, 0.0, -3.0 }, -}; -point_light point_lights[4]; - -int main() { - core* core = core_bringup(); - - // --- Set up our scene - - // 1. load model from disk - model_handle backpack_handle = - model_load_obj(core, "assets/models/obj/backpack/backpack.obj", true); - model* backpack = &core->models->data[backpack_handle.raw]; - assert(backpack->meshes->data->is_skinned == false); - // 2. upload vertex data to gpu - model_upload_meshes(&core->renderer, backpack); - // 3. create a camera - vec3 camera_pos = vec3(3., 2., 10.); - vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); - camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0)); - // 4. create lights - - // directional (sun) light setup - directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 }, - .ambient = (vec3){ 0.2, 0.2, 0.2 }, - .diffuse = (vec3){ 0.5, 0.5, 0.5 }, - .specular = (vec3){ 1.0, 1.0, 1.0 } }; - // point lights setup - for (int i = 0; i < 4; i++) { - point_lights[i].position = pointlight_positions[i]; - point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 }; - point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 }; - point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 }; - point_lights[i].constant = 1.0; - point_lights[i].linear = 0.09; - point_lights[i].quadratic = 0.032; - } - - scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 }; - memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4])); - - // --- Enter Main loop - while (!should_exit(core)) { - input_update(&core->input); - threadpool_process_results(&core->threadpool, 1); - - render_frame_begin(&core->renderer); - - // Draw the backpack - transform model_tf = transform_create(vec3(0.0, -0.4, 0.0), quat_ident(), - 1.8); // make the backpack a bit bigger - mat4 model_matrix = transform_to_mat(&model_tf); - draw_model(&core->renderer, &cam, backpack, &model_matrix, &our_scene); - - render_frame_end(&core->renderer); - } - - return 0; -} diff --git a/examples/pbr_params/ex_pbr_params.c b/examples/pbr_params/ex_pbr_params.c deleted file mode 100644 index f5c004b..0000000 --- a/examples/pbr_params/ex_pbr_params.c +++ /dev/null @@ -1,163 +0,0 @@ -#include <glfw3.h> -#include <stdbool.h> - -#include "builtin_materials.h" -#include "camera.h" -#include "colours.h" -#include "core.h" -#include "log.h" -#include "maths.h" -#include "maths_types.h" -#include "primitives.h" -#include "ral.h" -#include "render.h" -#include "render_types.h" -#include "str.h" - -extern core g_core; - -const vec3 pointlight_positions[4] = { - { 10.0 / 1., 10.0 / 1., 10.0 }, - { -10.0 / 1., 10.0 / 1., 10.0 }, - { 10.0 / 1., -10.0 / 1., 10.0 }, - { -10.0 / 1., -10.0 / 1., 10.0 }, -}; -pbr_point_light point_lights[4]; - -void encode_draw_mesh(mesh* m); - -const int num_rows = 7, num_cols = 7; -const float spacing = 2.5; - -pbr_params_material_uniforms pbr_params; - -int main() { - core_bringup(); - - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - for (int i = 0; i < 4; i++) { - point_lights[i].pos = pointlight_positions[i]; - point_lights[i].color = vec3(300.0, 300.0, 300.0); - } - - vec3 camera_pos = vec3(-1., -1., 26.); - camera cam = camera_create(camera_pos, VEC3_NEG_Z, VEC3_Y, deg_to_rad(45.0)); - - // PBR Material data - pbr_params.albedo = (vec3){ 0.5, 0.0, 0.0 }; - pbr_params.ao = 1.0; - shader_data pbr_uniforms = { .data = NULL, .shader_data_get_layout = &pbr_params_shader_layout }; - - // Make the pipeline - gpu_renderpass_desc pass_description = { .default_framebuffer = true, .color_target = true }; - gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); - // FIXME: Make this work on other API backends - str8 vert_path = str8lit("assets/shaders/pbr_params.vert"); - str8 frag_path = str8lit("assets/shaders/pbr_params.frag"); - str8_opt vertex_shader = str8_from_file(&scratch, vert_path); - str8_opt fragment_shader = str8_from_file(&scratch, frag_path); - if (!vertex_shader.has_value || !fragment_shader.has_value) { - ERROR_EXIT("Failed to load shaders from disk") - } - - struct graphics_pipeline_desc pipeline_description = { - .debug_name = "Basic Pipeline", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = { pbr_uniforms }, - .data_layouts_count = 1, - .vs = { .debug_name = "PBR (params) Vertex Shader", - .filepath = vert_path, - .code = vertex_shader.contents, - .is_spirv = false }, - .fs = { .debug_name = "PBR (params) Fragment Shader", - .filepath = frag_path, - .code = fragment_shader.contents, - .is_spirv = false }, - .renderpass = renderpass, - .wireframe = false, - .depth_test = false - }; - gpu_pipeline* pbr_pipeline = gpu_graphics_pipeline_create(pipeline_description); - - // Geometry - geometry_data sphere_data = geo_create_uvsphere(1.0, 64, 64); - mesh sphere = mesh_create(&sphere_data, false); - - geometry_data cube_data = geo_create_cuboid(f32x3(1, 1, 1)); - mesh cube = mesh_create(&cube_data, false); - - pbr_params_bindgroup pbr_bind_data; - - while (!should_exit()) { - input_update(&g_core.input); - - if (!gpu_backend_begin_frame()) { - continue; - } - gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - // Begin recording - gpu_cmd_encoder_begin(*enc); - gpu_cmd_encoder_begin_render(enc, renderpass); - encode_bind_pipeline(enc, PIPELINE_GRAPHICS, pbr_pipeline); - encode_set_default_settings(enc); - - mat4 model_affine = mat4_ident(); - mat4 view, proj; - camera_view_projection(&cam, 1000, 1000, &view, &proj); - - // Feed shader data - pbr_bind_data.mvp_matrices = - (mvp_matrix_uniforms){ .model = model_affine, .view = view, .projection = proj }; - pbr_bind_data.material = pbr_params; - pbr_bind_data.lights = (pbr_params_light_uniforms){ - .viewPos = vec4(cam.position.x, cam.position.y, cam.position.z, 1.0), - .pointLights = { point_lights[0], point_lights[1], point_lights[2], point_lights[3] } - }; - pbr_uniforms.data = &pbr_bind_data; - - // Record draw calls - for (u32 row = 0; row < num_rows; row++) { - f32 metallic = (float)row / (float)num_rows; - for (u32 col = 0; col < num_cols; col++) { - f32 roughness = (float)col / (float)num_cols; - if (roughness == 0.0) { - roughness += 0.05; - }; - if (roughness == 1.0) { - roughness -= 0.05; - }; - - pbr_bind_data.material.metallic = metallic; - pbr_bind_data.material.roughness = roughness; - - f32 x = (col - ((f32)num_cols / 2.)) * spacing; - f32 y = (row - ((f32)num_rows / 2.)) * spacing; - mat4 model = mat4_translation(vec3(x, y, 0.0f)); - pbr_bind_data.mvp_matrices.model = model; - encode_bind_shader_data(enc, 0, &pbr_uniforms); - mesh object = sphere; - encode_draw_mesh(&object); - } - } - - // End recording - gpu_cmd_encoder_end_render(enc); - - gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc); - gpu_queue_submit(&buf); - // Submit - gpu_backend_end_frame(); - } - - renderer_shutdown(&g_core.renderer); - - return 0; -} - -void encode_draw_mesh(mesh* m) { - gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - encode_set_vertex_buffer(enc, m->vertex_buffer); - encode_set_index_buffer(enc, m->index_buffer); - encode_draw_indexed(enc, m->geometry->indices->len); -}
\ No newline at end of file diff --git a/examples/pbr_textured/ex_pbr_textured.c b/examples/pbr_textured/ex_pbr_textured.c deleted file mode 100644 index 3a03d00..0000000 --- a/examples/pbr_textured/ex_pbr_textured.c +++ /dev/null @@ -1,142 +0,0 @@ -#include <glfw3.h> -#include <stdbool.h> - -#include "builtin_materials.h" -#include "camera.h" -#include "colours.h" -#include "core.h" -#include "loaders.h" -#include "log.h" -#include "maths.h" -#include "maths_types.h" -#include "primitives.h" -#include "ral.h" -#include "render.h" -#include "render_types.h" -#include "str.h" - -extern core g_core; - -#define MODEL_GET(h) (model_pool_get(&g_core.models, h)) - -const vec3 pointlight_positions[4] = { - { 10.0 / 1., 10.0 / 1., 10.0 }, - { -10.0 / 1., 10.0 / 1., 10.0 }, - { 10.0 / 1., -10.0 / 1., 10.0 }, - { -10.0 / 1., -10.0 / 1., 10.0 }, -}; -pbr_point_light point_lights[4]; - -int main() { - core_bringup(); - - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - for (int i = 0; i < 4; i++) { - point_lights[i].pos = pointlight_positions[i]; - point_lights[i].color = vec3(300.0, 300.0, 300.0); - } - - vec3 camera_pos = vec3(3., 2., 0.); - vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); - camera cam = camera_create(camera_pos, camera_front, VEC3_NEG_Z, deg_to_rad(45.0)); - - shader_data pbr_uniforms = { .data = NULL, - .shader_data_get_layout = &pbr_textured_shader_layout }; - - // Make the pipeline - gpu_renderpass_desc pass_description = { .default_framebuffer = true, .color_target = true }; - gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); - str8 vert_path = str8lit("assets/shaders/pbr_textured.vert"); - str8 frag_path = str8lit("assets/shaders/pbr_textured.frag"); - str8_opt vertex_shader = str8_from_file(&scratch, vert_path); - str8_opt fragment_shader = str8_from_file(&scratch, frag_path); - if (!vertex_shader.has_value || !fragment_shader.has_value) { - ERROR_EXIT("Failed to load shaders from disk") - } - - struct graphics_pipeline_desc pipeline_description = { - .debug_name = "PBR Pipeline", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = { pbr_uniforms }, - .data_layouts_count = 1, - .vs = { .debug_name = "PBR (textured) Vertex Shader", - .filepath = vert_path, - .code = vertex_shader.contents, - .is_spirv = false }, - .fs = { .debug_name = "PBR (textured) Fragment Shader", - .filepath = frag_path, - .code = fragment_shader.contents, - .is_spirv = false }, - .renderpass = renderpass, - .wireframe = false, - .depth_test = false - }; - gpu_pipeline* pbr_pipeline = gpu_graphics_pipeline_create(pipeline_description); - - // Model - model_handle helmet_handle = - model_load_gltf("assets/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf", false); - INFO("GLTF loaded successfully!"); - model* helmet = MODEL_GET(helmet_handle); - - pbr_textured_bindgroup pbr_bind_data; - - static f32 theta = 0.0; - - while (!should_exit()) { - input_update(&g_core.input); - - if (!gpu_backend_begin_frame()) { - continue; - } - gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - // Begin recording - gpu_cmd_encoder_begin(*enc); - gpu_cmd_encoder_begin_render(enc, renderpass); - encode_bind_pipeline(enc, PIPELINE_GRAPHICS, pbr_pipeline); - encode_set_default_settings(enc); - - theta += 0.01; - transform transform = { .position = vec3(0, 0, 0), - .rotation = quat_from_axis_angle(VEC3_Z, theta, true), - .scale = 1.0 }; - mat4 model_affine = transform_to_mat(&transform); - mat4 view, proj; - camera_view_projection(&cam, 1000, 1000, &view, &proj); - - // Feed shader data - pbr_bind_data.mvp_matrices = - (mvp_matrix_uniforms){ .model = model_affine, .view = view, .projection = proj }; - pbr_bind_data.lights = (pbr_params_light_uniforms){ - .viewPos = vec4(cam.position.x, cam.position.y, cam.position.z, 1.0), - .pointLights = { point_lights[0], point_lights[1], point_lights[2], point_lights[3] } - }; - pbr_bind_data.textures = (pbr_textures){ - .albedo_tex = helmet->materials->data[0].mat_data.pbr.albedo_map, - .metal_roughness_tex = helmet->materials->data[0].mat_data.pbr.metallic_map, - .ao_tex = helmet->materials->data[0].mat_data.pbr.ao_map, - .normal_tex = helmet->materials->data[0].mat_data.pbr.normal_map, - }; - pbr_uniforms.data = &pbr_bind_data; - encode_bind_shader_data(enc, 0, &pbr_uniforms); - - // Record draw calls - mesh m = helmet->meshes->data[0]; - encode_set_vertex_buffer(enc, m.vertex_buffer); - encode_set_index_buffer(enc, m.index_buffer); - encode_draw_indexed(enc, m.geometry->indices->len); - - // End recording - gpu_cmd_encoder_end_render(enc); - - gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc); - gpu_queue_submit(&buf); - // Submit - gpu_backend_end_frame(); - } - - renderer_shutdown(&g_core.renderer); - - return 0; -}
\ No newline at end of file diff --git a/examples/primitives/ex_primitives.c b/examples/primitives/ex_primitives.c deleted file mode 100644 index 5831910..0000000 --- a/examples/primitives/ex_primitives.c +++ /dev/null @@ -1,68 +0,0 @@ -#include <glfw3.h> - -#include "buf.h" -#include "camera.h" -#include "core.h" -#include "file.h" -#include "log.h" -#include "maths.h" -#include "maths_types.h" -#include "mem.h" -#include "primitives.h" -#include "ral.h" -#include "ral_types.h" -#include "render.h" -#include "render_types.h" - -extern core g_core; - -int main() { - core_bringup(); - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - vec3 camera_pos = vec3(3.0, 2., 6.); - vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); - camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0)); - - geometry_data cube_data = geo_create_cuboid(f32x3(1, 1, 1)); - mesh cube = mesh_create(&cube_data, false); - - geometry_data sphere_data = geo_create_uvsphere(1.0, 8, 8); - mesh sphere = mesh_create(&sphere_data, false); - - geometry_data plane_data = geo_create_plane(f32x2(6, 4)); - mesh plane = mesh_create(&plane_data, false); - - // FIXME: // Texture - // texture_data tex_data = texture_data_load("assets/textures/texture.jpg", false); - // texture_handle texture = texture_data_upload(tex_data, true); - - g_core.renderer.static_opaque_pipeline.wireframe = true; - - static f32 theta = 0.0; - - // Main loop - while (!should_exit(&g_core)) { - input_update(&g_core.input); - - render_frame_begin(&g_core.renderer); - - // theta += 0.01; - transform transform = { .position = vec3(0.0, 0.0, 0.0), - .rotation = quat_from_axis_angle(VEC3_Y, theta, true), - .scale = 1.0 }; - - mat4 sphere_model = transform_to_mat(&transform); - mat4 cube_model = mat4_translation(vec3(-2., 0, 0)); - mat4 plane_model = mat4_translation(vec3(0, -2, 0)); - draw_mesh(&cube, &cube_model, &cam); - draw_mesh(&sphere, &sphere_model, &cam); - draw_mesh(&plane, &plane_model, &cam); - - render_frame_end(&g_core.renderer); - } - - renderer_shutdown(&g_core.renderer); - - return 0; -} diff --git a/examples/shadow_maps/ex_shadow_maps.c b/examples/shadow_maps/ex_shadow_maps.c deleted file mode 100644 index e918d67..0000000 --- a/examples/shadow_maps/ex_shadow_maps.c +++ /dev/null @@ -1,259 +0,0 @@ -#include "celeritas.h" -#include "input.h" -#include "log.h" -#include "maths.h" -#include "maths_types.h" -#include "primitives.h" -#include "ral.h" -#include "ral_types.h" -#include "render.h" -#include "render_types.h" -#include "renderpasses.h" - -extern core g_core; - -// Scene / light setup -vec3 light_position = { -2, 4, -1 }; -mesh s_scene[5]; -transform s_transforms[5]; - -void draw_scene(); -void switch_view(); - -enum active_view { - SceneView = 0, - LightView, - DebugQuad, -}; - -// Define the shader data -typedef struct mvp_uniforms { - mat4 model; - mat4 view; - mat4 projection; -} mvp_uniforms; -typedef struct my_shader_bind_group { - mvp_uniforms mvp; - texture_handle tex; -} my_shader_bind_group; - -// We also must create a function that knows how to return a `shader_data_layout` -shader_data_layout mvp_uniforms_layout(void* data) { - my_shader_bind_group* d = (my_shader_bind_group*)data; - bool has_data = data != NULL; - - shader_binding b1 = { .label = "Matrices", - .type = SHADER_BINDING_BYTES, - .stores_data = has_data, - .data = { .bytes = { .size = sizeof(mvp_uniforms) } } }; - - shader_binding b2 = { .label = "texSampler", - .type = SHADER_BINDING_TEXTURE, - .stores_data = has_data }; - if (has_data) { - b1.data.bytes.data = &d->mvp; - b2.data.texture.handle = d->tex; - } - return (shader_data_layout){ .name = "global_ubo", .bindings = { b1, b2 }, .bindings_count = 2 }; -} - -int main() { - // Stuff that gets changed during program - enum active_view current_view = SceneView; - - core_bringup(); - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - vec3 camera_pos = vec3(5, 5, 5); - vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); - camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0)); - // TEMP - shader_data mvp_uniforms_data = { .data = NULL, .shader_data_get_layout = &mvp_uniforms_layout }; - - gpu_renderpass_desc pass_description = { .default_framebuffer = true }; - gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); - - str8 vert_path, frag_path; -#ifdef CEL_REND_BACKEND_OPENGL - vert_path = str8lit("assets/shaders/cube.vert"); - frag_path = str8lit("assets/shaders/cube.frag"); -#else - vert_path = str8lit("build/linux/x86_64/debug/cube.vert.spv"); - frag_path = str8lit("build/linux/x86_64/debug/cube.frag.spv"); -#endif - str8_opt vertex_shader = str8_from_file(&scratch, vert_path); - str8_opt fragment_shader = str8_from_file(&scratch, frag_path); - if (!vertex_shader.has_value || !fragment_shader.has_value) { - ERROR_EXIT("Failed to load shaders from disk") - } - - struct graphics_pipeline_desc pipeline_description = { - .debug_name = "Basic Pipeline", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = { mvp_uniforms_data }, - .data_layouts_count = 1, - .vs = { .debug_name = "Cube Vertex Shader", - .filepath = vert_path, - .code = vertex_shader.contents, - .is_spirv = true }, - .fs = { .debug_name = "Cube Fragment Shader", - .filepath = frag_path, - .code = fragment_shader.contents, - .is_spirv = true }, - .renderpass = renderpass, - .wireframe = false, - .depth_test = false - }; - gpu_pipeline* gfx_pipeline = gpu_graphics_pipeline_create(pipeline_description); - - // Textures - texture_data tex_data = texture_data_load("assets/textures/texture.jpg", false); - texture_handle texture = texture_data_upload(tex_data, true); - texture_handle white_tex = - texture_data_upload(texture_data_load("assets/models/obj/cube/container.jpg", false), true); - - // END TEMP - - ren_shadowmaps shadows = { .width = 1000, .height = 1000 }; - ren_shadowmaps_init(&shadows); - - // Set up the scene - // We want: - // 1. a ground plane - // 2. lights - // 3. some boxes - for (int i = 0; i < 4; i++) { - geometry_data geo = geo_create_cuboid(f32x3(1, 1, 1)); - s_scene[i] = mesh_create(&geo, true); - s_transforms[i] = transform_create(vec3(-2 + (i * 1.2), 0, 0), quat_ident(), 1.0); - } - geometry_data plane = geo_create_plane(f32x2(20, 20)); - s_scene[4] = mesh_create(&plane, true); - s_transforms[4] = transform_create(vec3(0, -3, 0), quat_ident(), 1.0); - - geometry_data quad_geo = geo_create_plane(f32x2(2, 2)); - - // HACK: Swap vertices to make it face us - vertex top0 = quad_geo.vertices->data[0]; - quad_geo.vertices->data[0] = quad_geo.vertices->data[2]; - quad_geo.vertices->data[2] = top0; - vertex top1 = quad_geo.vertices->data[1]; - quad_geo.vertices->data[1] = quad_geo.vertices->data[3]; - quad_geo.vertices->data[3] = top1; - - mesh quad = mesh_create(&quad_geo, true); - - // Main loop - while (!should_exit(&g_core)) { - input_update(&g_core.input); - printf("Frame\n"); - - if (key_just_released(KEYCODE_L)) { - current_view = (current_view + 1) % 3; - } - if (key_just_released(KEYCODE_R)) { - // TODO: gpu_pipeline_reload_shaders(gfx_pipeline); - } - - if (!gpu_backend_begin_frame()) { - continue; - } - gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - gpu_cmd_encoder_begin(*enc); - - // Shadow draw - gpu_cmd_encoder_begin_render(enc, shadows.rpass); - printf("Here\n"); - - // calculations - f32 near_plane = 1.0, far_plane = 10.0; - mat4 light_projection = mat4_orthographic(-10.0, 10.0, -10.0, 10.0, near_plane, far_plane); - mat4 light_view = mat4_look_at(light_position, VEC3_ZERO, VEC3_Y); - mat4 light_space_matrix = mat4_mult(light_view, light_projection); - lightspace_tf_uniform lsu = { .lightSpaceMatrix = light_space_matrix }; - - encode_bind_pipeline(enc, PIPELINE_GRAPHICS, shadows.static_pipeline); - - shader_data lightspace_data = { .data = NULL, - .shader_data_get_layout = &lightspace_uniform_layout }; - lightspace_data.data = &lsu; - encode_bind_shader_data(enc, 0, &lightspace_data); - - draw_scene(); - printf("Here\n"); - - gpu_cmd_encoder_end_render(enc); - // End - - // Debug quad - if (current_view == DebugQuad) { - gpu_cmd_encoder_begin_render(enc, shadows.debug_quad->renderpass); - - encode_bind_pipeline(enc, PIPELINE_GRAPHICS, shadows.debug_quad); - debug_quad_uniform dqu = { .depthMap = shadows.depth_tex }; - shader_data debug_quad_data = { .data = &dqu, .shader_data_get_layout = debug_quad_layout }; - encode_bind_shader_data(enc, 0, &debug_quad_data); - encode_set_vertex_buffer(enc, quad.vertex_buffer); - encode_set_index_buffer(enc, quad.index_buffer); - encode_draw_indexed(enc, quad.geometry->indices->len); - - gpu_cmd_encoder_end_render(enc); - } - - // Basic draw - if (current_view == SceneView || current_view == LightView) { - gpu_cmd_encoder_begin_render(enc, renderpass); - encode_bind_pipeline(enc, PIPELINE_GRAPHICS, gfx_pipeline); - - mat4 view, proj; - if (current_view == SceneView) { - camera_view_projection(&cam, 1000, 1000, &view, &proj); - } else { - view = light_view; - proj = light_projection; - } - for (int i = 0; i < 5; i++) { - mat4 model = transform_to_mat(&s_transforms[i]); - mvp_uniforms mvp_data = { .model = model, .view = view, .projection = proj }; - my_shader_bind_group shader_bind_data = { .mvp = mvp_data, .tex = texture }; - if (i == 4) { - shader_bind_data.tex = white_tex; - } - mvp_uniforms_data.data = &shader_bind_data; - encode_bind_shader_data(enc, 0, &mvp_uniforms_data); - encode_set_vertex_buffer(enc, s_scene[i].vertex_buffer); - encode_set_index_buffer(enc, s_scene[i].index_buffer); - encode_draw_indexed(enc, s_scene[i].geometry->indices->len); - } - - gpu_cmd_encoder_end_render(enc); - } - - // END drawing - gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc); - gpu_queue_submit(&buf); - gpu_backend_end_frame(); - } - - renderer_shutdown(&g_core.renderer); - - return 0; -} - -void draw_scene() { - gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - for (int i = 0; i < 5; i++) { - mat4 model = transform_to_mat(&s_transforms[i]); - model_uniform mu = { .model = model }; - shader_data model_data = { .data = &mu, .shader_data_get_layout = model_uniform_layout }; - encode_bind_shader_data(enc, 0, &model_data); - printf("Here1\n"); - encode_set_vertex_buffer(enc, s_scene[i].vertex_buffer); - printf("Here2\n"); - encode_set_index_buffer(enc, s_scene[i].index_buffer); - printf("Here3\n"); - printf("num %ld \n", s_scene[i].geometry->indices->len); - encode_draw_indexed(enc, s_scene[i].geometry->indices->len); - printf("Here4\n"); - } -} diff --git a/examples/skinned_animation/ex_skinned_animation.c b/examples/skinned_animation/ex_skinned_animation.c deleted file mode 100644 index 81642ae..0000000 --- a/examples/skinned_animation/ex_skinned_animation.c +++ /dev/null @@ -1,100 +0,0 @@ -#include <assert.h> -#include <glfw3.h> - -#include "animation.h" -#include "camera.h" -#include "core.h" -#include "loaders.h" -#include "log.h" -#include "maths.h" -#include "maths_types.h" -#include "pbr.h" -#include "render.h" -#include "render_types.h" - -int main() { - double currentFrame = glfwGetTime(); - double lastFrame = currentFrame; - double delta_time; - - Core_Bringup("Skinned Animation", NULL); - - ModelHandle handle = ModelLoad_gltf("assets/models/gltf/SimpleSkin/glTF/SimpleSkin.gltf", false); - Model* simple_skin = MODEL_GET(handle); - - RenderEnt_darray* rend_ents = RenderEnt_darray_new(1); - - // Okay, right here we've loaded the model. let's assert some facts - // assert(simple_skin->animations->len == 1); - // assert(simple_skin->animations->data[0].rotation != NULL); - // assert(simple_skin->animations->data[0].translation == NULL); - // assert(simple_skin->animations->data[0].scale == NULL); - - // mesh* m = &simple_skin->meshes->data[0]; - // assert(m->is_skinned); - // assert(m->bones->len == 2); // 1 root and 1 extra joint - - // assert(false); - - // model_upload_meshes(&core->renderer, simple_skin); - - // scene our_scene = make_default_scene(); - - Vec3 cam_pos = vec3_create(1.5, 2.2, 8); - Camera cam = Camera_Create(cam_pos, VEC3_NEG_Z, VEC3_Y, deg_to_rad(45.0)); - SetCamera(cam); - - // Main loop - const f32 camera_lateral_speed = 0.2; - const f32 camera_zoom_speed = 0.10; - - // animation - // animation_clip track = simple_skin->animations->data[0]; - CASSERT(AnimationClip_darray_len(simple_skin->animations) > 0); - AnimationClip track = simple_skin->animations->data[0]; - f64 total_time = 0.0; - - while (!ShouldExit()) { - Frame_Begin(); - - currentFrame = glfwGetTime(); - delta_time = currentFrame - lastFrame; - lastFrame = currentFrame; - total_time += delta_time; - // printf("delta time %f\n", deltaTime); - f64 t = fmod(total_time, track.channels->data[0].max); - INFO("Delta time %f Animation time: %f", delta_time, t); - - // bone rotation - // Quat rot = animation_sample(track.rotation, t).rotation; - - // m->bones->data[1].transform_components.rotation = rot; - - // quat rot = quat_ident(); - // Transform tf = transform_create(VEC3_ZERO, quat_ident(), 1.0); - - // TODO: Drawing should still just use the PBR pipeline - Mesh* m = Mesh_Get(simple_skin->meshes[0]); - RenderEnt render_ents[1] = { (RenderEnt){ .mesh = simple_skin->meshes[0], - .material = m->material, - .armature = &m->armature, - .affine = mat4_ident(), - .flags = 0 } }; - // ModelExtractRenderEnts(rend_ents, handle, mat4_translation(vec3(0, 0, 0)), 0); - - // draw_skinned_model(&core->renderer, &game.camera, simple_skin, tf, &our_scene); - Animation_Tick(&track, &m->armature, t); - - Render_RenderEntities(render_ents, 1); - - Animation_VisualiseJoints(&m->armature); - - RenderEnt_darray_clear(rend_ents); - - Frame_End(); - } - - INFO("Shutting down"); - - return 0; -} diff --git a/examples/transforms/ex_transforms.c b/examples/transforms/ex_transforms.c deleted file mode 100644 index fc225b4..0000000 --- a/examples/transforms/ex_transforms.c +++ /dev/null @@ -1,88 +0,0 @@ -#include <glfw3.h> - -#include "core.h" -#include "maths.h" -#include "maths_types.h" -#include "mem.h" -#include "render.h" -// #include "render_types.h" -#include "transform_hierarchy.h" - -const vec3 pointlight_positions[4] = { - { 0.7, 0.2, 2.0 }, - { 2.3, -3.3, -4.0 }, - { -4.0, 2.0, -12.0 }, - { 0.0, 0.0, -3.0 }, -}; -point_light point_lights[4]; - -int main() { - core* core = core_bringup(); - - // Set up scene - vec3 camera_pos = vec3(3., 4., 10.); - vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); - camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0)); - - model_handle cube_handle = model_load_obj(core, "assets/models/obj/cube/cube.obj", true); - model* cube = &core->models->data[cube_handle.raw]; - model_upload_meshes(&core->renderer, cube); - - directional_light dir_light = { .direction = (vec3){ -0.2, -1.0, -0.3 }, - .ambient = (vec3){ 0.2, 0.2, 0.2 }, - .diffuse = (vec3){ 0.5, 0.5, 0.5 }, - .specular = (vec3){ 1.0, 1.0, 1.0 } }; - // point lights setup - for (int i = 0; i < 4; i++) { - point_lights[i].position = pointlight_positions[i]; - point_lights[i].ambient = (vec3){ 0.05, 0.05, 0.05 }; - point_lights[i].diffuse = (vec3){ 0.8, 0.8, 0.8 }; - point_lights[i].specular = (vec3){ 1.0, 1.0, 1.0 }; - point_lights[i].constant = 1.0; - point_lights[i].linear = 0.09; - point_lights[i].quadratic = 0.032; - } - - scene our_scene = { .dir_light = dir_light, .n_point_lights = 4 }; - memcpy(&our_scene.point_lights, &point_lights, sizeof(point_light[4])); - - // Create transform hierarchy - transform_hierarchy* transform_tree = transform_hierarchy_create(); - transform_node* root_node = transform_hierarchy_root_node(transform_tree); - // Add nodes - // -- 4 cubes - transform cube1 = transform_create(vec3(0.0, -2.0, 0.0), quat_ident(), 0.8); - transform cube2 = transform_create(vec3(0.0, 1.0, 0.0), quat_ident(), 1.0); - transform cube3 = transform_create(vec3(0.0, 1.0, 0.0), quat_ident(), 1.0); - transform cube4 = transform_create(vec3(0.0, 1.0, 0.0), quat_ident(), 1.0); - transform_node* node1 = transform_hierarchy_add_node(root_node, cube_handle, cube1); - transform_node* node2 = transform_hierarchy_add_node(node1, cube_handle, cube2); - transform_node* node3 = transform_hierarchy_add_node(node2, cube_handle, cube3); - transform_node* node4 = transform_hierarchy_add_node(node3, cube_handle, cube4); - - transform_hierarchy_debug_print(root_node, core); - - char* frame_allocator_storage = malloc(1024 * 1024 * 64); - arena frame_arena = arena_create(frame_allocator_storage, 1024 * 1024 * 64); - - // Main loop - while (!glfwWindowShouldClose(core->renderer.window)) { - input_update(&core->input); - threadpool_process_results(&core->threadpool, 1); - - render_frame_begin(&core->renderer); - transform_hierarchy_propagate_transforms(transform_tree); - - // TODO: Add setters to transform API - node1->tf.position.x += 0.004; - node1->tf.is_dirty = true; - draw_scene(&frame_arena, core->models, &core->renderer, &cam, transform_tree, &our_scene); - - render_frame_end(&core->renderer); - arena_free_all(&frame_arena); - } - - transform_hierarchy_free(transform_tree); - - return 0; -} diff --git a/examples/triangle/ex_triangle.c b/examples/triangle/ex_triangle.c deleted file mode 100644 index cd401c7..0000000 --- a/examples/triangle/ex_triangle.c +++ /dev/null @@ -1,115 +0,0 @@ -#include <glfw3.h> - -#include "backend_vulkan.h" -#include "buf.h" -#include "camera.h" -#include "core.h" -#include "defines.h" -#include "file.h" -#include "log.h" -#include "maths.h" -#include "mem.h" -#include "ral.h" -#include "ral_types.h" -#include "render.h" -#include "render_types.h" - -extern core g_core; - -int main() { - custom_vertex vertices[] = { - (custom_vertex){ .pos = vec2(-0.5, -0.5), .color = vec3(1.0, 1.0, 1.0) }, - (custom_vertex){ .pos = vec2(0.5, -0.5), .color = vec3(1.0, 0.0, 0.0) }, - (custom_vertex){ .pos = vec2(-0.5, 0.5), .color = vec3(0.0, 0.0, 1.0) }, - (custom_vertex){ .pos = vec2(0.5, 0.5), .color = vec3(0.0, 1.0, 0.0) }, - }; - const u32 indices[] = { 2, 1, 0, 1, 2, 3 }; - - core_bringup(); - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - vertex_description vertex_input = { .use_full_vertex_size = false }; - vertex_input.debug_label = "Hello"; - vertex_desc_add(&vertex_input, "inPos", ATTR_F32x2); - vertex_desc_add(&vertex_input, "inColor", ATTR_F32x3); - - gpu_renderpass_desc pass_description = {}; - gpu_renderpass* renderpass = gpu_renderpass_create(&pass_description); - - str8 vert_path, frag_path; -#if defined(CEL_REND_BACKEND_OPENGL) - vert_path = str8lit("assets/shaders/triangle.vert"); - frag_path = str8lit("assets/shaders/triangle.frag"); -#elif defined(CEL_REND_BACKEND_METAL) - vert_path = str8lit("build/gfx.metallib"); - frag_path = str8lit("build/gfx.metallib"); -#endif - str8_opt vertex_shader = str8_from_file(&scratch, vert_path); - str8_opt fragment_shader = str8_from_file(&scratch, frag_path); - if (!vertex_shader.has_value || !fragment_shader.has_value) { - ERROR_EXIT("Failed to load shaders from disk") - } - - struct graphics_pipeline_desc pipeline_description = { - .debug_name = "Basic Pipeline", - .vertex_desc = vertex_input, - // .data_layouts = {0}, - // .data_layouts_count = 0, - .vs = { .debug_name = "Triangle Vertex Shader", - .filepath = vert_path, - .code = vertex_shader.contents, -#ifdef CEL_REND_BACKEND_METAL - .is_combined_vert_frag = true, -#endif - .is_spirv = true, - }, - .fs = { .debug_name = "Triangle Fragment Shader", - .filepath = frag_path, - .code = fragment_shader.contents, - .is_spirv = true }, - .renderpass = renderpass, - .wireframe = false, - .depth_test = false - }; - gpu_pipeline* gfx_pipeline = gpu_graphics_pipeline_create(pipeline_description); - - // Load triangle vertex and index data - buffer_handle triangle_vert_buf = gpu_buffer_create(4 * sizeof(custom_vertex), CEL_BUFFER_VERTEX, - CEL_BUFFER_FLAG_GPU, vertices); - - buffer_handle triangle_index_buf = - gpu_buffer_create(sizeof(indices), CEL_BUFFER_INDEX, CEL_BUFFER_FLAG_GPU, indices); - - // // Main loop - while (!should_exit()) { - input_update(&g_core.input); - - if (!gpu_backend_begin_frame()) { - continue; - } - gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); - // // Begin recording - gpu_cmd_encoder_begin(*enc); - gpu_cmd_encoder_begin_render(enc, renderpass); - encode_bind_pipeline(enc, PIPELINE_GRAPHICS, gfx_pipeline); - encode_set_default_settings(enc); - - // // Record draw calls - encode_set_vertex_buffer(enc, triangle_vert_buf); - encode_set_index_buffer(enc, triangle_index_buf); - encode_draw_indexed(enc, 6); - - // // End recording - // gpu_cmd_encoder_end_render(enc); - - // gpu_cmd_buffer buf = gpu_cmd_encoder_finish(enc); // Command buffer is no longer recording - // and is ready to submit - // // Submit - // gpu_queue_submit(&buf); - gpu_backend_end_frame(); - } - - renderer_shutdown(&g_core.renderer); - - return 0; -} diff --git a/include/celeritas.h b/include/celeritas.h index bb10d34..edd7a4b 100644 --- a/include/celeritas.h +++ b/include/celeritas.h @@ -93,6 +93,10 @@ bool should_exit(); // --- Strings +// --- Logging + +// TODO: Namespaced logger + // --- Maths /** @brief 3D Vector */ @@ -230,7 +234,7 @@ void GPU_TextureDestroy(TexHandle handle); // --- Containers (Forward declared as internals are unnecessary for external header) typedef struct u32_darray u32_darray; -// --- Base Renderer +// --- Base Renderer types DEFINE_HANDLE(MeshHandle); DEFINE_HANDLE(MaterialHandle); @@ -272,8 +276,14 @@ typedef struct Camera { f32 fov; } Camera; +// --- Reference Renderer + +// TODO: Filament PBR model + // --- Animation // --- Collisions // --- Physics + +// --- Platform diff --git a/new_src/platform_osx.c b/new_src/platform_osx.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/new_src/platform_osx.c diff --git a/new_src/platform_unix.c b/new_src/platform_unix.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/new_src/platform_unix.c diff --git a/new_src/platform_win32.c b/new_src/platform_win32.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/new_src/platform_win32.c |