diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-06-23 01:11:28 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-06-23 01:11:28 +1000 |
commit | 17f0db6607534c5bf1ba96153fabd3fdbb399ed9 (patch) | |
tree | c6531c6c688e9719817ac4c06127affc1313f5d3 /src | |
parent | d20356fd426ccea1866fbda798864a378303bbbd (diff) |
wip: debug quad shader
Diffstat (limited to 'src')
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.c | 1 | ||||
-rw-r--r-- | src/renderer/backends/opengl/backend_opengl.h | 1 | ||||
-rw-r--r-- | src/renderer/ral.c | 20 | ||||
-rw-r--r-- | src/renderer/ral.h | 2 | ||||
-rw-r--r-- | src/renderer/renderpasses.c | 44 | ||||
-rw-r--r-- | src/renderer/renderpasses.h | 19 |
6 files changed, 78 insertions, 9 deletions
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c index 00b41b2..7d8aa01 100644 --- a/src/renderer/backends/opengl/backend_opengl.c +++ b/src/renderer/backends/opengl/backend_opengl.c @@ -120,6 +120,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip } } + pipeline->renderpass = description.renderpass; pipeline->wireframe = description.wireframe; return pipeline; diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h index 9cfbb06..a5a9140 100644 --- a/src/renderer/backends/opengl/backend_opengl.h +++ b/src/renderer/backends/opengl/backend_opengl.h @@ -21,6 +21,7 @@ typedef struct gpu_pipeline_layout { } gpu_pipeline_layout; typedef struct gpu_pipeline { u32 shader_id; + gpu_renderpass* renderpass; vertex_description vertex_desc; buffer_handle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS]; bool wireframe; diff --git a/src/renderer/ral.c b/src/renderer/ral.c index e73843b..a52d605 100644 --- a/src/renderer/ral.c +++ b/src/renderer/ral.c @@ -1,4 +1,8 @@ #include "ral.h" +#include "file.h" +#include "log.h" +#include "str.h" +#include "mem.h" #if defined(CEL_REND_BACKEND_VULKAN) #include "backend_vulkan.h" @@ -75,3 +79,19 @@ void print_shader_binding(shader_binding b) { printf("Binding name: %s type %s vis %d stores data %d\n", b.label, shader_binding_type_name[b.type], b.vis, b.stores_data); } + +shader_desc shader_quick_load(const char* filepath) { + arena a = arena_create(malloc(1024 * 1024), 1024 * 1024); + str8 path = str8_cstr_view(filepath); + str8_opt shader = str8_from_file(&a, path); + if (!shader.has_value) { + ERROR_EXIT("Failed to load shaders from disk"); + } + + return (shader_desc) { + .debug_name = filepath, + .code = shader.contents, + .filepath = path, + .is_spirv = true, + }; +}
\ No newline at end of file diff --git a/src/renderer/ral.h b/src/renderer/ral.h index ab62679..9d6ed41 100644 --- a/src/renderer/ral.h +++ b/src/renderer/ral.h @@ -76,6 +76,8 @@ typedef struct shader_desc { bool is_combined_vert_frag; // Contains both vertex and fragment stages } shader_desc; +shader_desc shader_quick_load(const char* filepath); + struct graphics_pipeline_desc { const char* debug_name; vertex_description vertex_desc; diff --git a/src/renderer/renderpasses.c b/src/renderer/renderpasses.c index e005c14..5193a1c 100644 --- a/src/renderer/renderpasses.c +++ b/src/renderer/renderpasses.c @@ -11,6 +11,7 @@ #include "renderpasses.h" #include "file.h" +#include "log.h" #include "maths_types.h" #include "ral.h" #include "ral_types.h" @@ -18,9 +19,41 @@ #define SHADOW_WIDTH 1000 #define SHADOW_HEIGHT 1000 +shader_data_layout debug_quad_layout(void* data) { + debug_quad_uniform* d = data; + bool has_data = data != NULL; + + shader_binding b1 = { .label = "depthMap", + .type = SHADER_BINDING_TEXTURE, + .stores_data = has_data}; + if (has_data) { + b1.data.texture.handle = d->depthMap; + } + return (shader_data_layout){ .name = "debug quad uniforms", .bindings = { b1 }, .bindings_count = 1 }; +} + +gpu_pipeline* debug_quad_pipeline_create() { + gpu_renderpass_desc rpass_desc = {.default_framebuffer = true }; + gpu_renderpass* rpass = gpu_renderpass_create(&rpass_desc); + shader_data shader_layout = {.data = NULL, .shader_data_get_layout = debug_quad_layout}; + struct graphics_pipeline_desc desc = { + .debug_name = "Shadow maps debug quad", + .vertex_desc = static_3d_vertex_description(), + .data_layouts = { shader_layout }, + .data_layouts_count = 1, + .vs = shader_quick_load("assets/shaders/debug_quad.vert"), + .fs = shader_quick_load("assets/shaders/debug_quad.frag"), + .renderpass = rpass, + }; + + return gpu_graphics_pipeline_create(desc); +} + void ren_shadowmaps_init(ren_shadowmaps* storage) { storage->rpass = shadowmaps_renderpass_create(); storage->static_pipeline = shadowmaps_pipeline_create(storage->rpass); + storage->debug_quad = debug_quad_pipeline_create(); + storage->depth_tex = storage->rpass->description.depth_stencil; } gpu_renderpass* shadowmaps_renderpass_create() { @@ -39,13 +72,6 @@ gpu_renderpass* shadowmaps_renderpass_create() { } // == shader bindings -typedef struct model_uniform { - mat4 model; -} model_uniform; - -typedef struct lightspace_tf_uniform { - mat4 lightSpaceMatrix; -} lightspace_tf_uniform; shader_data_layout model_uniform_layout(void* data) { bool has_data = data != NULL; @@ -101,8 +127,8 @@ gpu_pipeline* shadowmaps_pipeline_create(gpu_renderpass* rpass) { .code = vertex_shader.contents, .is_spirv = true }, .fs = { .debug_name = "Shadows Frag shader", - .filepath = vert_path, - .code = vertex_shader.contents, + .filepath = frag_path, + .code = fragment_shader.contents, .is_spirv = true }, .renderpass = rpass }; diff --git a/src/renderer/renderpasses.h b/src/renderer/renderpasses.h index 3ee3b6e..5a5ffee 100644 --- a/src/renderer/renderpasses.h +++ b/src/renderer/renderpasses.h @@ -10,6 +10,7 @@ */ #pragma once #include "ral.h" +#include "ral_types.h" #include "render_types.h" // Shadowmap pass @@ -22,13 +23,31 @@ gpu_renderpass* renderpass_blinn_phong_create(); void renderpass_blinn_phong_execute(gpu_renderpass* pass, render_entity* entities, size_t entity_count); + typedef struct ren_shadowmaps { u32 width; u32 height; gpu_renderpass* rpass; gpu_pipeline* static_pipeline; + gpu_pipeline* debug_quad; + texture_handle depth_tex; } ren_shadowmaps; +typedef struct model_uniform { + mat4 model; +} model_uniform; +typedef struct lightspace_tf_uniform { + mat4 lightSpaceMatrix; +} lightspace_tf_uniform; + +typedef struct debug_quad_uniform { + texture_handle depthMap; +} debug_quad_uniform; + +shader_data_layout model_uniform_layout(void* data); +shader_data_layout lightspace_uniform_layout(void* data); +shader_data_layout debug_quad_layout(void* data); + void ren_shadowmaps_init(ren_shadowmaps* storage); gpu_renderpass* shadowmaps_renderpass_create(); |