diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pbr_params/ex_pbr_params.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/examples/pbr_params/ex_pbr_params.c b/examples/pbr_params/ex_pbr_params.c index 18e0fc9..fbe5f3a 100644 --- a/examples/pbr_params/ex_pbr_params.c +++ b/examples/pbr_params/ex_pbr_params.c @@ -1,4 +1,5 @@ #include <glfw3.h> +#include <stdbool.h> #include "builtin_materials.h" #include "camera.h" @@ -16,7 +17,7 @@ extern core g_core; const vec3 pointlight_positions[4] = { - { 10.0 / 1., 10.0 / 1., 10.0 / 5 }, + { 10.0 / 1., 10.0 / 1., 10.0 }, { -10.0 / 1., 10.0 / 1., 10.0 }, { 10.0 / 1., -10.0 / 1., 10.0 }, { -10.0 / 1., -10.0 / 1., 10.0 }, @@ -25,12 +26,16 @@ 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 = 0.7; -const f32 roughness = 0.8; +const f32 metallic = 1.0; +const f32 roughness = 0.3; const f32 ao = 1.0; -const pbr_params_material_uniforms pbr_params = { - .albedo = (vec3){ 0.6, 0.0, 0.0 }, .metallic = metallic, .roughness = roughness, .ao = ao +const int num_rows = 7; +const int 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 }; int main() { @@ -44,7 +49,7 @@ int main() { point_lights[i].color = vec3(300.0, 300.0, 300.0); } - vec3 camera_pos = vec3(1.0, 1., -2.); + 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)); @@ -83,9 +88,12 @@ int main() { gpu_pipeline* pbr_pipeline = gpu_graphics_pipeline_create(pipeline_description); // Geometry - geometry_data sphere_data = geo_create_uvsphere(1.0, 48, 48); + geometry_data sphere_data = geo_create_uvsphere(1.0, 64, 64); mesh sphere = mesh_create(&sphere_data, false); + geometry_data cube_data = geo_create_cuboid(f32x3(1, 1, 1)); + mesh cube = mesh_create(&cube_data, false); + pbr_params_bindgroup pbr_bind_data; while (!should_exit()) { @@ -116,14 +124,41 @@ int main() { point_lights[2], point_lights[3] } }; pbr_uniforms.data = &pbr_bind_data; - encode_bind_shader_data(enc, 0, &pbr_uniforms); + // encode_bind_shader_data(enc, 0, &pbr_uniforms); // Record draw call /* draw_mesh(&sphere, &model_affine, &cam); */ - encode_set_vertex_buffer(enc, sphere.vertex_buffer); - encode_set_index_buffer(enc, sphere.index_buffer); - encode_draw_indexed(enc, sphere.geometry->indices->len); - + #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 + + for (u32 row = 0; row < num_rows; row++) { + f32 metallic = (float)row / (float)num_rows; + for (u32 col = 0; col < num_cols; col++) { + f32 roughness = (float)col / (float)num_cols; + if (roughness == 0.0) { roughness += 0.05; }; + if (roughness == 1.0) { roughness -= 0.05; }; + + pbr_bind_data.material.metallic = metallic; + pbr_bind_data.material.roughness = roughness; + + f32 x = (col - ((f32)num_cols / 2.)) * spacing; + f32 y = (row - ((f32)num_rows / 2.)) * spacing; + 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); + } + } + // End recording gpu_cmd_encoder_end_render(enc); |