summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md19
-rw-r--r--assets/shaders/skybox.frag11
-rw-r--r--assets/shaders/skybox.vert19
-rw-r--r--examples/game_demo/game_demo.c4
-rw-r--r--src/new_render/pbr.c2
-rw-r--r--src/new_render/render.c2
-rw-r--r--src/new_render/render_types.h2
-rw-r--r--src/new_render/shadows.c2
-rw-r--r--src/new_render/skybox.c61
-rw-r--r--src/new_render/skybox.h19
-rw-r--r--src/ral/backends/opengl/backend_opengl.c2
-rw-r--r--src/systems/terrain.c7
-rw-r--r--src/systems/terrain.h4
13 files changed, 105 insertions, 49 deletions
diff --git a/README.md b/README.md
index 5ec3d37..b9c3bf6 100644
--- a/README.md
+++ b/README.md
@@ -37,3 +37,22 @@ All third-party dependencies are licensed under their own license.
* `docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material`
* Build docs static site
* `docker run --rm -it -v ${PWD}:/docs squidfunk/mkdocs-material build`
+
+## TODO
+
+### Core
+
+#### Memory
+- [x] Pool allocator (typed)
+- [ ] SoA hot/cold pool allocator (pool for all entities of same type, split into two structs in SoA so we can have hot ,(`VkHandle`and cold `size`, `format` data separated))
+
+#### Scene
+- [ ] Transform hierarchy / Scene tree
+ - [ ] transform propagation
+
+### Renderer
+
+- [ ] PBR
+ - [x] Basic implementation using learnopengl
+ - [ ] Implementation using filament as a reference for first in class PBR
+ - [ ] Handle metallic / roughness being in different channels, combined, or absent
diff --git a/assets/shaders/skybox.frag b/assets/shaders/skybox.frag
new file mode 100644
index 0000000..242477d
--- /dev/null
+++ b/assets/shaders/skybox.frag
@@ -0,0 +1,11 @@
+#version 410 core
+
+out vec4 FragColor;
+
+in vec3 TexCoords;
+
+uniform samplerCube cubemap;
+
+void main() {
+ FragColor = texture(cubemap, TexCoords);
+}
diff --git a/assets/shaders/skybox.vert b/assets/shaders/skybox.vert
index e9149d8..57c6399 100644
--- a/assets/shaders/skybox.vert
+++ b/assets/shaders/skybox.vert
@@ -1,11 +1,18 @@
#version 410 core
-layout(location = 0) in vec3 inPos;
+layout(location = 0) in vec3 inPosition;
+layout(location = 1) in vec3 inNormal;
+layout(location = 2) in vec2 inTexCoords;
-uniform In {
- vec3 textureDir;
-} inc;
+uniform Camera {
+ mat4 view;
+ mat4 proj;
+ vec4 viewPos;
+} cam;
+
+out vec3 TexCoords;
void main() {
-
-} \ No newline at end of file
+ TexCoords = inPosition;
+ gl_Position = cam.proj * cam.view * vec4(inPosition, 1.0);
+}
diff --git a/examples/game_demo/game_demo.c b/examples/game_demo/game_demo.c
index 6854449..720614f 100644
--- a/examples/game_demo/game_demo.c
+++ b/examples/game_demo/game_demo.c
@@ -90,9 +90,9 @@ int main() {
// BEGIN Draw calls
// draw the player model with shadows
- Render_RenderEntities(entities, entity_count);
+ // Render_RenderEntities(entities, entity_count);
// Render_DrawTerrain();
- // Skybox_Draw(&skybox);
+ Skybox_Draw(&skybox, cam);
// END Draw calls
Frame_Draw();
diff --git a/src/new_render/pbr.c b/src/new_render/pbr.c
index f793002..46c621f 100644
--- a/src/new_render/pbr.c
+++ b/src/new_render/pbr.c
@@ -111,7 +111,7 @@ void PBR_Execute(PBR_Storage* storage, Camera camera, TextureHandle shadowmap_te
GPU_EncodeSetVertexBuffer(enc, renderable.mesh->vertex_buffer);
GPU_EncodeSetIndexBuffer(enc, renderable.mesh->index_buffer);
// draw
- GPU_EncodeDrawIndexed(enc, renderable.mesh->geometry->indices->len);
+ GPU_EncodeDrawIndexed(enc, renderable.mesh->geometry.indices->len);
}
GPU_CmdEncoder_EndRender(enc);
diff --git a/src/new_render/render.c b/src/new_render/render.c
index d98db4f..2a0ea9d 100644
--- a/src/new_render/render.c
+++ b/src/new_render/render.c
@@ -188,7 +188,7 @@ Mesh Mesh_Create(Geometry* geometry, bool free_on_upload) {
GPU_BufferCreate(index_bytes, BUFFER_INDEX, BUFFER_FLAG_GPU, geometry->indices->data);
m.is_uploaded = true;
- m.geometry = geometry;
+ m.geometry = *geometry; // clone geometry data and store on Mesh struct
if (free_on_upload) {
Geometry_Destroy(geometry);
}
diff --git a/src/new_render/render_types.h b/src/new_render/render_types.h
index 376e512..4807559 100644
--- a/src/new_render/render_types.h
+++ b/src/new_render/render_types.h
@@ -29,7 +29,7 @@ typedef struct u32_opt {
typedef struct Mesh {
BufferHandle vertex_buffer;
BufferHandle index_buffer;
- Geometry* geometry; // NULL means it has been freed CPU-side
+ Geometry geometry; // NULL means it has been freed CPU-side
i32 material_index; // -1 => no material
bool is_uploaded; // has the data been uploaded to the GPU
} Mesh;
diff --git a/src/new_render/shadows.c b/src/new_render/shadows.c
index 24bfb57..9a44e55 100644
--- a/src/new_render/shadows.c
+++ b/src/new_render/shadows.c
@@ -105,7 +105,7 @@ void Shadow_ShadowmapExecute(Shadow_Storage* storage, Mat4 light_space_transform
GPU_EncodeBindShaderData(&shadow_encoder, 0, shader_data);
GPU_EncodeSetVertexBuffer(&shadow_encoder, mesh->vertex_buffer);
GPU_EncodeSetIndexBuffer(&shadow_encoder, mesh->index_buffer);
- GPU_EncodeDrawIndexed(&shadow_encoder, mesh->geometry->indices->len);
+ GPU_EncodeDrawIndexed(&shadow_encoder, mesh->geometry.indices->len);
}
}
diff --git a/src/new_render/skybox.c b/src/new_render/skybox.c
index a0e151a..b8aa361 100644
--- a/src/new_render/skybox.c
+++ b/src/new_render/skybox.c
@@ -3,12 +3,14 @@
#include "file.h"
#include "glad/glad.h"
#include "log.h"
+#include "maths.h"
#include "primitives.h"
#include "ral_common.h"
#include "ral_impl.h"
#include "ral_types.h"
#include "render.h"
#include "render_types.h"
+#include "shader_layouts.h"
Skybox Skybox_Create(const char** face_paths, int n) {
INFO("Creating a skybox");
@@ -16,7 +18,7 @@ Skybox Skybox_Create(const char** face_paths, int n) {
// -- cube verts
Geometry geom = Geo_CreateCuboid(f32x3(1.0, 1.0, 1.0));
- Mesh cube = Mesh_Create(&geom, true);
+ Mesh cube = Mesh_Create(&geom, false);
// -- cubemap texture
TextureHandle handle;
@@ -40,11 +42,6 @@ Skybox Skybox_Create(const char** face_paths, int n) {
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
// shader pipeline
-
-
-
- ShaderData shader_data = { .data = NULL, .get_layout = &Skybox_GetLayout };
-
GPU_RenderpassDesc rpass_desc = {
.default_framebuffer = true,
};
@@ -53,22 +50,25 @@ Skybox Skybox_Create(const char** face_paths, int n) {
arena scratch = arena_create(malloc(1024 * 1024), 1024 * 1024);
Str8 vert_path = str8("assets/shaders/skybox.vert");
- Str8 frag_path = str8("assets/shaders/pbr_textured.frag");
+ Str8 frag_path = str8("assets/shaders/skybox.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")
}
- VertexDescription pos_only = { .debug_label = "Position only verts" };
- VertexDesc_AddAttr(&pos_only, "inPos", ATTR_F32x3);
- pos_only.use_full_vertex_size = true;
+ // VertexDescription pos_only = { .debug_label = "Position only verts" };
+ // VertexDesc_AddAttr(&pos_only, "inPos", ATTR_F32x3);
+ // pos_only.use_full_vertex_size = true;
+
+ ShaderData camera_data = { .data = NULL, .get_layout = &Binding_Camera_GetLayout};
+ ShaderData shader_data = { .data = NULL, .get_layout = &Skybox_GetLayout };
GraphicsPipelineDesc pipeline_desc = {
.debug_name = "Skybox pipeline",
- .vertex_desc = pos_only,
- .data_layouts = { shader_data },
- .data_layouts_count = 1,
+ .vertex_desc = static_3d_vertex_description(),
+ .data_layouts = { camera_data, shader_data },
+ .data_layouts_count = 2,
.vs = {
.debug_name = "Skybox Vertex Shader",
.filepath = vert_path,
@@ -95,12 +95,37 @@ void Skybox_Draw(Skybox* skybox, Camera camera) {
GPU_EncodeSetDefaults(enc);
// Shader data
- SkyboxUniforms uniforms = { .in_position = camera.position, .cubemap = skybox->texture };
- ShaderData skybox_data = { .data = &uniforms, .get_layout = Skybox_GetLayout };
+
+ Mat4 view, proj;
+ Camera_ViewProj(&camera, 1000, 1000, &view, &proj);
+ Mat4 new = mat4_ident();
+ new.data[0] = view.data[0];
+ new.data[1] = view.data[1];
+ new.data[2] = view.data[2];
+ new.data[4] = view.data[4];
+ new.data[5] = view.data[5];
+ new.data[6] = view.data[6];
+ new.data[8] = view.data[8];
+ new.data[9] = view.data[9];
+ new.data[10] = view.data[10];
+
+ Binding_Camera camera_data = { .view = new,
+ .projection = proj,
+ .viewPos = vec4(camera.position.x, camera.position.y,
+ camera.position.z, 1.0) };
+ GPU_EncodeBindShaderData(
+ enc, 0, (ShaderData){ .data = &camera_data, .get_layout = &Binding_Camera_GetLayout });
+
+
+ SkyboxUniforms uniforms = { .cubemap = skybox->texture };
+ ShaderData skybox_data = { .data = &uniforms, .get_layout = &Skybox_GetLayout };
+ GPU_EncodeBindShaderData(enc, 0, skybox_data);
GPU_EncodeSetVertexBuffer(enc, skybox->cube.vertex_buffer);
- GPU_EncodeSetVertexBuffer(enc, skybox->cube.index_buffer);
- GPU_EncodeDrawIndexed(enc, skybox->cube.geometry->indices->len);
+ GPU_EncodeSetIndexBuffer(enc, skybox->cube.index_buffer);
+ glDepthFunc(GL_LEQUAL);
+ GPU_EncodeDrawIndexed(enc, skybox->cube.geometry.indices->len);
+ glDepthFunc(GL_LESS);
GPU_CmdEncoder_EndRender(enc);
-} \ No newline at end of file
+}
diff --git a/src/new_render/skybox.h b/src/new_render/skybox.h
index 5540381..bf70976 100644
--- a/src/new_render/skybox.h
+++ b/src/new_render/skybox.h
@@ -19,7 +19,6 @@ PUB Skybox Skybox_Create(const char** face_paths, int n); // should always pass
PUB void Skybox_Draw(Skybox* skybox, Camera camera);
typedef struct SkyboxUniforms {
- Vec3 in_position;
TextureHandle cubemap;
} SkyboxUniforms;
@@ -28,24 +27,16 @@ static ShaderDataLayout Skybox_GetLayout(void* data) {
bool has_data = data != NULL;
ShaderBinding b1 = {
- .label = "In",
- .vis = VISIBILITY_VERTEX,
- .kind = BINDING_BYTES,
- .data = {.bytes = {.size = sizeof(Vec3)}}
- };
-
- ShaderBinding b2 = {
.label = "cubemap",
.vis = VISIBILITY_FRAGMENT,
- .kind = BINDING_SAMPLER,
+ .kind = BINDING_TEXTURE,
};
if (has_data) {
- b1.data.bytes.data = &d->in_position;
- b2.data.texture.handle = d->cubemap;
+ b1.data.texture.handle = d->cubemap;
}
return (ShaderDataLayout) {
- .bindings = { b1, b2},
- .binding_count = 2
+ .bindings = { b1},
+ .binding_count = 1
};
-} \ No newline at end of file
+}
diff --git a/src/ral/backends/opengl/backend_opengl.c b/src/ral/backends/opengl/backend_opengl.c
index f4786b9..cf3a4e5 100644
--- a/src/ral/backends/opengl/backend_opengl.c
+++ b/src/ral/backends/opengl/backend_opengl.c
@@ -340,7 +340,7 @@ PUB void GPU_EncodeBindShaderData(GPU_CmdEncoder* encoder, u32 group, ShaderData
}
glUniform1i(tex_slot, i);
glActiveTexture(GL_TEXTURE0 + i);
- glBindTexture(GL_TEXTURE_2D, tex->id);
+ glBindTexture(GL_TEXTURE_CUBE_MAP, tex->id);
}
}
}
diff --git a/src/systems/terrain.c b/src/systems/terrain.c
index 1d23cc3..8a6b06a 100644
--- a/src/systems/terrain.c
+++ b/src/systems/terrain.c
@@ -11,8 +11,11 @@ struct Terrain_Storage {
GPU_Pipeline* hmap_pipeline;
};
-PUB bool Terrain_Init(Terrain_Storage* storage) { return true; }
-PUB void Terrain_Shutdown(Terrain_Storage* storage);
+bool Terrain_Init(Terrain_Storage* storage) {
+ return true;
+}
+
+void Terrain_Shutdown(Terrain_Storage* storage);
/* bool terrain_system_init(terrain_state* state) { */
/* gpu_renderpass_desc rpass_desc = { */
diff --git a/src/systems/terrain.h b/src/systems/terrain.h
index 890cb90..4e709ed 100644
--- a/src/systems/terrain.h
+++ b/src/systems/terrain.h
@@ -30,10 +30,10 @@ typedef struct Terrain_Storage Terrain_Storage;
// --- Public API
PUB bool Terrain_Init(Terrain_Storage* storage);
PUB void Terrain_Shutdown(Terrain_Storage* storage);
-PUB void Terrain_Run(Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer
+PUB void Terrain_Draw(Terrain_Storage* storage); // NOTE: For now it renders directly to main framebuffer
/** @brief Sets the active heightmap to be rendered and collided against. */
-PUB Heightmap Terrain_LoadHeightmap(Heightmap hmap, bool free_on_upload);
+PUB void Terrain_LoadHeightmap(Heightmap hmap, bool free_on_upload);
PUB Heightmap Heightmap_FromImage(Str8 filepath);
PUB Heightmap Heightmap_FromPerlin(/* TODO: perlin noise generation parameters */);