diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-06-16 22:57:25 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-06-16 22:58:05 +1000 |
commit | 9c8ef3cb95cff78bdc9d527b89ba30cf616e18c0 (patch) | |
tree | 88a20b91dd231f5213227702b87dc0a6b5651aea | |
parent | dd1e090e1416f21537637dac0b4fda20d322cb56 (diff) |
Fixed!
-rw-r--r-- | examples/pbr_params/ex_pbr_params.c | 46 | ||||
-rw-r--r-- | src/maths/primitives.c | 4 |
2 files changed, 20 insertions, 30 deletions
diff --git a/examples/pbr_params/ex_pbr_params.c b/examples/pbr_params/ex_pbr_params.c index 0d8ade4..1d2d756 100644 --- a/examples/pbr_params/ex_pbr_params.c +++ b/examples/pbr_params/ex_pbr_params.c @@ -24,19 +24,12 @@ const vec3 pointlight_positions[4] = { }; pbr_point_light point_lights[4]; -// Lets define some constant PBR parameters here to test on one sphere with first -const rgba ALBEDO = RED_700; -const f32 metallic = 1.0; -const f32 roughness = 0.3; -const f32 ao = 1.0; - -const int num_rows = 7; -const int num_cols = 7; +void encode_draw_mesh(mesh* m); + +const int num_rows = 7, num_cols = 7; const float spacing = 2.5; -pbr_params_material_uniforms pbr_params = { - .albedo = (vec3){ 0.5, 0.0, 0.0 }, .metallic = metallic, .roughness = roughness, .ao = ao -}; +pbr_params_material_uniforms pbr_params; int main() { core_bringup(); @@ -45,15 +38,15 @@ int main() { for (int i = 0; i < 4; i++) { point_lights[i].pos = pointlight_positions[i]; - // point_lights[i].color = vec3(0.25 * (i + 1), 0., 0.0); point_lights[i].color = vec3(300.0, 300.0, 300.0); } - vec3 camera_pos = vec3(1., 1., -25.); - vec3 camera_front = vec3_normalise(vec3_negate(camera_pos)); - camera cam = camera_create(camera_pos, camera_front, VEC3_Y, deg_to_rad(45.0)); + vec3 camera_pos = vec3(-1., -1., 26.); + camera cam = camera_create(camera_pos, VEC3_NEG_Z, VEC3_Y, deg_to_rad(45.0)); // PBR Material data + pbr_params.albedo = (vec3){ 0.5, 0.0, 0.0 }; + pbr_params.ao = 1.0; shader_data pbr_uniforms = { .data = NULL, .shader_data_get_layout = &pbr_params_shader_layout }; // Make the pipeline @@ -119,20 +112,11 @@ int main() { pbr_bind_data.material = pbr_params; pbr_bind_data.lights = (pbr_params_light_uniforms){ .viewPos = vec4(cam.position.x, cam.position.y, cam.position.z, 1.0), - // .viewPos = cam.position, .pointLights = { point_lights[0], point_lights[1], point_lights[2], point_lights[3] } }; pbr_uniforms.data = &pbr_bind_data; -// encode_bind_shader_data(enc, 0, &pbr_uniforms); - -// Record draw call -/* draw_mesh(&sphere, &model_affine, &cam); */ -#if 0 - encode_set_vertex_buffer(enc, cube.vertex_buffer); - encode_set_index_buffer(enc, cube.index_buffer); - encode_draw_indexed(enc, cube.geometry->indices->len); -#endif + // Record draw calls for (u32 row = 0; row < num_rows; row++) { f32 metallic = (float)row / (float)num_rows; for (u32 col = 0; col < num_cols; col++) { @@ -152,9 +136,8 @@ int main() { mat4 model = mat4_translation(vec3(x, y, 0.0f)); pbr_bind_data.mvp_matrices.model = model; encode_bind_shader_data(enc, 0, &pbr_uniforms); - encode_set_vertex_buffer(enc, sphere.vertex_buffer); - encode_set_index_buffer(enc, sphere.index_buffer); - encode_draw_indexed(enc, sphere.geometry->indices->len); + mesh object = sphere; + encode_draw_mesh(&object); } } @@ -171,3 +154,10 @@ int main() { return 0; } + +void encode_draw_mesh(mesh* m) { + gpu_cmd_encoder* enc = gpu_get_default_cmd_encoder(); + encode_set_vertex_buffer(enc, m->vertex_buffer); + encode_set_index_buffer(enc, m->index_buffer); + encode_draw_indexed(enc, m->geometry->indices->len); +}
\ No newline at end of file diff --git a/src/maths/primitives.c b/src/maths/primitives.c index 327159d..46175fd 100644 --- a/src/maths/primitives.c +++ b/src/maths/primitives.c @@ -224,14 +224,14 @@ geometry_data geo_create_uvsphere(f32 radius, u32 north_south_lines, u32 east_we 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); + push_triangle(indices, i0, i2, i1); /* 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); + push_triangle(indices, i1, i2, i3); } } |