summaryrefslogtreecommitdiff
path: root/src/renderer
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-10 21:53:14 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-06-10 21:53:14 +1000
commit76216f91aee936bc57d7e1a1b2c2b63a03ce976a (patch)
tree363da8e607959f1bd39173a0c145e44fdfede436 /src/renderer
parenta4c2dfa6c1026859b5c8930b70dfe42317cf32ad (diff)
load pbr textures
Diffstat (limited to 'src/renderer')
-rw-r--r--src/renderer/render.c25
-rw-r--r--src/renderer/render.h11
-rw-r--r--src/renderer/render_types.h58
3 files changed, 76 insertions, 18 deletions
diff --git a/src/renderer/render.c b/src/renderer/render.c
index 3a373dc..351a7e0 100644
--- a/src/renderer/render.c
+++ b/src/renderer/render.c
@@ -1,5 +1,6 @@
#include <glfw3.h>
#include "maths_types.h"
+#include "render_types.h"
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
@@ -260,3 +261,27 @@ texture_handle texture_data_upload(texture_data data, bool free_on_upload) {
}
return handle;
}
+
+/** @brief load all of the texture for a PBR material and returns an unnamed material */
+material pbr_material_load(char* albedo_path, char* normal_path, bool metal_roughness_combined,
+ char* metallic_path, char* roughness_map, char* ao_map) {
+ material m = { 0 };
+ m.kind = MAT_PBR;
+
+ // For now we must have the required textures
+ assert(albedo_path);
+ assert(normal_path);
+ assert(metallic_path);
+ assert(metal_roughness_combined);
+
+ m.mat_data.pbr.metal_roughness_combined = metal_roughness_combined;
+ texture_data tex_data;
+ tex_data = texture_data_load(albedo_path, false);
+ m.mat_data.pbr.albedo_map = texture_data_upload(tex_data, true);
+ tex_data = texture_data_load(normal_path, false);
+ m.mat_data.pbr.normal_map = texture_data_upload(tex_data, true);
+ tex_data = texture_data_load(metallic_path, false);
+ m.mat_data.pbr.metallic_map = texture_data_upload(tex_data, true);
+
+ return m;
+} \ No newline at end of file
diff --git a/src/renderer/render.h b/src/renderer/render.h
index 12c0ce4..35e2899 100644
--- a/src/renderer/render.h
+++ b/src/renderer/render.h
@@ -10,6 +10,7 @@
*/
#pragma once
+#include "file.h"
#include "ral_types.h"
#include "render_types.h"
@@ -64,6 +65,16 @@ texture_data texture_data_load(const char* path, bool invert_y);
*/
texture_handle texture_data_upload(texture_data data, bool free_on_upload);
+/** @brief load all of the texture for a PBR material and returns an unnamed material */
+material pbr_material_load(
+ char* albedo_path,
+ char* normal_path,
+ bool metal_roughness_combined,
+ char* metallic_path,
+ char* roughness_map,
+ char* ao_map
+);
+
buffer_handle buffer_create(const char* debug_name, u64 size);
bool buffer_destroy(buffer_handle buffer);
sampler_handle sampler_create();
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index 3448226..b8ed512 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -54,15 +54,6 @@ C side - reload_model():
- remove from transform graph so it isnt tried to be drawn
*/
-CORE_DEFINE_HANDLE(model_handle);
-
-typedef struct model {
- str8 name;
- mesh_darray* meshes;
-} model;
-
-TYPED_POOL(model, model)
-
typedef struct texture {
} texture;
@@ -71,6 +62,13 @@ typedef struct texture_data {
void* image_data;
} texture_data;
+typedef enum material_kind {
+ MAT_BLINN_PHONG,
+ MAT_PBR,
+ MAT_COUNT
+} material_kind;
+static const char* material_kind_names[] = { "Blinn Phong", "PBR", "Count (This should be an error)"};
+
typedef struct blinn_phong_material {
char name[256];
texture diffuse_texture;
@@ -84,18 +82,47 @@ typedef struct blinn_phong_material {
bool is_loaded;
bool is_uploaded;
} blinn_phong_material;
-typedef blinn_phong_material material;
+// typedef blinn_phong_material material;
typedef struct pbr_parameters {
} pbr_parameters;
typedef struct pbr_material {
-
+ texture_handle albedo_map;
+ texture_handle normal_map;
+ bool metal_roughness_combined;
+ texture_handle metallic_map;
+ texture_handle roughness_map;
+ texture_handle ao_map;
} pbr_material;
-// the default blinn-phong material. MUST be initialised with the function below
-extern material DEFAULT_MATERIAL;
+typedef struct material {
+ material_kind kind;
+ union {
+ blinn_phong_material blinn_phong;
+ pbr_material pbr;
+ } mat_data;
+ char* name;
+} material;
+
+#ifndef TYPED_MATERIAL_ARRAY
+KITC_DECL_TYPED_ARRAY(material)
+#define TYPED_MATERIAL_ARRAY
+#endif
+
+CORE_DEFINE_HANDLE(model_handle);
+
+typedef struct model {
+ str8 name;
+ mesh_darray* meshes;
+ material_darray* materials;
+} model;
+
+TYPED_POOL(model, model)
+
+// FIXME: the default blinn-phong material. MUST be initialised with the function below
+// FIXME: extern material DEFAULT_MATERIAL;
void default_material_init();
#ifndef TYPED_MODEL_ARRAY
@@ -103,11 +130,6 @@ KITC_DECL_TYPED_ARRAY(model)
#define TYPED_MODEL_ARRAY
#endif
-#ifndef TYPED_MATERIAL_ARRAY
-KITC_DECL_TYPED_ARRAY(material)
-#define TYPED_MATERIAL_ARRAY
-#endif
-
#ifndef TYPED_ANIMATION_CLIP_ARRAY
#include "animation.h"
KITC_DECL_TYPED_ARRAY(animation_clip)