diff options
author | Omniscient <omniscient.oce@gmail.com> | 2024-06-18 11:03:52 +1000 |
---|---|---|
committer | Omniscient <omniscient.oce@gmail.com> | 2024-06-18 11:03:52 +1000 |
commit | b2c9782ab2f4abec8f8548e667a8f2ad6e36bd4b (patch) | |
tree | 34973f37f585439357a5e455225d272e9398a742 | |
parent | 4b5695ce26a8f821dfac987e8e11a6ba5eeff610 (diff) |
wip
-rw-r--r-- | assets/shaders/pbr_textured.frag | 6 | ||||
-rw-r--r-- | assets/shaders/pbr_textured.vert | 4 | ||||
-rw-r--r-- | examples/pbr_textured/ex_pbr_textured.c | 9 | ||||
-rw-r--r-- | examples/primitives/ex_primitives.c | 4 | ||||
-rw-r--r-- | src/maths/primitives.c | 26 | ||||
-rw-r--r-- | src/renderer/builtin_materials.h | 5 | ||||
-rw-r--r-- | src/renderer/immediate.c | 10 | ||||
-rw-r--r-- | src/resources/gltf.c | 4 |
8 files changed, 29 insertions, 39 deletions
diff --git a/assets/shaders/pbr_textured.frag b/assets/shaders/pbr_textured.frag index 132c449..29d59a0 100644 --- a/assets/shaders/pbr_textured.frag +++ b/assets/shaders/pbr_textured.frag @@ -87,12 +87,12 @@ void main() { color = color / (color + vec3(1.0)); color = pow(color, vec3(1.0/2.2)); - FragColor = vec4(color, 1.0); + // FragColor = vec4(color, 1.0); // FragColor = vec4(1.0); // FragColor = vec4(scene.pointLights[0].position); - FragColor = vec4(albedo, 1.0); + // FragColor = vec4(albedo, 1.0); // FragColor = vec4(pbr.metallic, pbr.roughness, pbr.ao, 1.0); - // FragColor = scene.viewPos; + FragColor = vec4(fragTexCoords, 0.0, 1.0); } /* The below are from https://learnopengl.com/PBR/Lighting */ diff --git a/assets/shaders/pbr_textured.vert b/assets/shaders/pbr_textured.vert index 40a6f29..d0f8fd5 100644 --- a/assets/shaders/pbr_textured.vert +++ b/assets/shaders/pbr_textured.vert @@ -19,9 +19,7 @@ layout(location = 2) out vec2 fragTexCoords; void main() { fragWorldPos = vec3(mvp.model * vec4(inPosition, 1.0)); - fragNormal = mat3(transpose(inverse(mvp.model))) * inNormal; - // fragNormal = inNormal; - + fragNormal = mat3(transpose(inverse(mvp.model))) * inNormal; // world-space normal fragTexCoords = inTexCoords; gl_Position = mvp.proj * mvp.view * mvp.model * vec4(inPosition, 1.0); diff --git a/examples/pbr_textured/ex_pbr_textured.c b/examples/pbr_textured/ex_pbr_textured.c index a28d3fb..8c48b8d 100644 --- a/examples/pbr_textured/ex_pbr_textured.c +++ b/examples/pbr_textured/ex_pbr_textured.c @@ -41,7 +41,8 @@ int main() { vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); camera cam = camera_create(camera_pos, camera_front, VEC3_NEG_Z, deg_to_rad(45.0)); - shader_data pbr_uniforms = { .data = NULL, .shader_data_get_layout = &pbr_textured_shader_layout }; + shader_data pbr_uniforms = { .data = NULL, + .shader_data_get_layout = &pbr_textured_shader_layout }; // Make the pipeline gpu_renderpass_desc pass_description = {}; @@ -107,9 +108,9 @@ int main() { }; pbr_bind_data.textures = (pbr_textures){ .albedo_tex = helmet->materials->data[0].mat_data.pbr.albedo_map, - .metal_roughness_tex = helmet->materials->data[0].mat_data.pbr.metallic_map, - .ao_tex = helmet->materials->data[0].mat_data.pbr.ao_map, - .normal_tex = helmet->materials->data[0].mat_data.pbr.normal_map, + .metal_roughness_tex = helmet->materials->data[0].mat_data.pbr.metallic_map, + .ao_tex = helmet->materials->data[0].mat_data.pbr.ao_map, + .normal_tex = helmet->materials->data[0].mat_data.pbr.normal_map, }; pbr_uniforms.data = &pbr_bind_data; encode_bind_shader_data(enc, 0, &pbr_uniforms); diff --git a/examples/primitives/ex_primitives.c b/examples/primitives/ex_primitives.c index d39c0d1..5831910 100644 --- a/examples/primitives/ex_primitives.c +++ b/examples/primitives/ex_primitives.c @@ -30,7 +30,7 @@ int main() { geometry_data sphere_data = geo_create_uvsphere(1.0, 8, 8); mesh sphere = mesh_create(&sphere_data, false); - geometry_data plane_data = geo_create_plane(f32x2(6,4)); + geometry_data plane_data = geo_create_plane(f32x2(6, 4)); mesh plane = mesh_create(&plane_data, false); // FIXME: // Texture @@ -54,7 +54,7 @@ int main() { mat4 sphere_model = transform_to_mat(&transform); mat4 cube_model = mat4_translation(vec3(-2., 0, 0)); - mat4 plane_model = mat4_translation(vec3(0,-2,0)); + mat4 plane_model = mat4_translation(vec3(0, -2, 0)); draw_mesh(&cube, &cube_model, &cam); draw_mesh(&sphere, &sphere_model, &cam); draw_mesh(&plane, &plane_model, &cam); diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 2fbe71a..57e85a2 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -29,10 +29,10 @@ void geo_free_data(geometry_data* geo) { // vertices vec3 plane_vertex_positions[] = { - (vec3){ -0.5, 0, -0.5}, - (vec3){ 0.5, 0, -0.5}, - (vec3){ -0.5, 0, 0.5}, - (vec3){ 0.5, 0, 0.5}, + (vec3){ -0.5, 0, -0.5 }, + (vec3){ 0.5, 0, -0.5 }, + (vec3){ -0.5, 0, 0.5 }, + (vec3){ 0.5, 0, 0.5 }, }; geometry_data geo_create_plane(f32x2 extents) { @@ -49,17 +49,15 @@ geometry_data geo_create_plane(f32x2 extents) { VERT_3D(vertices, vert_pos[1], VEC3_Y, vec2(1, 0)); VERT_3D(vertices, vert_pos[2], VEC3_Y, vec2(0, 1)); VERT_3D(vertices, vert_pos[3], VEC3_Y, vec2(1, 1)); - - push_triangle(indices, 2,1,0); - push_triangle(indices, 1,2,3); - geometry_data geo = { - .format = VERTEX_STATIC_3D, - .vertices = vertices, - .has_indices = true, - .indices = indices, - .colour = (rgba){ 0, 0, 0, 1 } - }; + push_triangle(indices, 2, 1, 0); + push_triangle(indices, 1, 2, 3); + + geometry_data geo = { .format = VERTEX_STATIC_3D, + .vertices = vertices, + .has_indices = true, + .indices = indices, + .colour = (rgba){ 0, 0, 0, 1 } }; return geo; } diff --git a/src/renderer/builtin_materials.h b/src/renderer/builtin_materials.h index 1a04f32..f0e7d2f 100644 --- a/src/renderer/builtin_materials.h +++ b/src/renderer/builtin_materials.h @@ -11,10 +11,7 @@ #pragma once #include <assert.h> -#include "colours.h" #include "defines.h" -#include "maths.h" -#include "ral.h" #include "ral_types.h" // Currently supported materials @@ -154,4 +151,4 @@ static shader_data_layout pbr_textured_shader_layout(void* data) { return (shader_data_layout){ .name = "pbr_params", .bindings = { b1, b2, b3, b4, b5, b6 }, .bindings_count = 6 }; -}
\ No newline at end of file +} diff --git a/src/renderer/immediate.c b/src/renderer/immediate.c index b3431fa..63a62b8 100644 --- a/src/renderer/immediate.c +++ b/src/renderer/immediate.c @@ -12,7 +12,7 @@ typedef struct immdraw_system { mesh cube; mesh sphere; // command lists - + } immdraw_system; bool immdraw_system_init(immdraw_system* state) { @@ -28,13 +28,9 @@ bool immdraw_system_init(immdraw_system* state) { return true; } -void immdraw_plane(vec3 pos, quat rotation, f32 u_scale, f32 v_scale, vec4 colour) { - -} +void immdraw_plane(vec3 pos, quat rotation, f32 u_scale, f32 v_scale, vec4 colour) {} -void immdraw_system_render(immdraw_system* state) { - -} +void immdraw_system_render(immdraw_system* state) {} // void imm_draw_sphere(vec3 pos, f32 radius, vec4 colour) { // // Create the vertices diff --git a/src/resources/gltf.c b/src/resources/gltf.c index f136595..c51e30d 100644 --- a/src/resources/gltf.c +++ b/src/resources/gltf.c @@ -377,9 +377,9 @@ bool model_load_gltf_str(const char *file_string, const char *filepath, str8 rel geometry->vertices = geo_vertices; geometry->indices = geo_indices; geometry->has_indices = has_indices; - + mesh m = mesh_create(geometry, true); - m.material_index = (u32_opt){.has_value = mat_idx == 9999, .value = mat_idx }; + m.material_index = (u32_opt){ .has_value = mat_idx == 9999, .value = mat_idx }; mesh_darray_push(out_model->meshes, m); } |