diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-13 20:29:27 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-08-13 20:29:27 +1000 |
commit | 567d384b698151e287e31140709c93f1b92e6db4 (patch) | |
tree | e00975124d3f002a8aaa22e85475d913c6950346 /src/render | |
parent | 13949ca02bcf9fcdfcc48ea7949f617553a260b6 (diff) |
loading joints and animations
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/archive/backends/opengl/backend_opengl.h | 22 | ||||
-rw-r--r-- | src/render/immdraw.h | 3 | ||||
-rw-r--r-- | src/render/pbr.c | 109 | ||||
-rw-r--r-- | src/render/pbr.h | 6 | ||||
-rw-r--r-- | src/render/render.c | 5 | ||||
-rw-r--r-- | src/render/render.h | 1 | ||||
-rw-r--r-- | src/render/render_types.h | 4 | ||||
-rw-r--r-- | src/render/shadows.c | 2 |
8 files changed, 96 insertions, 56 deletions
diff --git a/src/render/archive/backends/opengl/backend_opengl.h b/src/render/archive/backends/opengl/backend_opengl.h index 73a19ed..14b44af 100644 --- a/src/render/archive/backends/opengl/backend_opengl.h +++ b/src/render/archive/backends/opengl/backend_opengl.h @@ -17,11 +17,11 @@ typedef struct gpu_swapchain { typedef struct gpu_device { } gpu_device; typedef struct gpu_pipeline_layout { - void *pad + void* pad } gpu_pipeline_layout; typedef struct gpu_pipeline { u32 shader_id; - gpu_renderpass *renderpass; + gpu_renderpass* renderpass; vertex_description vertex_desc; buffer_handle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS]; u32 uniform_count; @@ -32,10 +32,10 @@ typedef struct gpu_renderpass { gpu_renderpass_desc description; } gpu_renderpass; typedef struct gpu_cmd_encoder { - gpu_pipeline *pipeline; + gpu_pipeline* pipeline; } gpu_cmd_encoder; // Recording typedef struct gpu_cmd_buffer { - void *pad; + void* pad; } gpu_cmd_buffer; // Ready for submission typedef struct gpu_buffer { @@ -48,21 +48,21 @@ typedef struct gpu_buffer { u32 vao; u32 ubo_binding_point }; // Optional - char *name; + char* name; u64 size; } gpu_buffer; typedef struct gpu_texture { u32 id; - void *pad; + void* pad; } gpu_texture; typedef struct opengl_support { } opengl_support; -u32 shader_create_separate(const char *vert_shader, const char *frag_shader); +u32 shader_create_separate(const char* vert_shader, const char* frag_shader); -void uniform_vec3f(u32 program_id, const char *uniform_name, vec3 *value); -void uniform_f32(u32 program_id, const char *uniform_name, f32 value); -void uniform_i32(u32 program_id, const char *uniform_name, i32 value); -void uniform_mat4f(u32 program_id, const char *uniform_name, mat4 *value); +void uniform_vec3f(u32 program_id, const char* uniform_name, vec3* value); +void uniform_f32(u32 program_id, const char* uniform_name, f32 value); +void uniform_i32(u32 program_id, const char* uniform_name, i32 value); +void uniform_mat4f(u32 program_id, const char* uniform_name, mat4* value); #endif diff --git a/src/render/immdraw.h b/src/render/immdraw.h index aa1847b..b205129 100644 --- a/src/render/immdraw.h +++ b/src/render/immdraw.h @@ -37,7 +37,8 @@ PUB void Immdraw_TransformGizmo(Transform tf, f32 size); // --- Internal -void Immdraw_Primitive(Transform tf, PrimitiveTopology topology, f32 size, Vec4 colour, bool wireframe, Mesh mesh); +void Immdraw_Primitive(Transform tf, PrimitiveTopology topology, f32 size, Vec4 colour, + bool wireframe, Mesh mesh); Mesh GenBboxMesh(); diff --git a/src/render/pbr.c b/src/render/pbr.c index fbdacac..57ca1d8 100644 --- a/src/render/pbr.c +++ b/src/render/pbr.c @@ -15,7 +15,7 @@ void PBR_Init(PBR_Storage* storage) { INFO("PBR shaders init"); storage->pbr_pass = PBR_RPassCreate(); - storage->pbr_pipeline = PBR_PipelineCreate(storage->pbr_pass); + PBR_PipelinesCreate(storage, storage->pbr_pass); } GPU_Renderpass* PBR_RPassCreate() { @@ -23,45 +23,72 @@ GPU_Renderpass* PBR_RPassCreate() { return GPU_Renderpass_Create(desc); } -GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass) { - arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024); - - const char* vert_path = "assets/shaders/pbr_textured.vert"; - const char* frag_path = "assets/shaders/pbr_textured.frag"; - // Str8 vert_path = str8("assets/shaders/pbr_textured.vert"); - // Str8 frag_path = str8("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") - // } - char* vert_shader = string_from_file(vert_path); - char* frag_shader = string_from_file(frag_path); - - ShaderDataLayout camera_data = Binding_Camera_GetLayout(NULL); - ShaderDataLayout model_data = Binding_Model_GetLayout(NULL); - ShaderDataLayout material_data = PBRMaterial_GetLayout(NULL); - ShaderDataLayout lights_data = Binding_Lights_GetLayout(NULL); - - GraphicsPipelineDesc desc = { - .debug_name = "PBR Pipeline", - .vertex_desc = static_3d_vertex_description(), - .data_layouts = {camera_data,model_data,material_data, lights_data }, - .data_layouts_count = 4, - .vs = { .debug_name = "PBR (textured) Vertex Shader", - .filepath = str8(vert_path), - // .code = vertex_shader.contents - .code = vert_shader - }, - .fs = { .debug_name = "PBR (textured) Fragment Shader", - .filepath = str8(frag_path), - .code = frag_shader - // .code = fragment_shader.contents, - }, - .depth_test = true, - .wireframe = false, - }; - return GPU_GraphicsPipeline_Create(desc, rpass); +void PBR_PipelinesCreate(PBR_Storage* storage, GPU_Renderpass* rpass) { + // Static + { + const char* vert_path = "assets/shaders/static_geometry.vert"; + const char* frag_path = "assets/shaders/pbr_textured.frag"; + char* vert_shader = string_from_file(vert_path); + char* frag_shader = string_from_file(frag_path); + + ShaderDataLayout camera_data = Binding_Camera_GetLayout(NULL); + ShaderDataLayout model_data = Binding_Model_GetLayout(NULL); + ShaderDataLayout material_data = PBRMaterial_GetLayout(NULL); + ShaderDataLayout lights_data = Binding_Lights_GetLayout(NULL); + + GraphicsPipelineDesc desc = { + .debug_name = "PBR (Static) Pipeline", + .vertex_desc = static_3d_vertex_description(), + .data_layouts = { camera_data, model_data, material_data, lights_data }, + .data_layouts_count = 4, + .vs = { .debug_name = "PBR (textured) Vertex Shader", + .filepath = str8(vert_path), + .code = vert_shader }, + .fs = { .debug_name = "PBR (textured) Fragment Shader", + .filepath = str8(frag_path), + .code = frag_shader }, + .depth_test = true, + .wireframe = true, + }; + storage->pbr_static_pipeline = GPU_GraphicsPipeline_Create(desc, rpass); + } + + // Skinned + { + const char* vert_path = "assets/shaders/skinned_geometry.vert"; + const char* frag_path = "assets/shaders/pbr_textured.frag"; + char* vert_shader = string_from_file(vert_path); + char* frag_shader = string_from_file(frag_path); + + ShaderDataLayout camera_data = Binding_Camera_GetLayout(NULL); + ShaderDataLayout model_data = Binding_Model_GetLayout(NULL); + ShaderDataLayout material_data = PBRMaterial_GetLayout(NULL); + ShaderDataLayout lights_data = Binding_Lights_GetLayout(NULL); + + VertexDescription vertex_desc = { .debug_label = "Skinned vertices", + .use_full_vertex_size = true }; + VertexDesc_AddAttr(&vertex_desc, "inPos", ATTR_F32x3); + VertexDesc_AddAttr(&vertex_desc, "inNormal", ATTR_F32x3); + VertexDesc_AddAttr(&vertex_desc, "inTexCoords", ATTR_F32x2); + VertexDesc_AddAttr(&vertex_desc, "inBoneIndices", ATTR_I32x4); + VertexDesc_AddAttr(&vertex_desc, "inWeights", ATTR_F32x4); + + GraphicsPipelineDesc desc = { + .debug_name = "PBR (Skinned) Pipeline", + .vertex_desc = vertex_desc, + .data_layouts = { camera_data, model_data, material_data, lights_data }, + .data_layouts_count = 4, + .vs = { .debug_name = "PBR (textured) Vertex Shader", + .filepath = str8(vert_path), + .code = vert_shader }, + .fs = { .debug_name = "PBR (textured) Fragment Shader", + .filepath = str8(frag_path), + .code = frag_shader }, + .depth_test = true, + .wireframe = true, + }; + storage->pbr_skinned_pipeline = GPU_GraphicsPipeline_Create(desc, rpass); + } } void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_tex, @@ -75,7 +102,7 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te GPU_CmdEncoder* enc = GPU_GetDefaultEncoder(); GPU_CmdEncoder_BeginRender(enc, storage->pbr_pass); - GPU_EncodeBindPipeline(enc, storage->pbr_pipeline); + GPU_EncodeBindPipeline(enc, storage->pbr_static_pipeline); // Feed shader data Mat4 view, proj; diff --git a/src/render/pbr.h b/src/render/pbr.h index d7b660b..5a21533 100644 --- a/src/render/pbr.h +++ b/src/render/pbr.h @@ -16,7 +16,8 @@ /** @brief Holds data for the PBR pipeline */ typedef struct PBR_Storage { GPU_Renderpass* pbr_pass; - GPU_Pipeline* pbr_pipeline; + GPU_Pipeline* pbr_static_pipeline; + GPU_Pipeline* pbr_skinned_pipeline; } PBR_Storage; typedef struct PBRMaterialUniforms { @@ -62,7 +63,8 @@ PUB ShaderDataLayout PBRMaterial_GetLayout(void* data); GPU_Renderpass* PBR_RPassCreate(); /** @brief Create the PBR Renderpass */ -GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); /** @brief Create the PBR Pipeline */ +void PBR_PipelinesCreate(PBR_Storage* storage, + GPU_Renderpass* rpass); /** @brief Create PBR Pipelines */ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_tex, RenderEnt* entities, size_t entity_count); diff --git a/src/render/render.c b/src/render/render.c index 4e7a60c..af636a8 100644 --- a/src/render/render.c +++ b/src/render/render.c @@ -283,6 +283,11 @@ PUB MaterialHandle Material_Insert(Material* material) { } Mesh* Mesh_Get(MeshHandle handle) { return Mesh_pool_get(Render_GetMeshPool(), handle); } +void Mesh_DebugPrint(Mesh* mesh) { + printf("Mesh %d vertices %d indices %d joints \n", mesh->geometry.vertices->len, + mesh->geometry.indices->len); +} + size_t ModelExtractRenderEnts(RenderEnt_darray* entities, ModelHandle model_handle, Mat4 affine, RenderEntityFlags flags) { Model* model = MODEL_GET(model_handle); diff --git a/src/render/render.h b/src/render/render.h index 785c140..d752f8b 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -76,6 +76,7 @@ PUB void Mesh_Delete(Mesh* mesh); Mesh* Mesh_Get(MeshHandle handle); void Geometry_Destroy(Geometry* geometry); MeshHandle Mesh_Insert(Mesh* mesh); +void Mesh_DebugPrint(Mesh* mesh); MaterialHandle Material_Insert(Material* material); /** @brief gets render entities from a model and pushes them into a dynamic array for rendering */ diff --git a/src/render/render_types.h b/src/render/render_types.h index 89773a5..5e2b282 100644 --- a/src/render/render_types.h +++ b/src/render/render_types.h @@ -3,6 +3,7 @@ */ #pragma once +#include "animation.h" #include "defines.h" #include "maths_types.h" #include "mem.h" @@ -95,6 +96,9 @@ typedef struct Model { size_t mesh_count; MaterialHandle* materials; size_t material_count; + Armature armature; + bool has_joints; + AnimationClip_darray* animations; } Model; #ifndef TYPED_MODEL_ARRAY KITC_DECL_TYPED_ARRAY(Model) diff --git a/src/render/shadows.c b/src/render/shadows.c index 3d348ea..029eefb 100644 --- a/src/render/shadows.c +++ b/src/render/shadows.c @@ -127,7 +127,7 @@ void Shadow_Init(Shadow_Storage* storage, u32 shadowmap_width, u32 shadowmap_hei storage->debugquad_pipeline = GPU_GraphicsPipeline_Create(debugquad_pipeline_desc, storage->debugquad_pass); - Geometry quad_geo = Geo_CreatePlane(f32x2(1, 1), 1,1 ); + Geometry quad_geo = Geo_CreatePlane(f32x2(1, 1), 1, 1); // 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]; |