summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOmniscient <omniscient.oce@gmail.com>2024-06-15 16:38:05 +1000
committerOmniscient <omniscient.oce@gmail.com>2024-06-15 16:38:05 +1000
commitc5808488875484aca814bfc8e526f37f3f447166 (patch)
treee560bc86302fad0c8520140511e1994c2b4800d7 /src
parent59f67f04d7238453da766218a37b3c78607fb122 (diff)
shinchoku
Diffstat (limited to 'src')
-rw-r--r--src/colours.h1
-rw-r--r--src/maths/maths.h2
-rw-r--r--src/maths/primitives.c34
-rw-r--r--src/renderer/backends/opengl/backend_opengl.c13
-rw-r--r--src/renderer/backends/opengl/backend_opengl.h1
-rw-r--r--src/renderer/builtin_materials.h81
-rw-r--r--src/renderer/ral.c9
-rw-r--r--src/renderer/render.h10
-rw-r--r--src/renderer/render_types.h7
-rw-r--r--src/renderer/static_pipeline.h4
-rw-r--r--src/scene.h1
11 files changed, 122 insertions, 41 deletions
diff --git a/src/colours.h b/src/colours.h
index a981c6c..ac8996a 100644
--- a/src/colours.h
+++ b/src/colours.h
@@ -13,6 +13,7 @@ typedef struct rgba {
#define COLOUR_WHITE ((rgba){ 1.0, 1.0, 1.0, 1.0 })
#define rgba_to_vec4(color) (vec4(color.r, color.g, color.b, color.a))
+#define rgba_to_vec3(color) (vec3(color.r, color.g, color.b))
// Thanks ChatGPT
#define STONE_50 ((rgba){ 0.980, 0.980, 0.976, 1.0 })
diff --git a/src/maths/maths.h b/src/maths/maths.h
index 80ce04d..fa58088 100644
--- a/src/maths/maths.h
+++ b/src/maths/maths.h
@@ -314,7 +314,7 @@ static inline mat4 transform_to_mat(transform *tf) {
mat4 scale = mat4_scale(tf->scale);
mat4 rotation = mat4_rotation(tf->rotation);
mat4 translation = mat4_translation(tf->position);
- return mat4_mult( mat4_mult(scale, rotation), translation);
+ return mat4_mult(mat4_mult(scale, rotation), translation);
}
// --- Sizing asserts
diff --git a/src/maths/primitives.c b/src/maths/primitives.c
index b6b5784..86f9261 100644
--- a/src/maths/primitives.c
+++ b/src/maths/primitives.c
@@ -199,38 +199,38 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we
u32 i1 = i + 1;
u32 i2 = (i + 1) % north_south_lines + 1;
push_triangle(indices, 0, i1, i2);
- TRACE("Push triangle (%.2f %.2f %.2f)->(%.2f %.2f %.2f)->(%.2f %.2f %.2f)\n",
- vertices->data[0].static_3d.position.x, vertices->data[0].static_3d.position.y,
- vertices->data[0].static_3d.position.z, vertices->data[i1].static_3d.position.x,
- vertices->data[i1].static_3d.position.y, vertices->data[i1].static_3d.position.z,
- vertices->data[i2].static_3d.position.x, vertices->data[i2].static_3d.position.y,
- vertices->data[i2].static_3d.position.z);
+ /* TRACE("Push triangle (%.2f %.2f %.2f)->(%.2f %.2f %.2f)->(%.2f %.2f %.2f)\n", */
+ /* vertices->data[0].static_3d.position.x, vertices->data[0].static_3d.position.y, */
+ /* vertices->data[0].static_3d.position.z, vertices->data[i1].static_3d.position.x, */
+ /* vertices->data[i1].static_3d.position.y, vertices->data[i1].static_3d.position.z, */
+ /* vertices->data[i2].static_3d.position.x, vertices->data[i2].static_3d.position.y, */
+ /* vertices->data[i2].static_3d.position.z); */
u32 bot = vertices->len - 1;
u32 i3 = i + north_south_lines * (east_west_lines - 2) + 1;
u32 i4 = (i + 1) % north_south_lines + north_south_lines * (east_west_lines - 2) + 1;
- push_triangle(indices, bot, i3, i4);
+ push_triangle(indices, i3, bot, i4);
}
// quads
for (u32 i = 0; i < east_west_lines - 2; i++) {
u32 ring_start = i * north_south_lines + 1;
u32 next_ring_start = (i + 1) * north_south_lines + 1;
- printf("ring start %d next ring start %d\n", ring_start, next_ring_start);
- print_vec3(vertices->data[ring_start].static_3d.position);
- print_vec3(vertices->data[next_ring_start].static_3d.position);
+ /* printf("ring start %d next ring start %d\n", ring_start, next_ring_start); */
+ /* print_vec3(vertices->data[ring_start].static_3d.position); */
+ /* print_vec3(vertices->data[next_ring_start].static_3d.position); */
for (u32 j = 0; j < north_south_lines; j++) {
u32 i0 = ring_start + j;
u32 i1 = next_ring_start + j;
u32 i2 = ring_start + (j + 1) % north_south_lines;
u32 i3 = next_ring_start + (j + 1) % north_south_lines;
push_triangle(indices, i0, i1, i2);
- TRACE("Push triangle (%.2f %.2f %.2f)->(%.2f %.2f %.2f)->(%.2f %.2f %.2f)\n",
- vertices->data[i0].static_3d.position.x, vertices->data[i0].static_3d.position.y,
- vertices->data[i0].static_3d.position.z, vertices->data[i1].static_3d.position.x,
- vertices->data[i1].static_3d.position.y, vertices->data[i1].static_3d.position.z,
- vertices->data[i2].static_3d.position.x, vertices->data[i2].static_3d.position.y,
- vertices->data[i2].static_3d.position.z);
- // push_triangle(indices, i2, i1, i3);
+ /* TRACE("Push triangle (%.2f %.2f %.2f)->(%.2f %.2f %.2f)->(%.2f %.2f %.2f)\n", */
+ /* vertices->data[i0].static_3d.position.x, vertices->data[i0].static_3d.position.y, */
+ /* vertices->data[i0].static_3d.position.z, vertices->data[i1].static_3d.position.x, */
+ /* vertices->data[i1].static_3d.position.y, vertices->data[i1].static_3d.position.z, */
+ /* vertices->data[i2].static_3d.position.x, vertices->data[i2].static_3d.position.y, */
+ /* vertices->data[i2].static_3d.position.z); */
+ push_triangle(indices, i2, i1, i3);
}
}
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/renderer/backends/opengl/backend_opengl.c
index 5a11f39..478ba0c 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/renderer/backends/opengl/backend_opengl.c
@@ -55,7 +55,7 @@ bool gpu_backend_init(const char* window_name, struct GLFWwindow* window) {
}
glEnable(GL_DEPTH_TEST);
- // glFrontFace(GL_CW);
+ glEnable(GL_CULL_FACE);
return true;
}
@@ -93,8 +93,13 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip
pipeline->uniform_bindings[binding_id] = ubo_handle;
gpu_buffer* ubo_buf = BUFFER_GET(ubo_handle);
- u32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, "Matrices");
- printf("Block index for Matrices: %d", blockIndex);
+ i32 blockIndex = glGetUniformBlockIndex(pipeline->shader_id, binding.label);
+ /* printf("Block index for Matrices: %d", blockIndex); */
+ if (blockIndex < 0) {
+ WARN("Couldn't retrieve block index for uniform block '%s'", binding.label);
+ } else {
+ DEBUG("Retrived block index %d for %s", blockIndex, binding.label);
+ }
u32 blocksize;
glGetActiveUniformBlockiv(pipeline->shader_id, blockIndex, GL_UNIFORM_BLOCK_DATA_SIZE,
&blocksize);
@@ -259,7 +264,7 @@ buffer_handle gpu_buffer_create(u64 size, gpu_buffer_type buf_type, gpu_buffer_f
TRACE("Upload data (%d bytes) as part of buffer creation", size);
glBufferData(gl_buf_type, buffer->size, data, gl_buf_usage);
} else {
- TRACE("Allocating the correct size anyway");
+ TRACE("Allocating but not uploading (%d bytes)", size);
glBufferData(gl_buf_type, buffer->size, NULL, gl_buf_usage);
}
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/renderer/backends/opengl/backend_opengl.h
index ccdb446..cde52a3 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/renderer/backends/opengl/backend_opengl.h
@@ -47,7 +47,6 @@ typedef struct gpu_texture {
} gpu_texture;
typedef struct opengl_support {
-
} opengl_support;
u32 shader_create_separate(const char *vert_shader, const char *frag_shader);
diff --git a/src/renderer/builtin_materials.h b/src/renderer/builtin_materials.h
new file mode 100644
index 0000000..c284acc
--- /dev/null
+++ b/src/renderer/builtin_materials.h
@@ -0,0 +1,81 @@
+/**
+ * @file builtin_materials.h
+ * @author your name (you@domain.com)
+ * @brief
+ * @version 0.1
+ * @date 2024-06-15
+ *
+ * @copyright Copyright (c) 2024
+ *
+ */
+#pragma once
+
+#include "colours.h"
+#include "defines.h"
+#include "ral.h"
+#include "ral_types.h"
+
+// Currently supported materials
+// - Blinn Phong (textured)
+// - PBR (params)
+// - PBR (textured)
+
+// Thoughts
+// --------
+//
+// A material and a shader are inextricably linked. The input data for a shader needs the material.
+// However, a shader may require more than just a material?
+
+// --- Common uniform blocks
+
+/* In glsl code we call it 'MVP_Matrices' */
+typedef struct mvp_matrix_uniforms {
+ mat4 model;
+ mat4 view;
+ mat4 projection;
+} mvp_matrix_uniforms;
+
+// --- PBR (params)
+
+typedef struct pbr_params_material_uniforms {
+ vec3 albedo;
+ f32 metallic;
+ f32 roughness;
+ f32 ao;
+} pbr_params_material_uniforms;
+
+typedef struct pbr_params_light_uniforms {
+ vec3 viewPos;
+ // TODO: PointLights
+
+} pbr_params_light_uniforms;
+
+typedef struct pbr_params_bindgroup {
+ mvp_matrix_uniforms mvp_matrices;
+ pbr_params_material_uniforms material;
+ pbr_params_light_uniforms lights;
+} pbr_params_bindgroup;
+
+static shader_data_layout pbr_params_shader_layout(void* data) {
+ pbr_params_bindgroup* d = (pbr_params_bindgroup*)data;
+ bool has_data = data != NULL;
+
+ shader_binding b1 = { .label = "MVP_Matrices",
+ .type = SHADER_BINDING_BYTES,
+ .stores_data = has_data,
+ .data = { .bytes = { .size = sizeof(mvp_matrix_uniforms) } } };
+
+ shader_binding b2 = { .label = "PBR_Params",
+ .type = SHADER_BINDING_BYTES,
+ .stores_data = has_data,
+ .data = { .bytes = { .size = sizeof(pbr_params_material_uniforms) } } };
+
+ shader_binding b3 = { .label = "Scene_Lights",
+ .type = SHADER_BINDING_BYTES,
+ .stores_data = has_data,
+ .data = { .bytes = { .size = sizeof(pbr_params_light_uniforms) } } };
+
+ return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3 }, .bindings_count = 3
+
+ };
+}
diff --git a/src/renderer/ral.c b/src/renderer/ral.c
index 123c932..e73843b 100644
--- a/src/renderer/ral.c
+++ b/src/renderer/ral.c
@@ -42,10 +42,11 @@ void vertex_desc_add(vertex_description* builder, const char* name, vertex_attri
}
vertex_description static_3d_vertex_description() {
- vertex_description builder = { .debug_label = "vertex" };
- vertex_desc_add(&builder, "position", ATTR_F32x3);
- vertex_desc_add(&builder, "normal", ATTR_F32x3);
- vertex_desc_add(&builder, "texCoords", ATTR_F32x2);
+ vertex_description builder = { .debug_label = "Standard static 3d vertex format" };
+ vertex_desc_add(&builder, "inPosition", ATTR_F32x3);
+ vertex_desc_add(&builder, "inNormal", ATTR_F32x3);
+ vertex_desc_add(&builder, "inTexCoords", ATTR_F32x2);
+ builder.use_full_vertex_size = true;
return builder;
}
diff --git a/src/renderer/render.h b/src/renderer/render.h
index 35e2899..4e8035e 100644
--- a/src/renderer/render.h
+++ b/src/renderer/render.h
@@ -66,14 +66,8 @@ 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
-);
+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);
diff --git a/src/renderer/render_types.h b/src/renderer/render_types.h
index 1485ae4..8588b87 100644
--- a/src/renderer/render_types.h
+++ b/src/renderer/render_types.h
@@ -10,10 +10,10 @@
*/
#pragma once
+#include "colours.h"
#include "defines.h"
#include "ral.h"
#include "ral_types.h"
-#include "colours.h"
#if defined(CEL_PLATFORM_WINDOWS)
// #include "backend_dx11.h"
#endif
@@ -66,10 +66,11 @@ typedef struct texture_data {
typedef enum material_kind {
MAT_BLINN_PHONG,
MAT_PBR,
- MAT_PBR_PARAMS, // uses float values to represent a surface uniformly
+ MAT_PBR_PARAMS, // uses float values to represent a surface uniformly
MAT_COUNT
} material_kind;
-static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", "Count (This should be an error)"};
+static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)",
+ "Count (This should be an error)" };
typedef struct blinn_phong_material {
char name[256];
diff --git a/src/renderer/static_pipeline.h b/src/renderer/static_pipeline.h
index 78f09f2..15e8842 100644
--- a/src/renderer/static_pipeline.h
+++ b/src/renderer/static_pipeline.h
@@ -1,6 +1,6 @@
#pragma once
-#include "maths_types.h"
#include "defines.h"
+#include "maths_types.h"
#include "ral.h"
#include "ral_types.h"
#include "render_types.h"
@@ -26,5 +26,5 @@ static shader_data_layout mvp_uniforms_layout(void* data) {
if (has_data) {
b1.data.bytes.data = &d->mvp;
}
- return (shader_data_layout){ .name = "global_ubo", .bindings = { b1}, .bindings_count = 1 };
+ return (shader_data_layout){ .name = "global_ubo", .bindings = { b1 }, .bindings_count = 1 };
}
diff --git a/src/scene.h b/src/scene.h
index f60bfff..5ac7542 100644
--- a/src/scene.h
+++ b/src/scene.h
@@ -26,7 +26,6 @@ typedef struct scene {
// TODO: tree - transform_hierarchy
} scene;
-
void scene_init(scene* s);
void scene_free(scene* s);