diff options
Diffstat (limited to 'src/new_render')
-rw-r--r-- | src/new_render/pbr.c | 56 | ||||
-rw-r--r-- | src/new_render/pbr.h | 5 | ||||
-rw-r--r-- | src/new_render/render.c | 19 | ||||
-rw-r--r-- | src/new_render/render.h | 4 | ||||
-rw-r--r-- | src/new_render/render_types.h | 27 |
5 files changed, 89 insertions, 22 deletions
diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c index 6df4e97..ccc4dcf 100644 --- a/src/new_render/pbr.c +++ b/src/new_render/pbr.c @@ -4,9 +4,11 @@ #include "file.h" #include "log.h" #include "maths.h" +#include "mem.h" #include "ral_common.h" #include "ral_impl.h" #include "ral_types.h" +#include "render.h" #include "render_scene.h" #include "render_types.h" #include "shader_layouts.h" @@ -145,13 +147,57 @@ ShaderDataLayout PBRMaterial_GetLayout(void* data) { .label = "normalMap", .kind = BINDING_TEXTURE, }; + ShaderBinding b5 = { .label = "PBR_Params", + .kind = BINDING_BYTES, + .data.bytes.size = sizeof(PBR_Params) }; if (has_data) { - b1.data.texture.handle = d->mat.pbr_albedo_map; - b2.data.texture.handle = d->mat.pbr_metallic_map; - b3.data.texture.handle = d->mat.pbr_ao_map; - b4.data.texture.handle = d->mat.pbr_normal_map; + TextureHandle white1x1 = Render_GetWhiteTexture(); + if (d->mat.albedo_map.raw != INVALID_TEX_HANDLE.raw) { + b1.data.texture.handle = d->mat.albedo_map; + } else { + b1.data.texture.handle = white1x1; + } + + if (d->mat.metallic_roughness_map.raw != INVALID_TEX_HANDLE.raw) { + b2.data.texture.handle = d->mat.metallic_roughness_map; + } else { + b2.data.texture.handle = white1x1; + } + + if (d->mat.ambient_occlusion_map.raw != INVALID_TEX_HANDLE.raw) { + b3.data.texture.handle = d->mat.ambient_occlusion_map; + } else { + b3.data.texture.handle = white1x1; + } + + if (d->mat.normal_map.raw != INVALID_TEX_HANDLE.raw) { + b4.data.texture.handle = d->mat.normal_map; + } else { + b4.data.texture.handle = white1x1; + } + + arena* frame = Render_GetFrameArena(); + PBR_Params* params = arena_alloc(frame, sizeof(PBR_Params)); + params->albedo = d->mat.base_colour; + params->metallic = d->mat.metallic; + params->roughness = d->mat.roughness; + params->ambient_occlusion = d->mat.ambient_occlusion; + b5.data.bytes.data = params; } - return (ShaderDataLayout){ .bindings = { b1, b2, b3, b4 }, .binding_count = 4 }; + return (ShaderDataLayout){ .bindings = { b1, b2, b3, b4, b5 }, .binding_count = 5 }; +} + +Material PBRMaterialDefault() { + return (Material){ .name = "Standard Material", + .kind = MAT_PBR, + .base_colour = vec3(1.0, 1.0, 1.0), + .metallic = 0.0, + .roughness = 0.5, + .ambient_occlusion = 0.0, + .albedo_map = INVALID_TEX_HANDLE, + .metallic_roughness_map = INVALID_TEX_HANDLE, + .normal_map = INVALID_TEX_HANDLE, + .ambient_occlusion_map = INVALID_TEX_HANDLE }; }
\ No newline at end of file diff --git a/src/new_render/pbr.h b/src/new_render/pbr.h index 914975b..0aa9dfe 100644 --- a/src/new_render/pbr.h +++ b/src/new_render/pbr.h @@ -36,7 +36,7 @@ typedef struct PBR_Params { Vec3 albedo; f32 metallic; f32 roughness; - f32 ao; + f32 ambient_occlusion; } PBR_Params; typedef struct PBR_Textures { @@ -48,10 +48,13 @@ typedef struct PBR_Textures { TextureHandle ao_map; } PBR_Textures; + // --- Internal typedef struct MaterialMap MaterialMap; +Material PBRMaterialDefault(); + GPU_Renderpass* PBR_RPassCreate(); GPU_Pipeline* PBR_PipelineCreate(GPU_Renderpass* rpass); diff --git a/src/new_render/render.c b/src/new_render/render.c index cfe68d7..5202cd3 100644 --- a/src/new_render/render.c +++ b/src/new_render/render.c @@ -40,6 +40,7 @@ struct Renderer { // Text_Storage text; ResourcePools* resource_pools; arena frame_arena; + TextureHandle white_1x1; }; Renderer* get_renderer() { return g_core.renderer; } @@ -62,6 +63,7 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window INFO("GLFWwindow pointer was provided!!!! Skipping generic glfw init.."); window = optional_window; } else { + INFO("No GLFWwindow provided - creating one"); // NOTE: all platforms use GLFW at the moment but thats subject to change glfwInit(); @@ -95,11 +97,11 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window ren->window = window; *out_window = window; - // glfwMakeContextCurrent(ren->window); + glfwMakeContextCurrent(ren->window); // FIXME // DEBUG("Set up GLFW window callbacks"); - // glfwSetWindowSizeCallback(window, Render_WindowSizeChanged); + glfwSetWindowSizeCallback(window, Render_WindowSizeChanged); // set the RAL backend up if (!GPU_Backend_Init(config.window_name, window, ren->resource_pools)) { @@ -126,6 +128,9 @@ bool Renderer_Init(RendererConfig config, Renderer* ren, GLFWwindow** out_window ren->terrain = malloc(sizeof(Terrain_Storage)); // Terrain_Init(ren->terrain); + // load default textures + ren->white_1x1 = TextureLoadFromFile("assets/textures/white1x1.png"); + return true; } @@ -273,4 +278,14 @@ Shadow_Storage* Render_GetShadowStorage() { Terrain_Storage* Render_GetTerrainStorage() { Renderer* ren = Core_GetRenderer(&g_core); return ren->terrain; +} + +TextureHandle Render_GetWhiteTexture() { + Renderer* ren = Core_GetRenderer(&g_core); + return ren->white_1x1; +} + +arena* Render_GetFrameArena() { + Renderer* ren = Core_GetRenderer(&g_core); + return &ren->frame_arena; }
\ No newline at end of file diff --git a/src/new_render/render.h b/src/new_render/render.h index 2df684c..b8c34b9 100644 --- a/src/new_render/render.h +++ b/src/new_render/render.h @@ -77,4 +77,6 @@ typedef struct Terrain_Storage Terrain_Storage; RenderScene* Render_GetScene(); Shadow_Storage* Render_GetShadowStorage(); -Terrain_Storage* Render_GetTerrainStorage();
\ No newline at end of file +Terrain_Storage* Render_GetTerrainStorage(); +TextureHandle Render_GetWhiteTexture(); +arena* Render_GetFrameArena();
\ No newline at end of file diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h index e0bd76b..f4f108a 100644 --- a/src/new_render/render_types.h +++ b/src/new_render/render_types.h @@ -53,22 +53,23 @@ typedef enum MaterialKind { static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", "Count (This should be an error)" }; +/** + * @brief + * @note mostly references https://google.github.io/filament/Filament.html#materialsystem/standardmodel + */ typedef struct Material { char name[64]; - MaterialKind kind; - // parameterised pbr - Vec3 param_albedo; - f32 param_metallic; - f32 param_roughness; - f32 param_ao; - // textured pbr - TextureHandle pbr_albedo_map; - TextureHandle pbr_normal_map; - bool metal_roughness_combined; - TextureHandle pbr_metallic_map; - TextureHandle pbr_roughness_map; - TextureHandle pbr_ao_map; + MaterialKind kind; // at the moment all materials are PBR materials + Vec3 base_colour; // linear RGB {0,0,0} to {1,1,1} + f32 metallic; + f32 roughness; + f32 ambient_occlusion; + TextureHandle albedo_map; + TextureHandle normal_map; + TextureHandle metallic_roughness_map; + TextureHandle ambient_occlusion_map; } Material; + #ifndef TYPED_MATERIAL_ARRAY KITC_DECL_TYPED_ARRAY(Material) #define TYPED_MATERIAL_ARRAY |